Convert Runners class to enum with string cases
This commit is contained in:
parent
7c9f63955a
commit
69de79ccf4
4 changed files with 17 additions and 27 deletions
|
@ -54,11 +54,11 @@
|
|||
{
|
||||
$bin = match($unit->getExecutionPolicy()->getRunner())
|
||||
{
|
||||
Runners::PHP => (new ExecutableFinder())->find('php'),
|
||||
Runners::BASH => (new ExecutableFinder())->find('bash'),
|
||||
Runners::PYTHON => (new ExecutableFinder())->find('python'),
|
||||
Runners::LUA => (new ExecutableFinder())->find('lua'),
|
||||
Runners::PERL => (new ExecutableFinder())->find('perl'),
|
||||
Runners::PHP->value => (new ExecutableFinder())->find('php'),
|
||||
Runners::BASH->value => (new ExecutableFinder())->find('bash'),
|
||||
Runners::PYTHON->value => (new ExecutableFinder())->find('python'),
|
||||
Runners::LUA->value => (new ExecutableFinder())->find('lua'),
|
||||
Runners::PERL->value => (new ExecutableFinder())->find('perl'),
|
||||
|
||||
default => throw new NotSupportedException(sprintf('The execution policy %s is not supported because it uses the %s runner', $unit->getExecutionPolicy()->getName(), $unit->getExecutionPolicy()->getRunner()))
|
||||
};
|
||||
|
@ -109,8 +109,8 @@
|
|||
$execution_unit = ExecutionUnit::fromArray(ZiProto::decode(IO::fread($unit_path)));
|
||||
return match ($execution_unit->getExecutionPolicy()->getRunner())
|
||||
{
|
||||
Runners::PHP => PhpRunner::executeUnit($execution_unit, $args),
|
||||
Runners::BASH => BashRunner::executeUnit($execution_unit, $args),
|
||||
Runners::PHP->value => PhpRunner::executeUnit($execution_unit, $args),
|
||||
Runners::BASH->value => BashRunner::executeUnit($execution_unit, $args),
|
||||
default => throw new NotSupportedException(sprintf('The execution policy %s is not supported because it uses the %s runner', $execution_unit->getExecutionPolicy()->getName(), $execution_unit->getExecutionPolicy()->getRunner())),
|
||||
};
|
||||
}
|
||||
|
@ -138,8 +138,8 @@
|
|||
{
|
||||
return match ($execution_unit->getExecutionPolicy()->getRunner())
|
||||
{
|
||||
Runners::PHP => PhpRunner::executeUnit($execution_unit, $args, false),
|
||||
Runners::BASH => BashRunner::executeUnit($execution_unit, $args),
|
||||
Runners::PHP->value => PhpRunner::executeUnit($execution_unit, $args, false),
|
||||
Runners::BASH->value => BashRunner::executeUnit($execution_unit, $args),
|
||||
default => throw new NotSupportedException(sprintf('The execution policy %s is not supported because it uses the %s runner', $execution_unit->getExecutionPolicy()->getName(), $execution_unit->getExecutionPolicy()->getRunner())),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
*/
|
||||
public static function executeUnit(ExecutionUnit $unit, array $args=[], bool $local=true): int
|
||||
{
|
||||
if($unit->getExecutionPolicy()->getRunner() !== Runners::PHP)
|
||||
if($unit->getExecutionPolicy()->getRunner() !== Runners::PHP->value)
|
||||
{
|
||||
throw new InvalidArgumentException(sprintf('The execution unit %s is not a php execution unit', $unit->getExecutionPolicy()->getName()));
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
public static function applyTemplate(ProjectManager $project_manager): void
|
||||
{
|
||||
$project_manager->getProjectConfiguration()->addExecutionPolicy(
|
||||
new ExecutionPolicy('main_policy', Runners::PHP, new ExecutionPolicy\Execute('main'))
|
||||
new ExecutionPolicy('main_policy', Runners::PHP->value, new ExecutionPolicy\Execute('main'))
|
||||
);
|
||||
|
||||
$project_manager->getProjectConfiguration()->getBuild()->setMain('main_policy');
|
||||
|
|
|
@ -22,25 +22,15 @@
|
|||
|
||||
namespace ncc\Enums;
|
||||
|
||||
final class Runners
|
||||
enum Runners : string
|
||||
{
|
||||
public const PHP = 'php';
|
||||
case PHP = 'php';
|
||||
|
||||
public const BASH = 'bash';
|
||||
case BASH = 'bash';
|
||||
|
||||
public const PYTHON = 'python';
|
||||
case PYTHON = 'python';
|
||||
|
||||
public const PERL = 'perl';
|
||||
case PERL = 'perl';
|
||||
|
||||
public const LUA = 'lua';
|
||||
|
||||
public const ALL = [
|
||||
self::PHP,
|
||||
self::BASH,
|
||||
self::PYTHON,
|
||||
self::PYTHON_3,
|
||||
self::PYTHON_2,
|
||||
self::PERL,
|
||||
self::LUA
|
||||
];
|
||||
case LUA = 'lua';
|
||||
}
|
Loading…
Add table
Reference in a new issue