From 09b1f700c4e3bde5e85ac733d77b805f8f5a41c2 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Thu, 26 May 2022 08:43:49 -0400 Subject: [PATCH] [minor] move setting Invokable::$io to initialize method --- src/Invokable.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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))), ] );