static-php-cli/src/SPC/builder/BuilderProvider.php

54 lines
1.6 KiB
PHP
Raw Normal View History

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;
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
{
private static ?BuilderBase $builder = null;
2023-03-18 17:34:37 +08:00
/**
* @throws FileSystemException
2023-03-18 17:34:37 +08:00
* @throws RuntimeException
* @throws WrongUsageException
2023-03-18 17:34:37 +08:00
*/
public static function makeBuilderByInput(InputInterface $input): BuilderBase
{
self::$builder = match (PHP_OS_FAMILY) {
2023-03-18 17:34:37 +08:00
// 'Windows' => new WindowsBuilder(
// binary_sdk_dir: $input->getOption('with-sdk-binary-dir'),
// vs_ver: $input->getOption('vs-ver'),
// arch: $input->getOption('arch'),
// ),
'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
};
return self::$builder;
}
/**
* @throws WrongUsageException
*/
public static function getBuilder(): BuilderBase
{
if (self::$builder === null) {
throw new WrongUsageException('Builder has not been initialized');
}
return self::$builder;
2023-03-18 17:34:37 +08:00
}
}