2025-12-15 17:00:20 +08:00
|
|
|
<?php
|
|
|
|
|
|
2025-12-18 15:43:58 +08:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2025-12-15 17:00:20 +08:00
|
|
|
namespace StaticPHP\Skeleton;
|
|
|
|
|
|
|
|
|
|
use StaticPHP\Exception\ValidationException;
|
|
|
|
|
use StaticPHP\Runtime\Executor\Executor;
|
2025-12-18 15:43:58 +08:00
|
|
|
use StaticPHP\Runtime\Executor\UnixAutoconfExecutor;
|
|
|
|
|
use StaticPHP\Runtime\Executor\UnixCMakeExecutor;
|
|
|
|
|
use StaticPHP\Runtime\Executor\WindowsCMakeExecutor;
|
2025-12-15 17:00:20 +08:00
|
|
|
|
|
|
|
|
class ExecutorGenerator
|
|
|
|
|
{
|
|
|
|
|
public function __construct(protected string $class)
|
|
|
|
|
{
|
|
|
|
|
if (!is_a($class, Executor::class, true)) {
|
|
|
|
|
throw new ValidationException('Executor class must extend ' . Executor::class);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-12-18 15:43:58 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generate the code to create an instance of the executor.
|
|
|
|
|
*
|
|
|
|
|
* @return array{0: string, 1: string} an array containing the class name and the code string
|
|
|
|
|
*/
|
|
|
|
|
public function generateCode(): array
|
|
|
|
|
{
|
|
|
|
|
return match ($this->class) {
|
|
|
|
|
UnixCMakeExecutor::class => [UnixCMakeExecutor::class, 'UnixCMakeExecutor::create($package)->build();'],
|
|
|
|
|
UnixAutoconfExecutor::class => [UnixAutoconfExecutor::class, 'UnixAutoconfExecutor::create($package)->build();'],
|
|
|
|
|
WindowsCMakeExecutor::class => [WindowsCMakeExecutor::class, 'WindowsCMakeExecutor::create($package)->build();'],
|
|
|
|
|
default => throw new ValidationException("Unsupported executor class: {$this->class}"),
|
|
|
|
|
};
|
|
|
|
|
}
|
2025-12-15 17:00:20 +08:00
|
|
|
}
|