X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fconsolidation%2Frobo%2Fsrc%2FTask%2FFile%2FConcat.php;fp=vendor%2Fconsolidation%2Frobo%2Fsrc%2FTask%2FFile%2FConcat.php;h=12b1eca00fe0bdbcd5f4f6ae39ee9e9add1a9d9b;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/consolidation/robo/src/Task/File/Concat.php b/vendor/consolidation/robo/src/Task/File/Concat.php new file mode 100644 index 000000000..12b1eca00 --- /dev/null +++ b/vendor/consolidation/robo/src/Task/File/Concat.php @@ -0,0 +1,101 @@ +taskConcat([ + * 'web/assets/screen.css', + * 'web/assets/print.css', + * 'web/assets/theme.css' + * ]) + * ->to('web/assets/style.css') + * ->run() + * ?> + * ``` + */ +class Concat extends BaseTask +{ + use ResourceExistenceChecker; + + /** + * @var array|Iterator + */ + protected $files; + + /** + * @var string + */ + protected $dst; + + /** + * Constructor. + * + * @param array|Iterator $files + */ + public function __construct($files) + { + $this->files = $files; + } + + /** + * set the destination file + * + * @param string $dst + * + * @return $this + */ + public function to($dst) + { + $this->dst = $dst; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function run() + { + if (is_null($this->dst) || "" === $this->dst) { + return Result::error($this, 'You must specify a destination file with to() method.'); + } + + if (!$this->checkResources($this->files, 'file')) { + return Result::error($this, 'Source files are missing!'); + } + + if (file_exists($this->dst) && !is_writable($this->dst)) { + return Result::error($this, 'Destination already exists and cannot be overwritten.'); + } + + $dump = ''; + + foreach ($this->files as $path) { + foreach (glob($path) as $file) { + $dump .= file_get_contents($file) . "\n"; + } + } + + $this->printTaskInfo('Writing {destination}', ['destination' => $this->dst]); + + $dst = $this->dst . '.part'; + $write_result = file_put_contents($dst, $dump); + + if (false === $write_result) { + @unlink($dst); + return Result::error($this, 'File write failed.'); + } + // Cannot be cross-volume; should always succeed. + @rename($dst, $this->dst); + + return Result::success($this); + } +}