Skip to content

Commit

Permalink
feat(composer): use lazy inject instead of container
Browse files Browse the repository at this point in the history
  • Loading branch information
joelwurtz committed Apr 22, 2024
1 parent 574b2dd commit 6e530aa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/Console/Command/ComposerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@
namespace Castor\Console\Command;

use Castor\Console\Input\GetRawTokenTrait;
use Castor\Container;
use Castor\Import\Remote\Composer;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

/** @internal */
#[AsCommand(
name: 'castor:composer',
description: 'Interact with built-in Composer for castor',
aliases: ['composer'],
)]
class ComposerCommand extends Command
final class ComposerCommand extends Command
{
use GetRawTokenTrait;

public function __construct(
private readonly string $rootDir,
#[Autowire(lazy: true)]
private readonly Composer $composer,
) {
parent::__construct();
}
Expand All @@ -36,7 +38,6 @@ protected function configure(): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
$extra = array_filter($this->getRawTokens($input), fn ($item) => 'composer' !== $item);
$composer = Container::get()->composer;

$vendorDirectory = $this->rootDir . Composer::VENDOR_DIR;

Expand All @@ -45,7 +46,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$file = $this->rootDir . '/castor.composer.json';
}

$composer->run($file, $vendorDirectory, $extra, $output, true);
$this->composer->run($file, $vendorDirectory, $extra, $output, true);

return Command::SUCCESS;
}
Expand Down
2 changes: 0 additions & 2 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Castor\Helper\Notifier;
use Castor\Helper\Waiter;
use Castor\Import\Importer;
use Castor\Import\Remote\Composer;
use Castor\Runner\ParallelRunner;
use Castor\Runner\ProcessRunner;
use Castor\Runner\SshRunner;
Expand All @@ -32,7 +31,6 @@ final class Container
public function __construct(
public readonly Application $application,
public readonly CacheItemPoolInterface&CacheInterface $cache,
public readonly Composer $composer,
public readonly ContextRegistry $contextRegistry,
public readonly ContextRegistry $outputInterface,
public readonly EventDispatcherInterface $eventDispatcher,
Expand Down

0 comments on commit 6e530aa

Please sign in to comment.