mirror of
https://github.com/andres-montanez/Magallanes
synced 2024-06-03 06:12:15 +02:00
Allow to define default options in the tasks (eg: flags)
This commit is contained in:
parent
5f4236c208
commit
83f047aab0
|
@ -61,7 +61,8 @@ abstract class AbstractTask
|
||||||
if (!is_array($options)) {
|
if (!is_array($options)) {
|
||||||
$options = [];
|
$options = [];
|
||||||
}
|
}
|
||||||
$this->options = $options;
|
|
||||||
|
$this->options = array_merge($options, $this->getDefaults());
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,4 +77,13 @@ abstract class AbstractTask
|
||||||
$this->runtime = $runtime;
|
$this->runtime = $runtime;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return Default options
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getDefaults()
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,10 @@ abstract class AbstractFileTask extends AbstractTask
|
||||||
protected function getOptions()
|
protected function getOptions()
|
||||||
{
|
{
|
||||||
$mandatory = $this->getParameters();
|
$mandatory = $this->getParameters();
|
||||||
|
$defaults = array_keys($this->getDefaults());
|
||||||
|
$missing = array_diff($mandatory, $defaults);
|
||||||
|
|
||||||
foreach ($mandatory as $parameter) {
|
foreach ($missing as $parameter) {
|
||||||
if (!array_key_exists($parameter, $this->options)) {
|
if (!array_key_exists($parameter, $this->options)) {
|
||||||
throw new ErrorException(sprintf('Parameter "%s" is not defined', $parameter));
|
throw new ErrorException(sprintf('Parameter "%s" is not defined', $parameter));
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,4 +50,9 @@ class ChangeModeTask extends AbstractFileTask
|
||||||
{
|
{
|
||||||
return ['file', 'mode', 'flags'];
|
return ['file', 'mode', 'flags'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDefaults()
|
||||||
|
{
|
||||||
|
return ['flags' => null];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue