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

61 lines
1.3 KiB
PHP
Raw Normal View History

2017-02-05 21:52:16 +01:00
<?php
2022-04-10 06:20:03 +02:00
2017-02-05 21:52:16 +01: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 Marian Bäuerle
*/
class ChangeModeTask extends AbstractFileTask
{
2022-04-10 06:20:03 +02:00
public function getName(): string
2017-02-05 21:52:16 +01:00
{
return 'fs/chmod';
}
2022-04-10 06:20:03 +02:00
public function getDescription(): string
2017-02-05 21:52:16 +01:00
{
try {
return sprintf('[FS] Change mode of "%s" to "%s"', $this->getFile('file'), $this->options['mode']);
2022-04-10 06:20:03 +02:00
} catch (\Exception $exception) {
2017-02-05 21:52:16 +01:00
return '[FS] Chmod [missing parameters]';
}
}
2022-04-10 06:20:03 +02:00
public function execute(): bool
2017-02-05 21:52:16 +01:00
{
$file = $this->getFile('file');
$mode = $this->options['mode'];
$flags = $this->options['flags'];
$cmd = sprintf('chmod %s %s "%s"', $flags, $mode, $file);
2017-02-05 21:52:16 +01:00
/** @var Process $process */
$process = $this->runtime->runCommand($cmd);
return $process->isSuccessful();
}
2022-04-10 06:20:03 +02:00
protected function getParameters(): array
2017-02-05 21:52:16 +01:00
{
return ['file', 'mode', 'flags'];
}
2022-04-10 06:20:03 +02:00
public function getDefaults(): array
{
return ['flags' => null];
}
2017-02-05 21:52:16 +01:00
}