Yaffs site version 1.1
[yaffs-website] / vendor / drupal-composer / drupal-scaffold / src / PrestissimoFileFetcher.php
1 <?php
2
3 /**
4  * @file
5  * Contains \DrupalComposer\DrupalScaffold\FileFetcher.
6  */
7
8 namespace DrupalComposer\DrupalScaffold;
9
10 use Composer\Config;
11 use Composer\IO\IOInterface;
12 use Hirak\Prestissimo\CopyRequest;
13 use Hirak\Prestissimo\CurlMulti;
14
15 class PrestissimoFileFetcher extends FileFetcher {
16
17   /**
18    * @var \Composer\IO\IOInterface
19    */
20   protected $io;
21
22   /**
23    * @var \Composer\Config
24    */
25   protected $config;
26
27   public function __construct(\Composer\Util\RemoteFilesystem $remoteFilesystem, $source, array $filenames = [], IOInterface $io, Config $config) {
28     parent::__construct($remoteFilesystem, $source, $filenames);
29     $this->io = $io;
30     $this->config = $config;
31   }
32
33   public function fetch($version, $destination) {
34     if (class_exists(CurlMulti::class)) {
35       $this->fetchWithPrestissimo($version, $destination);
36       return;
37     }
38     parent::fetch($version, $destination);
39   }
40
41   protected function fetchWithPrestissimo($version, $destination) {
42     $requests = [];
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);
47     });
48
49     $successCnt = $failureCnt = 0;
50     $totalCnt = count($requests);
51
52     $multi = new CurlMulti;
53     $multi->setRequests($requests);
54     do {
55       $multi->setupEventLoop();
56       $multi->wait();
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);
62       }
63     } while ($multi->remain());
64   }
65
66 }