Skip to content

Improved the section about overriding bundle services #10054

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

Merged
merged 1 commit into from
Jul 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 6 additions & 22 deletions bundles/override.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,12 @@ If the controller is a service, see the next section on how to override it.
Services & Configuration
------------------------

If you want to modify service definitions of another bundle, you can use a compiler
pass to change the class of the service or to modify method calls. In the following
example, the implementing class for the ``original-service-id`` is changed to
``Acme\DemoBundle\YourService``::

// src/Acme/DemoBundle/DependencyInjection/Compiler/OverrideServiceCompilerPass.php
namespace Acme\DemoBundle\DependencyInjection\Compiler;

use Acme\DemoBundle\YourService;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class OverrideServiceCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$definition = $container->getDefinition('original-service-id');
$definition->setClass(YourService::class);
}
}

For more information on compiler passes, see :doc:`/service_container/compiler_passes`.
If you want to modify the services created by a bundle, you can use
:doc:`service decoration </service_container/service_decoration>`.

If you want to do more advanced manipulations, like removing services created by
other bundles, you must work with :doc:`service definitions </service_container/definitions>`
inside a :doc:`compiler pass </service_container/compiler_passes>`.

Entities & Entity Mapping
-------------------------
Expand Down
12 changes: 6 additions & 6 deletions service_container/compiler_passes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
How to Work with Compiler Passes in Bundles
===========================================

Compiler passes give you an opportunity to manipulate other service
definitions that have been registered with the service container. You
can read about how to create them in the components section
":ref:`components-di-separate-compiler-passes`".
Compiler passes give you an opportunity to manipulate other
:doc:`service definitions </service_container/definitions>` that have been
registered with the service container. You can read about how to create them in
the components section ":ref:`components-di-separate-compiler-passes`".

When using :ref:`separate compiler passes <components-di-separate-compiler-passes>`,
you need to register them in the ``build()`` method of the bundle class (this
Expand All @@ -31,8 +31,8 @@ is not needed when implementing the ``process()`` method in the extension)::
}
}

One of the most common use-cases of compiler passes is to work with tagged services
(read more about tags in ":doc:`/service_container/tags`"). If you are using
One of the most common use-cases of compiler passes is to work with
":doc:`service tags </service_container/tags>`". If you are using
custom tags in a bundle then by convention, tag names consist of the name of
the bundle (lowercase, underscores as separators), followed by a dot, and
finally the "real" name. For example, if you want to introduce some sort of
Expand Down