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())
|
$bin = match($unit->getExecutionPolicy()->getRunner())
|
||||||
{
|
{
|
||||||
Runners::PHP => (new ExecutableFinder())->find('php'),
|
Runners::PHP->value => (new ExecutableFinder())->find('php'),
|
||||||
Runners::BASH => (new ExecutableFinder())->find('bash'),
|
Runners::BASH->value => (new ExecutableFinder())->find('bash'),
|
||||||
Runners::PYTHON => (new ExecutableFinder())->find('python'),
|
Runners::PYTHON->value => (new ExecutableFinder())->find('python'),
|
||||||
Runners::LUA => (new ExecutableFinder())->find('lua'),
|
Runners::LUA->value => (new ExecutableFinder())->find('lua'),
|
||||||
Runners::PERL => (new ExecutableFinder())->find('perl'),
|
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()))
|
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)));
|
$execution_unit = ExecutionUnit::fromArray(ZiProto::decode(IO::fread($unit_path)));
|
||||||
return match ($execution_unit->getExecutionPolicy()->getRunner())
|
return match ($execution_unit->getExecutionPolicy()->getRunner())
|
||||||
{
|
{
|
||||||
Runners::PHP => PhpRunner::executeUnit($execution_unit, $args),
|
Runners::PHP->value => PhpRunner::executeUnit($execution_unit, $args),
|
||||||
Runners::BASH => BashRunner::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())),
|
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())
|
return match ($execution_unit->getExecutionPolicy()->getRunner())
|
||||||
{
|
{
|
||||||
Runners::PHP => PhpRunner::executeUnit($execution_unit, $args, false),
|
Runners::PHP->value => PhpRunner::executeUnit($execution_unit, $args, false),
|
||||||
Runners::BASH => BashRunner::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())),
|
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
|
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()));
|
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
|
public static function applyTemplate(ProjectManager $project_manager): void
|
||||||
{
|
{
|
||||||
$project_manager->getProjectConfiguration()->addExecutionPolicy(
|
$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');
|
$project_manager->getProjectConfiguration()->getBuild()->setMain('main_policy');
|
||||||
|
|
|
@ -22,25 +22,15 @@
|
||||||
|
|
||||||
namespace ncc\Enums;
|
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';
|
case LUA = 'lua';
|
||||||
|
|
||||||
public const ALL = [
|
|
||||||
self::PHP,
|
|
||||||
self::BASH,
|
|
||||||
self::PYTHON,
|
|
||||||
self::PYTHON_3,
|
|
||||||
self::PYTHON_2,
|
|
||||||
self::PERL,
|
|
||||||
self::LUA
|
|
||||||
];
|
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue