2023-03-18 17:34:37 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace SPC\builder;
|
|
|
|
|
|
2023-10-15 13:07:13 +08:00
|
|
|
use SPC\builder\freebsd\BSDBuilder;
|
2023-03-18 17:34:37 +08:00
|
|
|
use SPC\builder\linux\LinuxBuilder;
|
|
|
|
|
use SPC\builder\macos\MacOSBuilder;
|
2024-01-10 21:08:25 +08:00
|
|
|
use SPC\builder\windows\WindowsBuilder;
|
2023-08-20 19:51:45 +08:00
|
|
|
use SPC\exception\FileSystemException;
|
2023-03-18 17:34:37 +08:00
|
|
|
use SPC\exception\RuntimeException;
|
2023-03-29 21:39:36 +08:00
|
|
|
use SPC\exception\WrongUsageException;
|
2023-03-18 17:34:37 +08:00
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用于生成对应系统环境的 Builder 对象的类
|
|
|
|
|
*/
|
|
|
|
|
class BuilderProvider
|
|
|
|
|
{
|
2024-01-03 16:02:12 +08:00
|
|
|
private static ?BuilderBase $builder = null;
|
|
|
|
|
|
2023-03-18 17:34:37 +08:00
|
|
|
/**
|
2023-08-20 19:51:45 +08:00
|
|
|
* @throws FileSystemException
|
2023-03-18 17:34:37 +08:00
|
|
|
* @throws RuntimeException
|
2023-08-20 19:51:45 +08:00
|
|
|
* @throws WrongUsageException
|
2023-03-18 17:34:37 +08:00
|
|
|
*/
|
|
|
|
|
public static function makeBuilderByInput(InputInterface $input): BuilderBase
|
|
|
|
|
{
|
2024-06-03 23:16:15 +08:00
|
|
|
ini_set('memory_limit', '2G');
|
|
|
|
|
|
2024-01-03 16:02:12 +08:00
|
|
|
self::$builder = match (PHP_OS_FAMILY) {
|
2024-01-10 21:08:25 +08:00
|
|
|
'Windows' => new WindowsBuilder($input->getOptions()),
|
2023-08-20 19:51:45 +08:00
|
|
|
'Darwin' => new MacOSBuilder($input->getOptions()),
|
|
|
|
|
'Linux' => new LinuxBuilder($input->getOptions()),
|
2023-10-15 13:07:13 +08:00
|
|
|
'BSD' => new BSDBuilder($input->getOptions()),
|
2023-03-29 21:39:36 +08:00
|
|
|
default => throw new WrongUsageException('Current OS "' . PHP_OS_FAMILY . '" is not supported yet'),
|
2023-03-18 17:34:37 +08:00
|
|
|
};
|
2024-01-03 16:02:12 +08:00
|
|
|
return self::$builder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @throws WrongUsageException
|
|
|
|
|
*/
|
2024-01-09 10:35:14 +08:00
|
|
|
public static function getBuilder(): BuilderBase
|
2024-01-03 16:02:12 +08:00
|
|
|
{
|
|
|
|
|
if (self::$builder === null) {
|
|
|
|
|
throw new WrongUsageException('Builder has not been initialized');
|
|
|
|
|
}
|
|
|
|
|
return self::$builder;
|
2023-03-18 17:34:37 +08:00
|
|
|
}
|
|
|
|
|
}
|