Skip to content

Commit ba7e567

Browse files
committed
Pass a PSR logger to LoadDataFixturesDoctrineCommand
Not doing so is deprecated. See doctrine/data-fixtures#462
1 parent a345e6c commit ba7e567

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/Command/LoadDataFixturesDoctrineCommand.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
1313
use Doctrine\ORM\EntityManagerInterface;
1414
use Doctrine\Persistence\ManagerRegistry;
15+
use Psr\Log\AbstractLogger;
1516
use Symfony\Component\Console\Input\InputInterface;
1617
use Symfony\Component\Console\Input\InputOption;
1718
use Symfony\Component\Console\Output\OutputInterface;
@@ -134,9 +135,27 @@ private function doExecute(InputInterface $input, OutputInterface $output): int
134135
$input->getOption('purge-with-truncate'),
135136
);
136137
$executor = new ORMExecutor($em, $purger);
137-
$executor->setLogger(static function ($message) use ($ui): void {
138-
$ui->text(sprintf(' <comment>></comment> <info>%s</info>', $message));
138+
$executor->setLogger(new class ($ui) extends AbstractLogger {
139+
private SymfonyStyle $ui;
140+
141+
public function __construct(SymfonyStyle $ui)
142+
{
143+
$this->ui = $ui;
144+
}
145+
146+
/** {@inheritDoc} */
147+
public function log($level, $message, array $context = []): void
148+
{
149+
$this->ui->text(sprintf(' <comment>></comment> <info>%s</info>', $message));
150+
}
151+
152+
/** @deprecated to be removed when dropping support for doctrine/data-fixtures <1.8 */
153+
public function __invoke(string $message): void
154+
{
155+
$this->log(0, $message);
156+
}
139157
});
158+
140159
$executor->execute($fixtures, $input->getOption('append'));
141160

142161
return 0;

0 commit comments

Comments
 (0)