diff --git a/src/Commands/DrushCommands.php b/src/Commands/DrushCommands.php index a5d56133cf..9cc041b13d 100644 --- a/src/Commands/DrushCommands.php +++ b/src/Commands/DrushCommands.php @@ -17,8 +17,10 @@ use GuzzleHttp\HandlerStack; use GuzzleHttp\MessageFormatter; use GuzzleHttp\Middleware; +use JetBrains\PhpStorm\Deprecated; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; +use Psr\Log\LoggerInterface; use Robo\Common\IO; use Robo\Contract\ConfigAwareInterface; use Robo\Contract\IOAwareInterface; @@ -64,6 +66,17 @@ protected function io(): SymfonyStyle return $this->io; } + /** + * Sets a logger, if none is available yet. + */ + #[Deprecated('Use logger() in Drush 13+')] + public function setLoggerIfEmpty(LoggerInterface $logger): void + { + if ($this->logger === null) { + $this->setLogger($logger); + } + } + /** * Returns a logger object. */ diff --git a/src/Runtime/ServiceManager.php b/src/Runtime/ServiceManager.php index b35ad02535..58c62db3b4 100644 --- a/src/Runtime/ServiceManager.php +++ b/src/Runtime/ServiceManager.php @@ -23,7 +23,6 @@ use Grasmash\YamlCli\Command\UpdateKeyCommand; use Grasmash\YamlCli\Command\UpdateValueCommand; use Psr\Container\ContainerInterface as DrushContainer; -use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerInterface; use Robo\ClassDiscovery\RelativeNamespaceDiscovery; use Robo\Contract\ConfigAwareInterface; @@ -462,8 +461,8 @@ public function inflect(DrushContainer $container, $object): void if ($object instanceof ConfigAwareInterface) { $object->setConfig($container->get('config')); } - if ($object instanceof LoggerAwareInterface) { - $object->setLogger($container->get('logger')); + if (method_exists($object, 'setLoggerIfEmpty')) { + $object->setLoggerIfEmpty($container->get('logger')); } // Made available by DrushCommands (must preserve for basic bc) if ($object instanceof ProcessManagerAwareInterface) {