-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[DI] add docs for new namespace option #8310
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
kbond
commented
Aug 28, 2017
Q | A |
---|---|
Doc fix? | no |
New docs? | yes |
Applies to? | 3.4 |
Fixed tickets? | symfony/symfony#23991 |
… 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
service_container.rst
Outdated
When using the ``resource`` option in YAML, the namespace prefix can only be used once | ||
per file when defining it as the ``id``. In order to have multiple definitions in the | ||
same file with the same namespace prefix, you can use the ``namespace`` option. When | ||
this option is used, the ``id`` can be anything as long as it is unique. For example, |
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.
IMO this sentence is confusing. One may ask: Where is the id now taken from?
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.
Should I remove the sentence?
service_container.rst
Outdated
this option is used, the ``id`` can be anything as long as it is unique. For example, | ||
you can define your services like this: | ||
|
||
.. configuration-block:: |
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 can omit the configuration block and just start with the YAML code block.
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.
service_container.rst
Outdated
@@ -923,6 +923,34 @@ them will not cause the container to be rebuilt. | |||
means that all classes are "available to be *used* as services" without needing | |||
to be manually configured. | |||
|
|||
The namespace Option |
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.
What about enclosing the following section in a sidebar
directive instead? IMO it's a nice addition for the YAML format, but not a totally new concept.
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.
70ec5df
to
16e0cc7
Compare
@kbond Can you tell me when this is a useful feature people (I didn't meant that to sound negative at all - I want to make sure I understand the precise use-case). Is it only when there are multiple classes in the same file? If not, I didn't quite understand the description of it. I would also prefer to put this doc somewhere else (though I'm not sure where). I want to keep the main article very light and focused on the 90% use-cases. |
Here is a use-case: SimpleBus/symfony-bridge#43 (comment) It allows you to use the same namespace multiple times in the same yaml file. |
FYI - XML has the namespace option already. I can find reference to it on this page: http://symfony.com/doc/current/service_container/3.3-di-changes.html. Don't know if it makes sense to move there as this is a 3.4 change. |
@kbond thanks for this contribution! I'm sorry we didn't merge it earlier. The doc your proposed was great ... but we try to not use sidebars in the docs (because you can't easily link to them directly) so I reworded the contents to be a normal section instead. Thanks! |
…luz) This PR was merged into the 3.4 branch. Discussion ---------- [DI] add docs for new namespace option | Q | A | ------------- | --- | Doc fix? | no | New docs? | yes | Applies to? | 3.4 | Fixed tickets? | symfony/symfony#23991 Commits ------- f395dad Reworded and turned the sidebar into a section 16e0cc7 [DI] add docs for new namespace option
* 3.4: Fix missing trailling commas [Serializer] Added missing ObjectNormalizer [Serializer] By default the serializer do not convert to lower case properties Added a note about named form types Update translation.rst minor symfony#8310 [DI] add docs for new namespace option (kbond, javiereguiluz) Added a note about controller arguments Documented the new behavior of getGroupSequence() method Fix UrlMatcher::match() URL Updated a diagram to SVG format
* 4.0: Fix missing trailling commas [Serializer] Added missing ObjectNormalizer [Serializer] By default the serializer do not convert to lower case properties Added a note about named form types Update translation.rst minor symfony#8310 [DI] add docs for new namespace option (kbond, javiereguiluz) Added a note about controller arguments Documented the new behavior of getGroupSequence() method Fix UrlMatcher::match() URL Updated a diagram to SVG format Added a missing namespace in CacheKernel example fix creating a CacheKernel in HTTP cache documentation