Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass a PSR logger to LoadDataFixturesDoctrineCommand #454

Merged
merged 1 commit into from
Nov 13, 2024

Conversation

greg0ire
Copy link
Member

@greg0ire greg0ire commented Nov 6, 2024

Not doing so is deprecated.
See doctrine/data-fixtures#462

@greg0ire greg0ire added the Bug label Nov 6, 2024
@greg0ire greg0ire force-pushed the address-deprecation branch 2 times, most recently from af42133 to 5d0c3eb Compare November 6, 2024 10:06
@@ -8,6 +8,8 @@
<service id="doctrine.fixtures_load_command" class="Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand">
<argument type="service" id="doctrine.fixtures.loader" />
<argument type="service" id="doctrine" />
<argument type="collection"></argument>
<argument type="service" id="logger" on-invalid="null"/>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this is the right logger instance to use here, @derrabus maybe you will know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, I guess. In case, the app uses Monolog, we should subscribe to the Doctrine channel.

<tag name="monolog.logger" channel="doctrine" />

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thanks, that was the missing piece 👍

@greg0ire greg0ire added Improvement and removed Bug labels Nov 6, 2024
Comment on lines 145 to 157
$executor->setLogger($this->logger ?? static function ($message) use ($ui): void {
$ui->text(sprintf(' <comment>></comment> <info>%s</info>', $message));
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing a closure as logger is deprecated. We could use an anonymous class instead that extends PSR-3's AbstractLogger.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand your comment, but I see I made a big mistake here: I didn't check for support of the PSR-3 logger.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a straightforward way to detect it. I think I'll just bump the dependency.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I understood, Copilot gave me an example implementation. So… I guess I should remove the new $logger property entirely then.

@greg0ire greg0ire force-pushed the address-deprecation branch 2 times, most recently from fb8fefc to 5b9e0c0 Compare November 6, 2024 19:16
composer.json Outdated
@@ -21,7 +21,7 @@
],
"require": {
"php": "^7.4 || ^8.0",
"doctrine/data-fixtures": "^1.3",
"doctrine/data-fixtures": "^1.8",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I use __invoke, this could be postponed to 3.7 🤔

@greg0ire
Copy link
Member Author

ping @derrabus @SenseException 🙏

@greg0ire greg0ire added this to the 3.6.2 milestone Nov 13, 2024
@greg0ire greg0ire merged commit f44a224 into doctrine:3.6.x Nov 13, 2024
13 checks passed
@greg0ire greg0ire deleted the address-deprecation branch November 13, 2024 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants