-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add auto-register compiler pass #43
Conversation
Codecov Report
@@ Coverage Diff @@
## master #43 +/- ##
=========================================
- Coverage 90.4% 89.7% -0.71%
=========================================
Files 17 18 +1
Lines 271 301 +30
=========================================
+ Hits 245 270 +25
- Misses 26 31 +5
Continue to review full report at Codecov.
|
I'm totally 👍 on this approach over the ones in #40/#39. |
+1 |
@kbond I really like the clean way of implementing it this way. The only question i have is we should add tests to it. Can you provided these or should i merge it an do it myself? |
Yeah, I wanted to see if this was acceptable before adding tests. I will try to get to writing some this week. |
Hi, My idea was to avoid changing configuration when event handler is very trivial, e.g. final class LogUserEvents
{
public function onUserWasRegistered(UserWasRegistered $event)
{
$this->pinba->log('user_was_registered');
}
public function onUserActivatedPremiumAccount(UserActivatedPremiumAccount $event)
{
$this->pinba->log('user_activated_premium_account');
}
// ...
} It looks waste of time for me to create class per event + fix configuration for cases like this one. By the way, my approach also supports |
@unkind I suppose I could loop over the public methods - does anyone foresee any side effects to this? |
Yes, that was the main idea. |
@kbond: Yeah, it'd register a listener for each public setter you have on the class. Also, it's way less clean. With Symfony 3.3 and autowiring, there really isn't any overhead to creating a new listener class. There's no configuration change, it's just a new file. |
I'll leave it as |
Ok, I added some functional tests and documentation. |
Yes, I liked the clean solution with only support for the @kbond Tnx for the test AND docs! Very happy with it I will review the rest later this week. |
It makes sense when you define what "job" is. SRP is not about it. |
Ping? |
@kbond Tnx, i just merged this. |
Awesome! Can we get a new release? |
A new release would be very helpful - I want to use this in a project, but I'm not going to set |
I updated some major things in the library and i'm waiting on crating a new major release because of that. The one thing i'm waiting for is the following I did not have had the time to test this out myself. I was on a holiday the past 3 weeks. I wil try to get the new release going asap. |
FYI, in 3.4, registering your handlers/subscribers in YAML will be even easier (see symfony/symfony#23991) Currently, your config might look like this: services:
App\Domain\User\CommandHandler\:
resource: ../../src/Domain/User/CommandHandler
tags: [command_handler]
App\Domain\User\EventSubscriber\:
resource: ../../src/Domain/User/EventSubscriber
tags: [event_subscriber]
App\Domain\Article\CommandHandler\:
resource: ../../src/Domain/Article/CommandHandler
tags: [command_handler]
App\Domain\Article\EventSubscriber\:
resource: ../../src/Domain/Article/EventSubscriber
tags: [event_subscriber]
App\Domain\Comment\CommandHandler\:
resource: ../../src/Domain/Comment/CommandHandler
tags: [command_handler]
App\Domain\Comment\EventSubscriber\:
resource: ../../src/Domain/Comment/EventSubscriber
tags: [event_subscriber] In 3.4, this config can be reduced to: services:
command_handlers:
namespace: App\Domain\
resource: ../../src/Domain/*/CommandHandler
tags: [command_handler]
event_subscribers:
namespace: App\Domain\
resource: ../../src/Domain/*/EventSubscriber
tags: [event_subscriber] |
This is an alternative to #40/#39.
This allows you to leave off the
subscribes_to
andhandles
tag attribute for subscribers/handlers that meet the following conditions:subscribes_to
/handles
tag parameters__invoke
__invoke
method parameterThe compiler pass auto-adds the proper
subscribes_to
/handles
tag parameter.In Symfony 3.3, it allows you to simply have this as your config: