From ba7e5670b91e215ee47f8e173bf3964213707317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 6 Nov 2024 10:55:31 +0100 Subject: [PATCH] Pass a PSR logger to LoadDataFixturesDoctrineCommand Not doing so is deprecated. See https://github.com/doctrine/data-fixtures/pull/462 --- .../LoadDataFixturesDoctrineCommand.php | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Command/LoadDataFixturesDoctrineCommand.php b/src/Command/LoadDataFixturesDoctrineCommand.php index 6ca2c78..4aecac9 100644 --- a/src/Command/LoadDataFixturesDoctrineCommand.php +++ b/src/Command/LoadDataFixturesDoctrineCommand.php @@ -12,6 +12,7 @@ use Doctrine\Common\DataFixtures\Executor\ORMExecutor; use Doctrine\ORM\EntityManagerInterface; use Doctrine\Persistence\ManagerRegistry; +use Psr\Log\AbstractLogger; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -134,9 +135,27 @@ private function doExecute(InputInterface $input, OutputInterface $output): int $input->getOption('purge-with-truncate'), ); $executor = new ORMExecutor($em, $purger); - $executor->setLogger(static function ($message) use ($ui): void { - $ui->text(sprintf(' > %s', $message)); + $executor->setLogger(new class ($ui) extends AbstractLogger { + private SymfonyStyle $ui; + + public function __construct(SymfonyStyle $ui) + { + $this->ui = $ui; + } + + /** {@inheritDoc} */ + public function log($level, $message, array $context = []): void + { + $this->ui->text(sprintf(' > %s', $message)); + } + + /** @deprecated to be removed when dropping support for doctrine/data-fixtures <1.8 */ + public function __invoke(string $message): void + { + $this->log(0, $message); + } }); + $executor->execute($fixtures, $input->getOption('append')); return 0;