diff --git a/src/Invokable.php b/src/Invokable.php index 5a87520..c3ff2bb 100644 --- a/src/Invokable.php +++ b/src/Invokable.php @@ -40,12 +40,15 @@ public function addArgumentFactory(?string $type, callable $factory): self return $this; } + protected function initialize(InputInterface $input, OutputInterface $output): void + { + $this->io = ($this->argumentFactories[IO::class] ?? static fn() => new IO($input, $output))($input, $output); + } + protected function execute(InputInterface $input, OutputInterface $output): int { self::invokeParameters(); - $this->io = ($this->argumentFactories[IO::class] ?? static fn() => new IO($input, $output))($input, $output); - $parameters = \array_merge( \array_map( static function(callable $factory, ?string $type) use ($input, $output) { @@ -57,10 +60,10 @@ static function(callable $factory, ?string $type) use ($input, $output) { \array_keys($this->argumentFactories) ), [ - Parameter::untyped($this->io), + Parameter::untyped($this->io()), Parameter::typed(InputInterface::class, $input, Argument::EXACT), Parameter::typed(OutputInterface::class, $output, Argument::EXACT), - Parameter::typed(IO::class, $this->io, Argument::COVARIANCE), + Parameter::typed(IO::class, $this->io(), Argument::COVARIANCE), Parameter::typed(IO::class, Parameter::factory(fn($class) => new $class($input, $output))), ] );