add BuilderProvider::getBuilder() function

This commit is contained in:
crazywhalecc 2024-01-03 16:02:12 +08:00 committed by Jerry Ma
parent 149e844d59
commit e973fe743e

View File

@ -17,6 +17,8 @@ use Symfony\Component\Console\Input\InputInterface;
*/ */
class BuilderProvider class BuilderProvider
{ {
private static ?BuilderBase $builder = null;
/** /**
* @throws FileSystemException * @throws FileSystemException
* @throws RuntimeException * @throws RuntimeException
@ -24,7 +26,7 @@ class BuilderProvider
*/ */
public static function makeBuilderByInput(InputInterface $input): BuilderBase public static function makeBuilderByInput(InputInterface $input): BuilderBase
{ {
return match (PHP_OS_FAMILY) { self::$builder = match (PHP_OS_FAMILY) {
// 'Windows' => new WindowsBuilder( // 'Windows' => new WindowsBuilder(
// binary_sdk_dir: $input->getOption('with-sdk-binary-dir'), // binary_sdk_dir: $input->getOption('with-sdk-binary-dir'),
// vs_ver: $input->getOption('vs-ver'), // vs_ver: $input->getOption('vs-ver'),
@ -35,5 +37,17 @@ class BuilderProvider
'BSD' => new BSDBuilder($input->getOptions()), 'BSD' => new BSDBuilder($input->getOptions()),
default => throw new WrongUsageException('Current OS "' . PHP_OS_FAMILY . '" is not supported yet'), default => throw new WrongUsageException('Current OS "' . PHP_OS_FAMILY . '" is not supported yet'),
}; };
return self::$builder;
}
/**
* @throws WrongUsageException
*/
public function getBuilder(): BuilderBase
{
if (self::$builder === null) {
throw new WrongUsageException('Builder has not been initialized');
}
return self::$builder;
} }
} }