diff --git a/.php.stub b/.php.stub deleted file mode 100644 index be1e3f0..0000000 --- a/.php.stub +++ /dev/null @@ -1,19 +0,0 @@ - $name - * @psalm-return ($name is class-string ? T : mixed) - */ - public function get(string $name): object; - } -} diff --git a/.phpstorm.meta.php b/.phpstorm.meta.php new file mode 100644 index 0000000..05552cf --- /dev/null +++ b/.phpstorm.meta.php @@ -0,0 +1,9 @@ + '@', + ]) + ); +} diff --git a/bin/pie b/bin/pie index 4928bff..cbff1ac 100755 --- a/bin/pie +++ b/bin/pie @@ -6,19 +6,21 @@ declare(strict_types=1); namespace Php\Pie; use Php\Pie\Command\DownloadCommand; -use Php\Pie\DependencyResolver\ResolveDependencyWithComposer; -use Php\Pie\Downloading\UnixDownloadAndExtract; use Symfony\Component\Console\Application; use Symfony\Component\Console\CommandLoader\ContainerCommandLoader; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; /** @psalm-suppress UnresolvableInclude */ include $_composer_autoload_path ?? __DIR__ . '/../vendor/autoload.php'; +$container = Container::factory(); + $application = new Application('pie', 'dev-main'); $application->setCommandLoader(new ContainerCommandLoader( - Container::factory(), + $container, [ 'download' => DownloadCommand::class, ] )); -$application->run(); +$application->run($container->get(InputInterface::class), $container->get(OutputInterface::class)); diff --git a/psalm.xml.dist b/psalm.xml.dist index f8fc9cf..5fd0a8e 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -20,9 +20,6 @@ - - - diff --git a/src/Container.php b/src/Container.php index 8ce2af0..73c6238 100644 --- a/src/Container.php +++ b/src/Container.php @@ -4,7 +4,10 @@ declare(strict_types=1); namespace Php\Pie; -use Composer\Factory; +use Composer\Composer; +use Composer\Factory as ComposerFactory; +use Composer\IO\ConsoleIO; +use Composer\IO\IOInterface; use Composer\IO\NullIO; use Composer\Repository\CompositeRepository; use Composer\Repository\PlatformRepository; @@ -13,6 +16,7 @@ use Composer\Repository\RepositorySet; use Composer\Util\AuthHelper; use Composer\Util\Platform; use GuzzleHttp\Client; +use Illuminate\Container\Container as IlluminateContainer; use Php\Pie\Command\DownloadCommand; use Php\Pie\DependencyResolver\DependencyResolver; use Php\Pie\DependencyResolver\ResolveDependencyWithComposer; @@ -22,13 +26,37 @@ use Php\Pie\Downloading\ExtractZip; use Php\Pie\Downloading\UnixDownloadAndExtract; use Psr\Container\ContainerInterface; use RuntimeException; +use Symfony\Component\Console\Helper\HelperSet; +use Symfony\Component\Console\Input\ArgvInput; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\ConsoleOutput; +use Symfony\Component\Console\Output\OutputInterface; final class Container { public static function factory(): ContainerInterface { - $container = new \Illuminate\Container\Container(); + $container = new IlluminateContainer(); + $container->instance(InputInterface::class, new ArgvInput()); + $container->instance(OutputInterface::class, new ConsoleOutput()); + $container->singleton(DownloadCommand::class); + + $container->singleton(IOInterface::class, static function (ContainerInterface $container): IOInterface { + return new ConsoleIO( + $container->get(InputInterface::class), + $container->get(OutputInterface::class), + new HelperSet([]), + ); + }); + $container->singleton(Composer::class, static function (ContainerInterface $container): Composer { + $io = $container->get(IOInterface::class); + $composer = ComposerFactory::create($io); + $io->loadConfiguration($composer->getConfig()); + + return $composer; + }); + $container->singleton( DependencyResolver::class, static function (): DependencyResolver { @@ -43,15 +71,14 @@ final class Container ); $container->singleton( UnixDownloadAndExtract::class, - static function (): UnixDownloadAndExtract { - $config = Factory::createConfig(); - $io = new NullIO(); - $io->loadConfiguration($config); - + static function (ContainerInterface $container): UnixDownloadAndExtract { return new UnixDownloadAndExtract( new DownloadZip( new Client(), - new AuthHelper($io, $config), + new AuthHelper( + $container->get(IOInterface::class), + $container->get(Composer::class)->getConfig(), + ), ), new ExtractZip(), );