-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[MonologBridge] Use composition instead of inheritance in monolog bridge #35740
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
Conversation
51cb2f1
to
0abcc9f
Compare
Can you please give more details about the envisioned benefits? |
Well, the benefit is that you can combine behavior of various activation strategies when using composition. |
What I have in mind is to provide (in a dedicated bundle) a new ActivationStrategy implementation to be able to change dynamicaly (through endpoint or cli command or whatever) the actionLevel of ErrorLevelActivationStrategy or ChannelLevelActivationStrategy, and keep compatibility with HttpCodeActivationStrategy. |
You've basically implemented the decorator pattern for activation strategies. I see the benefit of stacking/decorating strategies, but the current implementation might break code that relies on the current inheritance. What we could do:
|
I see the point. Let me work on your second proposal. Additionally it will be more convenient to handle in monolog-bundle during the deprecated period. |
@derrabus @stof @nicolas-grekas Here is a new proposal regarding your feedback |
src/Symfony/Bridge/Monolog/Handler/FingersCrossed/HttpCodeActivationStrategy.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to add "symfony/deprecation-contracts": "^2.1"
to the bridge's composer.json.
...fony/Bridge/Monolog/Tests/Handler/FingersCrossed/HttpCodeActivationStrategyDecoratorTest.php
Outdated
Show resolved
Hide resolved
...fony/Bridge/Monolog/Tests/Handler/FingersCrossed/NotFoundActivationStrategyDecoratorTest.php
Outdated
Show resolved
Hide resolved
Looks good to me. I wonder if we should finalize the new decorator classes. We should rather encourage people to stack decorators than to extend ours. |
3f63171
to
5f0efd3
Compare
5f0efd3
to
0eb3578
Compare
Just rebased on master, anything else I can do ? |
0eb3578
to
f53661a
Compare
f53661a
to
02c582b
Compare
02c582b
to
1faa688
Compare
1faa688
to
205e644
Compare
205e644
to
e871564
Compare
Instead of creating new classes, I would instead accept both constructor signatures (we've done that multiple times in the past). The main benefit is to avoid having new class names. |
@pvgnd Do you still want to work on this PR? What do you think of my proposal? |
Hello @fabpot, your proposal was my first attempt before comments from other contributors. Introducing new classes allows us to make them final, which will discourage to break the decorator pattern. This will also make easier the deprecated code cleaning. If you prefer to keep old classes and manage 2 constructor signatures, I can rework the PR. Please let me know and I'll give some time to rework on this. |
If the goal was to make these classes final, you can mark them as such via the |
OK @fabpot I will update the PR |
deed44d
to
8e00615
Compare
@fabpot Can you have a look please and tell me if it's OK for you? |
*/ | ||
class HttpCodeActivationStrategy extends ErrorLevelActivationStrategy | ||
/* final */ class HttpCodeActivationStrategy extends ErrorLevelActivationStrategy implements ActivationStrategyInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use a @final
phpdoc instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -1,6 +1,11 @@ | |||
CHANGELOG | |||
========= | |||
|
|||
5.2.0 | |||
----- | |||
* The `$actionLevel` constructor argument of `Symfony\Bridge\Monolog\Handler\FingersCrossed\NotFoundActivationStrategy` has been deprecated and replaced by the `$inner` one which expects an ActivationStrategyInterface to decorate instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing blank line above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, I also mentioned that classes will become final in 6.0
*/ | ||
class NotFoundActivationStrategy extends ErrorLevelActivationStrategy | ||
/* final */ class NotFoundActivationStrategy extends ErrorLevelActivationStrategy implements ActivationStrategyInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use a @final
phpdoc instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
745760d
to
0fb1439
Compare
Thank you @pvgnd. |
In order to allow better customization in monolog activation strategy, this PR introduce composition instead of inheritance for these 2 classes :