mirror of
https://github.com/php/pie.git
synced 2026-03-23 23:12:17 +01:00
Rewire some Composer dependencies and console IO
This commit is contained in:
19
.php.stub
19
.php.stub
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psr\Container {
|
||||
|
||||
interface ContainerInterface
|
||||
{
|
||||
/** @param string|class-string $name */
|
||||
public function has(string $name): bool;
|
||||
|
||||
/**
|
||||
* @template T of object
|
||||
* @psalm-param string|class-string<T> $name
|
||||
* @psalm-return ($name is class-string ? T : mixed)
|
||||
*/
|
||||
public function get(string $name): object;
|
||||
}
|
||||
}
|
||||
9
.phpstorm.meta.php
Normal file
9
.phpstorm.meta.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace PHPSTORM_META {
|
||||
override(\Psr\Container\ContainerInterface::get(0),
|
||||
map([
|
||||
'' => '@',
|
||||
])
|
||||
);
|
||||
}
|
||||
10
bin/pie
10
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));
|
||||
|
||||
@@ -20,9 +20,6 @@
|
||||
<plugins>
|
||||
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
|
||||
</plugins>
|
||||
<stubs>
|
||||
<file name=".php.stub"/>
|
||||
</stubs>
|
||||
<issueHandlers>
|
||||
<PossiblyUnusedMethod>
|
||||
<errorLevel type="suppress">
|
||||
|
||||
@@ -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(),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user