Skip to content

Commit 6d2b810

Browse files
authored
Use PSR Logger instead of Closure in LoadDataFixturesDoctrineODMCommand (#865)
1 parent 33a9d71 commit 6d2b810

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
},
4141
"require-dev": {
4242
"doctrine/coding-standard": "^11.0",
43-
"doctrine/data-fixtures": "^1.7",
43+
"doctrine/data-fixtures": "^1.8 || ^2.0",
4444
"phpunit/phpunit": "^9.5.5",
4545
"psalm/plugin-symfony": "^5.0",
4646
"symfony/browser-kit": "^6.4 || ^7.0",
@@ -53,7 +53,7 @@
5353
"vimeo/psalm": "^5.25"
5454
},
5555
"conflict": {
56-
"doctrine/data-fixtures": "<1.3"
56+
"doctrine/data-fixtures": "<1.8"
5757
},
5858
"suggest": {
5959
"doctrine/data-fixtures": "Load data fixtures"

src/Command/LoadDataFixturesDoctrineODMCommand.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Doctrine\Bundle\MongoDBBundle\ManagerRegistry;
99
use Doctrine\Common\DataFixtures\Executor\MongoDBExecutor;
1010
use Doctrine\Common\DataFixtures\Purger\MongoDBPurger;
11+
use Psr\Log\AbstractLogger;
12+
use Stringable;
1113
use Symfony\Component\Console\Input\InputInterface;
1214
use Symfony\Component\Console\Input\InputOption;
1315
use Symfony\Component\Console\Output\OutputInterface;
@@ -83,8 +85,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8385

8486
$purger = new MongoDBPurger($dm);
8587
$executor = new MongoDBExecutor($dm, $purger);
86-
$executor->setLogger(static function ($message) use ($output): void {
87-
$output->writeln(sprintf(' <comment>></comment> <info>%s</info>', $message));
88+
$executor->setLogger(new class ($output) extends AbstractLogger {
89+
public function __construct(private readonly OutputInterface $output)
90+
{
91+
}
92+
93+
public function log(mixed $level, string|Stringable $message, array $context = []): void
94+
{
95+
$this->output->writeln(sprintf(' <comment>></comment> <info>%s</info>', $message));
96+
}
8897
});
8998
$executor->execute($fixtures, $input->getOption('append'));
9099

0 commit comments

Comments
 (0)