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 7cadc10
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
6 changes: 6 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ parameters:
count: 1
path: src/Command/LoadDataFixturesDoctrineODMCommand.php

-
message: '#^Method Psr\\Log\\AbstractLogger@anonymous/src/Command/LoadDataFixturesDoctrineODMCommand\.php\:88\:\:log\(\) has parameter \$message with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: src/Command/LoadDataFixturesDoctrineODMCommand.php

-
message: '#^Parameter \#1 \$dm of class Doctrine\\Common\\DataFixtures\\Executor\\MongoDBExecutor constructor expects Doctrine\\ODM\\MongoDB\\DocumentManager, Doctrine\\Persistence\\ObjectManager given\.$#'
identifier: argument.type
Expand Down
20 changes: 18 additions & 2 deletions src/Command/LoadDataFixturesDoctrineODMCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Doctrine\Bundle\MongoDBBundle\ManagerRegistry;
use Doctrine\Common\DataFixtures\Executor\MongoDBExecutor;
use Doctrine\Common\DataFixtures\Purger\MongoDBPurger;
use Psr\Log\AbstractLogger;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -83,8 +84,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($level, $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 7cadc10

Please sign in to comment.