Skip to content

Commit 03a8055

Browse files
committed
minor #10054 Improved the section about overriding bundle services (javiereguiluz)
This PR was merged into the 2.8 branch. Discussion ---------- Improved the section about overriding bundle services Fixes #7102 ... and removes an unneeded example to avoid duplicating contents in the docs. Commits ------- e95bf63 Improved the section about overriding bundle services
2 parents b6b8b4b + e95bf63 commit 03a8055

File tree

2 files changed

+12
-28
lines changed

2 files changed

+12
-28
lines changed

bundles/override.rst

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,12 @@ If the controller is a service, see the next section on how to override it.
4545
Services & Configuration
4646
------------------------
4747

48-
If you want to modify service definitions of another bundle, you can use a compiler
49-
pass to change the class of the service or to modify method calls. In the following
50-
example, the implementing class for the ``original-service-id`` is changed to
51-
``Acme\DemoBundle\YourService``::
52-
53-
// src/Acme/DemoBundle/DependencyInjection/Compiler/OverrideServiceCompilerPass.php
54-
namespace Acme\DemoBundle\DependencyInjection\Compiler;
55-
56-
use Acme\DemoBundle\YourService;
57-
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
58-
use Symfony\Component\DependencyInjection\ContainerBuilder;
59-
60-
class OverrideServiceCompilerPass implements CompilerPassInterface
61-
{
62-
public function process(ContainerBuilder $container)
63-
{
64-
$definition = $container->getDefinition('original-service-id');
65-
$definition->setClass(YourService::class);
66-
}
67-
}
68-
69-
For more information on compiler passes, see :doc:`/service_container/compiler_passes`.
48+
If you want to modify the services created by a bundle, you can use
49+
:doc:`service decoration </service_container/service_decoration>`.
50+
51+
If you want to do more advanced manipulations, like removing services created by
52+
other bundles, you must work with :doc:`service definitions </service_container/definitions>`
53+
inside a :doc:`compiler pass </service_container/compiler_passes>`.
7054

7155
Entities & Entity Mapping
7256
-------------------------

service_container/compiler_passes.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
How to Work with Compiler Passes in Bundles
66
===========================================
77

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

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

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

0 commit comments

Comments
 (0)