3 namespace DrupalComposer\DrupalScaffold;
5 use Composer\IO\IOInterface;
6 use Composer\Util\Filesystem;
7 use Composer\Util\RemoteFilesystem;
10 * Downloads all required files and writes it to the file system.
15 * @var \Composer\Util\RemoteFilesystem
17 protected $remoteFilesystem;
20 * @var \Composer\IO\IOInterface
27 * A boolean indicating if progress should be displayed.
36 * Constructs this FileFetcher object.
38 public function __construct(RemoteFilesystem $remoteFilesystem, $source, IOInterface $io, $progress = TRUE) {
39 $this->remoteFilesystem = $remoteFilesystem;
41 $this->source = $source;
42 $this->fs = new Filesystem();
43 $this->progress = $progress;
47 * Downloads all required files and writes it to the file system.
49 public function fetch($version, $destination, $override) {
50 foreach ($this->filenames as $sourceFilename => $filename) {
51 $target = "$destination/$filename";
52 if ($override || !file_exists($target)) {
53 $url = $this->getUri($sourceFilename, $version);
54 $this->fs->ensureDirectoryExists($destination . '/' . dirname($filename));
55 if ($this->progress) {
56 $this->io->writeError(" - <info>$filename</info> (<comment>$url</comment>): ", FALSE);
57 $this->remoteFilesystem->copy($url, $url, $target, $this->progress);
58 // Used to put a new line because the remote file system does not put
60 $this->io->writeError('');
63 $this->remoteFilesystem->copy($url, $url, $target, $this->progress);
72 public function setFilenames(array $filenames) {
73 $this->filenames = $filenames;
77 * Replace filename and version in the source pattern with their values.
79 protected function getUri($filename, $version) {
81 '{path}' => $filename,
82 '{version}' => $version,
84 return str_replace(array_keys($map), array_values($map), $this->source);