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

61 lines
1.3 KiB
PHP
Raw Normal View History

<?php
/*
* 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;
2017-01-07 05:53:57 +01:00
use Exception;
/**
* File System Task - Copy a File
*
* @author Andrés Montañez <andresmontanez@gmail.com>
*/
class CopyTask extends AbstractFileTask
{
public function getName()
{
return 'fs/copy';
}
public function getDescription()
{
2017-01-07 05:53:57 +01:00
try {
return sprintf('[FS] Copy "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
2017-01-07 05:53:57 +01:00
} catch (Exception $exception) {
return '[FS] Copy [missing parameters]';
}
}
public function execute()
{
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();
}
protected function getParameters()
{
return ['from', 'to', 'flags'];
}
2017-02-07 23:27:00 +01:00
public function getDefaults()
2017-02-07 23:27:00 +01:00
{
return ['flags' => '-p'];
2017-02-07 23:27:00 +01:00
}
}