5 * Contains \DrupalComposer\DrupalScaffold\FileFetcher.
8 namespace DrupalComposer\DrupalScaffold;
11 use Composer\IO\IOInterface;
12 use Hirak\Prestissimo\CopyRequest;
13 use Hirak\Prestissimo\CurlMulti;
15 class PrestissimoFileFetcher extends FileFetcher {
18 * @var \Composer\IO\IOInterface
23 * @var \Composer\Config
27 public function __construct(\Composer\Util\RemoteFilesystem $remoteFilesystem, $source, array $filenames = [], IOInterface $io, Config $config) {
28 parent::__construct($remoteFilesystem, $source, $filenames);
30 $this->config = $config;
33 public function fetch($version, $destination) {
34 if (class_exists(CurlMulti::class)) {
35 $this->fetchWithPrestissimo($version, $destination);
38 parent::fetch($version, $destination);
41 protected function fetchWithPrestissimo($version, $destination) {
43 array_walk($this->filenames, function ($filename) use ($version, $destination, &$requests) {
44 $url = $this->getUri($filename, $version);
45 $this->fs->ensureDirectoryExists($destination . '/' . dirname($filename));
46 $requests[] = new CopyRequest($url, $destination . '/' . $filename, false, $this->io, $this->config);
49 $successCnt = $failureCnt = 0;
50 $totalCnt = count($requests);
52 $multi = new CurlMulti;
53 $multi->setRequests($requests);
55 $multi->setupEventLoop();
57 $result = $multi->getFinishedResults();
58 $successCnt += $result['successCnt'];
59 $failureCnt += $result['failureCnt'];
60 foreach ($result['urls'] as $url) {
61 $this->io->writeError(" <comment>$successCnt/$totalCnt</comment>:\t$url", true, \Composer\IO\IOInterface::VERBOSE);
63 } while ($multi->remain());