-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI] PSR4 loader suggestion #22397
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
Comments
Adding new syntax adds complexity so better not if possible. services:
App\Domain\*\CommandHandler\:
resource: ../../src/Domain/*/CommandHandler
tags: [command_handler]
App\Domain\*\EventSubscriber\:
resource: ../../src/Domain/*/EventSubscriber
tags: [event_subscriber] |
@kbond interested in trying a PR doing what I described just above? |
@nicolas-grekas sure - I will give it a shot |
@nicolas-grekas having globs inside the key is not simpler IMO, as it is not a prefix anymore either. On a side note, it is already possible to use the same prefix multiple time in XML files, as the prefix is not used as a PHP array key there 😄 |
Yeah, having a glob in 2 places would be annoying... |
simpler than what? there has been no other proposal that really work (the proposed one doesn't, nothing personal :) ) |
Rereading your yesterday's comment @stof, it looks like I didn't get it then, sorry about that. |
… implementation) (kbond) This PR was merged into the 3.4 branch. Discussion ---------- [DI] Improve psr4-based service discovery (alternative implementation) | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #22397 | License | MIT | Doc PR | symfony/symfony-docs#8310 This is an alternative to #23986. It is simpler and doesn't require a second glob in the service id. This adds a `namespace` option. It is optional and if it isn't used, then it falls back to using the service id (current behaviour). As stof mentions in #22397 (comment), it is consistent with the xml loader. With this feature, you can define your services like this: ```yaml 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] ``` ping @stof, @nicolas-grekas Commits ------- 00d7f6f [DI] improve psr4-based service discovery with namespace option
I'm really enjoying the new PSR4 loader but have a suggestion. It would be nice if I could declare multiple definitions with the same prefix. Example:
I can't use
instanceof
here because my handlers/subscribers don't have interfaces.Ref: #22016 (comment)
The text was updated successfully, but these errors were encountered: