diff --git a/src/Bootstrap.php b/src/Bootstrap.php index 87bc220..9745f6b 100644 --- a/src/Bootstrap.php +++ b/src/Bootstrap.php @@ -5,9 +5,9 @@ namespace Internal\DLoad; use Internal\DLoad\Module\Common\Architecture; +use Internal\DLoad\Module\Common\Internal\Injection\ConfigLoader; use Internal\DLoad\Module\Common\OperatingSystem; use Internal\DLoad\Module\Common\Stability; -use Internal\DLoad\Module\Container\Internal\ConfigLoader; use Internal\DLoad\Service\Container; /** @@ -21,7 +21,7 @@ private function __construct( private Container $container, ) {} - public static function init(Container $container = new Module\Container\Internal\Container()): self + public static function init(Container $container = new Module\Common\Internal\Container()): self { return new self($container); } diff --git a/src/Command/Get.php b/src/Command/Get.php index 5af53f1..80aa91c 100644 --- a/src/Command/Get.php +++ b/src/Command/Get.php @@ -14,6 +14,7 @@ use Symfony\Component\Console\Command\SignalableCommandInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; /** @@ -29,17 +30,11 @@ final class Get extends Command implements SignalableCommandInterface public function configure(): void { - $this->addArgument( - 'binary', - InputArgument::REQUIRED, - 'Binary name, e.g. "rr", "dolt", "temporal" etc.', - ); - $this->addArgument( - 'path', - InputArgument::OPTIONAL, - 'Path to store the binary, e.g. "./bin"', - ".", - ); + $this->addArgument('binary', InputArgument::REQUIRED, 'Binary name, e.g. "rr", "dolt", "temporal" etc.'); + $this->addOption('path', null, InputOption::VALUE_OPTIONAL, 'Path to store the binary, e.g. "./bin"', "."); + $this->addOption('arch', null, InputOption::VALUE_OPTIONAL, 'Architecture, e.g. "amd64", "arm64" etc.'); + $this->addOption('os', null, InputOption::VALUE_OPTIONAL, 'Operating system, e.g. "linux", "darwin" etc.'); + $this->addOption('stability', null, InputOption::VALUE_OPTIONAL, 'Stability, e.g. "stable", "beta" etc.'); } public function handleSignal(int $signal, int|false $previousExitCode = 0): int|false @@ -71,7 +66,7 @@ protected function execute( OutputInterface $output, ): int { $output->writeln('Binary to load: ' . $input->getArgument('binary')); - $output->writeln('Path to store the binary: ' . $input->getArgument('path')); + $output->writeln('Path to store the binary: ' . $input->getOption('path')); $container = Bootstrap::init()->withConfig( xml: \dirname(__DIR__, 2) . '/dload.xml', @@ -85,11 +80,12 @@ protected function execute( $output->writeln('Stability: ' . $container->get(Stability::class)->name); - $repo = 'roadrunner-server/roadrunner'; - trap(GitHubRepository::fromDsn($repo)->getReleases()->first()->getAssets() - ->whereArchitecture($container->get(Architecture::class)) - ->whereOperatingSystem($container->get(OperatingSystem::class)) - ); + // $repo = 'roadrunner-server/roadrunner'; + // trap( + // GitHubRepository::fromDsn($repo)->getReleases()->first()->getAssets() + // ->whereArchitecture($container->get(Architecture::class)) + // ->whereOperatingSystem($container->get(OperatingSystem::class)), + // ); return Command::SUCCESS; diff --git a/src/Module/Common/Architecture.php b/src/Module/Common/Architecture.php index d79d017..84e1957 100644 --- a/src/Module/Common/Architecture.php +++ b/src/Module/Common/Architecture.php @@ -4,6 +4,7 @@ namespace Internal\DLoad\Module\Common; +use Internal\DLoad\Module\Common\Config\BuildInput; use Internal\DLoad\Service\Factoriable; /** @@ -18,9 +19,9 @@ enum Architecture: string implements Factoriable private const ERROR_UNKNOWN_ARCH = 'Current architecture `%s` may not be supported.'; - public static function create(): static + public static function create(BuildInput $config): self { - return self::fromGlobals(); + return self::tryFrom((string) $config->arch) ?? self::fromGlobals(); } public static function fromGlobals(): self diff --git a/src/Module/Common/Config/BuildInput.php b/src/Module/Common/Config/BuildInput.php new file mode 100644 index 0000000..ab81865 --- /dev/null +++ b/src/Module/Common/Config/BuildInput.php @@ -0,0 +1,23 @@ +factory[$class] ?? null; if ($binding instanceof \Closure) { - $result = $binding($this); + $result = $this->injector->invoke($binding); } else { try { $result = $this->injector->make($class, \array_merge((array) $binding, $arguments)); @@ -97,7 +98,7 @@ public function make(string $class, array $arguments = []): object // Detect related types // Configs - if (\str_starts_with($class, 'Internal\\DLoad\\Config\\')) { + if (\str_starts_with($class, 'Internal\\DLoad\\Module\\Common\\Config\\')) { // Hydrate config /** @var ConfigLoader $configLoader */ $configLoader = $this->get(ConfigLoader::class); diff --git a/src/Module/Container/Internal/ConfigLoader.php b/src/Module/Common/Internal/Injection/ConfigLoader.php similarity index 90% rename from src/Module/Container/Internal/ConfigLoader.php rename to src/Module/Common/Internal/Injection/ConfigLoader.php index f91b0f7..a1c6c6e 100644 --- a/src/Module/Container/Internal/ConfigLoader.php +++ b/src/Module/Common/Internal/Injection/ConfigLoader.php @@ -2,13 +2,14 @@ declare(strict_types=1); -namespace Internal\DLoad\Module\Container\Internal; - -use Internal\DLoad\Module\Container\Attribute\Env; -use Internal\DLoad\Module\Container\Attribute\InputArgument; -use Internal\DLoad\Module\Container\Attribute\InputOption; -use Internal\DLoad\Module\Container\Attribute\PhpIni; -use Internal\DLoad\Module\Container\Attribute\XPath; +namespace Internal\DLoad\Module\Common\Internal\Injection; + +use Internal\DLoad\Module\Common\Internal\Attribute\ConfigAttribute; +use Internal\DLoad\Module\Common\Internal\Attribute\Env; +use Internal\DLoad\Module\Common\Internal\Attribute\InputArgument; +use Internal\DLoad\Module\Common\Internal\Attribute\InputOption; +use Internal\DLoad\Module\Common\Internal\Attribute\PhpIni; +use Internal\DLoad\Module\Common\Internal\Attribute\XPath; use Internal\DLoad\Service\Logger; /** diff --git a/src/Module/Common/OperatingSystem.php b/src/Module/Common/OperatingSystem.php index 39d928f..a216b87 100644 --- a/src/Module/Common/OperatingSystem.php +++ b/src/Module/Common/OperatingSystem.php @@ -4,6 +4,7 @@ namespace Internal\DLoad\Module\Common; +use Internal\DLoad\Module\Common\Config\BuildInput; use Internal\DLoad\Service\Factoriable; /** @@ -21,9 +22,9 @@ enum OperatingSystem: string implements Factoriable private const ERROR_UNKNOWN_OS = 'Current OS `%s` may not be supported'; - public static function create(): static + public static function create(BuildInput $config): static { - return self::fromGlobals(); + return self::tryFrom((string) $config->os) ?? self::fromGlobals(); } public static function fromGlobals(): self diff --git a/src/Module/Common/Stability.php b/src/Module/Common/Stability.php index 57f19df..fb15e60 100644 --- a/src/Module/Common/Stability.php +++ b/src/Module/Common/Stability.php @@ -4,6 +4,7 @@ namespace Internal\DLoad\Module\Common; +use Internal\DLoad\Module\Common\Config\BuildInput; use Internal\DLoad\Service\Factoriable; /** @@ -19,9 +20,9 @@ enum Stability: string implements Factoriable case Alpha = 'alpha'; case Dev = 'dev'; - public static function create(): static + public static function create(BuildInput $config): static { - return self::fromGlobals(); + return self::tryFrom((string) $config->stability) ?? self::fromGlobals(); } public static function fromGlobals(): self diff --git a/src/Module/Repository/Internal/GitHub/GitHubRepository.php b/src/Module/Repository/Internal/GitHub/GitHubRepository.php index eeb86a0..a2a2797 100644 --- a/src/Module/Repository/Internal/GitHub/GitHubRepository.php +++ b/src/Module/Repository/Internal/GitHub/GitHubRepository.php @@ -55,7 +55,7 @@ public function __construct(string $owner, string $repository, HttpClientInterfa */ public static function fromDsn(string $package, HttpClientInterface $client = null): GitHubRepository { - [$owner, $name] = explode('/', $package); + [$owner, $name] = \explode('/', $package); return new GitHubRepository($owner, $name, $client); } diff --git a/src/Service/Factoriable.php b/src/Service/Factoriable.php index a284efd..82999eb 100644 --- a/src/Service/Factoriable.php +++ b/src/Service/Factoriable.php @@ -7,9 +7,8 @@ /** * Class creates new instances of itself. * + * @method static create + * * @internal */ -interface Factoriable -{ - public static function create(): static; -} +interface Factoriable {}