Yaffs site version 1.1
[yaffs-website] / vendor / drupal-composer / drupal-scaffold / src / FileFetcher.php
1 <?php
2
3 /**
4  * @file
5  * Contains \DrupalComposer\DrupalScaffold\FileFetcher.
6  */
7
8 namespace DrupalComposer\DrupalScaffold;
9
10 use Composer\Util\Filesystem;
11 use Composer\Util\RemoteFilesystem;
12
13 class FileFetcher {
14
15   /**
16    * @var \Composer\Util\RemoteFilesystem
17    */
18   protected $remoteFilesystem;
19
20   protected $source;
21   protected $filenames;
22   protected $fs;
23
24   public function __construct(RemoteFilesystem $remoteFilesystem, $source, $filenames = []) {
25     $this->remoteFilesystem = $remoteFilesystem;
26     $this->source = $source;
27     $this->filenames = $filenames;
28     $this->fs = new Filesystem();
29   }
30
31   public function fetch($version, $destination) {
32     array_walk($this->filenames, function ($filename) use ($version, $destination) {
33       $url = $this->getUri($filename, $version);
34       $this->fs->ensureDirectoryExists($destination . '/' . dirname($filename));
35       $this->remoteFilesystem->copy($url, $url, $destination . '/' . $filename);
36     });
37   }
38
39   protected function getUri($filename, $version) {
40     $map = [
41       '{path}' => $filename,
42       '{version}' => $version
43     ];
44     return str_replace(array_keys($map), array_values($map), $this->source);
45   }
46
47 }