-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[FrameworkBundle] Document service replacements feature #2228
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
How to replace services and aliases provided by other Bundles | ||
============================================================= | ||
|
||
.. versionadded:: 2.3 | ||
The ability to replace existing services and aliases | ||
is new to version 2.3 | ||
|
||
Sometimes you might want to replace service or alias that is provided by | ||
different Bundle; for example you might want to completely re-invent the | ||
wheel or just decorate implementation of particular feature. | ||
|
||
Lets assume that some bundle provides service with ID ``bundle.service`` | ||
and we want to replace that service with our implementation: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
.. configuration-block:: | ||
|
||
.. code-block:: yaml | ||
|
||
# yoursbundle/Resources/config/services.yml | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should use |
||
service: | ||
yoursbundle.my.service: | ||
class: YoursBundle\YourClass | ||
tags: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please put |
||
- { name: framework.service_replacer, replaces: bundle.service } | ||
|
||
.. code-block:: xml | ||
|
||
<!-- yoursbundle/Resources/config/services.xml --> | ||
<service id="yoursbundle.my.service" | ||
class="YoursBundle\YourClass"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be indented 4 spaces |
||
<tag name="framework.service_replacer" replaces="bundle.service" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can place |
||
</service> | ||
|
||
.. code-block:: php | ||
|
||
$container->register('yoursbundle.my.service', 'YoursBundle\YourClass') | ||
->addTag('framework.service_replacer', array('replaces' => 'bundle.service')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should use: $container
->register(...)
->addTag(..., array(
'replaces' => 'bundle.service',
))
; |
||
|
||
Now when you'll request ``bundle.service`` from container, you'll get yours | ||
implementation (``yoursbundle.my.service``) instead. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
.. note:: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be a |
||
|
||
If old service was tagged, the tags will be removed, you have to properly | ||
tag yours definition to behave correctly, as replacement. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
Old service will be still accessible witch changed ID, by default changed | ||
ID will have ``.orig`` suffix, but you can change it for some completely | ||
different, by setting ``renameTo`` argument on tag. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
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.