@@ -35,7 +35,36 @@ inheritance. For more information, see :doc:`/cookbook/bundles/inheritance`.
35
35
Services & Configuration
36
36
------------------------
37
37
38
- In progress...
38
+ In order to override/extend a service, there are two options. Firstly, you can
39
+ set the parameter holding the service's class name to your own class by setting
40
+ it in the config.yml. This of course is only possible if the class name is
41
+ defined as a parameter in the service config of the bundle containing the
42
+ service. Secondly, if this is not the case, or if you want to make sure the
43
+ class is always overridden when your bundle is used, you should use a compiler
44
+ pass:
45
+
46
+ .. code-block :: php
47
+ namespace Foo\BarBundle\DependencyInjection\Compiler;
48
+
49
+ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
50
+ use Symfony\Component\DependencyInjection\ContainerBuilder;
51
+
52
+ class OverrideServiceCompilerPass implements CompilerPassInterface
53
+ {
54
+
55
+ public function process(ContainerBuilder $container)
56
+ {
57
+ $definition = $container->getDefinition('original-service-id');
58
+ $definition->setClass('Foo\BarBundle\YourService');
59
+ }
60
+ }
61
+
62
+ In this example we fetch the service definition of the original service, and set
63
+ it's class name to our own class.
64
+
65
+ See `/cookbook/service_container/compiler_passes ` for information on how to use
66
+ compiler passes. If you want to do something beyond just overriding the class -
67
+ like adding a method call - You can only use the compiler pass method.
39
68
40
69
Entities & Entity mapping
41
70
-------------------------
0 commit comments