magallanes/src/Task/BuiltIn/FS/CopyTask.php

61 lines
1.4 KiB
PHP
Raw Normal View History

<?php
2022-04-10 06:20:03 +02:00
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mage\Task\BuiltIn\FS;
use Symfony\Component\Process\Process;
/**
* File System Task - Copy a File
*
* @author Andrés Montañez <andresmontanez@gmail.com>
*/
class CopyTask extends AbstractFileTask
{
2022-04-10 06:20:03 +02:00
public function getName(): string
{
return 'fs/copy';
}
2022-04-10 06:20:03 +02:00
public function getDescription(): string
{
2017-01-07 05:53:57 +01:00
try {
return sprintf('[FS] Copy "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
2022-04-10 06:20:03 +02:00
} catch (\Exception $exception) {
2017-01-07 05:53:57 +01:00
return '[FS] Copy [missing parameters]';
}
}
2022-04-10 06:20:03 +02:00
public function execute(): bool
{
2017-01-07 22:44:28 +01:00
$copyFrom = $this->getFile('from');
$copyTo = $this->getFile('to');
$flags = $this->options['flags'];
$cmd = sprintf('cp %s "%s" "%s"', $flags, $copyFrom, $copyTo);
/** @var Process $process */
$process = $this->runtime->runCommand($cmd);
return $process->isSuccessful();
}
2022-04-10 06:20:03 +02:00
protected function getParameters(): array
{
return ['from', 'to', 'flags'];
}
2017-02-07 23:27:00 +01:00
2022-04-10 06:20:03 +02:00
public function getDefaults(): array
2017-02-07 23:27:00 +01:00
{
return ['flags' => '-p'];
2017-02-07 23:27:00 +01:00
}
}