Skip to content

Commit

Permalink
Address deprecation of callable logger
Browse files Browse the repository at this point in the history
We must provide a psr logger instead.
  • Loading branch information
greg0ire committed Dec 8, 2024
1 parent 401750e commit f6d9d48
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/Command/LoadDataFixturesDoctrineODMCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Doctrine\Bundle\MongoDBBundle\ManagerRegistry;
use Doctrine\Common\DataFixtures\Executor\MongoDBExecutor;
use Doctrine\Common\DataFixtures\Purger\MongoDBPurger;
use Psr\Log\AbstractLogger;
use Stringable;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -83,8 +85,23 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$purger = new MongoDBPurger($dm);
$executor = new MongoDBExecutor($dm, $purger);
$executor->setLogger(static function ($message) use ($output): void {
$output->writeln(sprintf(' <comment>></comment> <info>%s</info>', $message));

$executor->setLogger(new class ($output) extends AbstractLogger {
public function __construct(private OutputInterface $output)
{
}

/** {@inheritDoc} */
public function log(mixed $level, string|Stringable $message, array $context = []): void
{
$this->output->writeln(sprintf(' <comment>></comment> <info>%s</info>', $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'));

Expand Down

0 comments on commit f6d9d48

Please sign in to comment.