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

61 lines
1.5 KiB
PHP
Raw Normal View History

2017-02-05 21:52:16 +01:00
<?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;
use Exception;
/**
* File System Task - Copy a File
*
* @author Marian Bäuerle
*/
class ChangeModeTask extends AbstractFileTask
{
public function getName()
{
return 'fs/chmod';
}
public function getDescription()
{
try {
2017-02-11 04:06:57 +01:00
$description = sprintf('[FS] Change mode of "%s" to "%s"', $this->getFile('file'), $this->options['mode']);
if ($this->options['flags'] != null) {
$description = sprintf('[FS] Change mode of "%s" to "%s" with flags "%s"', $this->getFile('file'), $this->options['mode'], $this->options['flags']);
}
return $description;
2017-02-05 21:52:16 +01:00
} catch (Exception $exception) {
return '[FS] Chmod [missing parameters]';
}
}
public function execute()
{
2017-02-11 04:06:57 +01:00
$cmd = sprintf('chmod %s %s %s', $this->options['flags'], $this->options['mode'], $this->getFile('file'));
2017-02-05 21:52:16 +01:00
/** @var Process $process */
$process = $this->runtime->runCommand($cmd);
return $process->isSuccessful();
}
protected function getParameters()
{
return ['file', 'mode', 'flags'];
}
public function getDefaults()
{
return ['flags' => null];
}
2017-02-05 21:52:16 +01:00
}