@@ -37,39 +37,10 @@ If the controller is a service, see the next section on how to override it.
37
37
Services & Configuration
38
38
------------------------
39
39
40
- In order to override/extend a service, there are two options. First, you can
41
- set the parameter holding the service's class name to your own class by setting
42
- it in ``app/config/config.yml ``. This of course is only possible if the class name is
43
- defined as a parameter in the service config of the bundle containing the
44
- service. For example, to override the class used for Symfony's ``translator ``
45
- service, you would override the ``translator.class `` parameter. Knowing exactly
46
- which parameter to override may take some research. For the translator, the
47
- parameter is defined and used in the ``Resources/config/translation.xml `` file
48
- in the core FrameworkBundle:
49
-
50
- .. configuration-block ::
51
-
52
- .. code-block :: yaml
53
-
54
- # app/config/config.yml
55
- parameters :
56
- translator.class : Acme\HelloBundle\Translation\Translator
57
-
58
- .. code-block :: xml
59
-
60
- <!-- app/config/config.xml -->
61
- <parameters >
62
- <parameter key =" translator.class" >Acme\HelloBundle\Translation\Translator</parameter >
63
- </parameters >
64
-
65
- .. code-block :: php
66
-
67
- // app/config/config.php
68
- $container->setParameter('translator.class', 'Acme\HelloBundle\Translation\Translator');
69
-
70
- Secondly, if the class is not available as a parameter, you want to make sure the
71
- class is always overridden when your bundle is used or if you need to modify
72
- something beyond just the class name, you should use a compiler pass::
40
+ If you want to modify service definitions of another bundle, you can use a compiler
41
+ pass to change the class of the service or to modify method calls. In the following
42
+ example, the implementing class for the ``original-service-id `` is changed to
43
+ ``Acme\DemoBundle\YourService ``::
73
44
74
45
// src/Acme/DemoBundle/DependencyInjection/Compiler/OverrideServiceCompilerPass.php
75
46
namespace Acme\DemoBundle\DependencyInjection\Compiler;
@@ -86,12 +57,7 @@ something beyond just the class name, you should use a compiler pass::
86
57
}
87
58
}
88
59
89
- In this example you fetch the service definition of the original service, and set
90
- its class name to your own class.
91
-
92
- See :doc: `/service_container/compiler_passes ` for information on how to use
93
- compiler passes. If you want to do something beyond just overriding the class,
94
- like adding a method call, you can only use the compiler pass method.
60
+ For more information on compiler passes, see :doc: `/service_container/compiler_passes `.
95
61
96
62
Entities & Entity Mapping
97
63
-------------------------
0 commit comments