@@ -7,6 +7,13 @@ How to Override any Part of a Bundle
7
7
This document is a quick reference for how to override different parts of
8
8
third-party bundles.
9
9
10
+ .. note ::
11
+
12
+ Whenever you are extending a (part of a) bundle, make sure that your bundle
13
+ is registered in the kernel **after ** the bundle you're trying to override
14
+ parts of. Otherwise, your config that is supposed to override bundle
15
+ configuration, is instead overridden by it!
16
+
10
17
Templates
11
18
---------
12
19
@@ -35,7 +42,40 @@ inheritance. For more information, see :doc:`/cookbook/bundles/inheritance`.
35
42
Services & Configuration
36
43
------------------------
37
44
38
- In progress...
45
+ In order to completely override a service, just define the service as you would
46
+ usual, but making sure the id of the service is identical to the one you are
47
+ overriding.
48
+
49
+ In order to extend a service (e.g. just add a method, but leaving the
50
+ dependencies or tags intact), make sure the class name is defined as a parameter
51
+ in the service config of the bundle containing the service. Then, in your bundle
52
+ you can override the class name by setting the parameter directly in the
53
+ container in the Extension class of your bundle:
54
+
55
+ .. code-block :: html+php
56
+ <?php
57
+
58
+ namespace Foo\B arBundle\D ependencyInjection;
59
+
60
+ use Symfony\C omponent\D ependencyInjection\C ontainerBuilder;
61
+ use Symfony\C omponent\C onfig\F ileLocator;
62
+ use Symfony\C omponent\H ttpKernel\D ependencyInjection\E xtension;
63
+ use Symfony\C omponent\D ependencyInjection\L oader;
64
+
65
+ class FooBarExtension extends Extension
66
+ {
67
+
68
+ public function load(array $configs, ContainerBuilder $container)
69
+ {
70
+ $configuration = new Configuration();
71
+ $config = $this->processConfiguration($configuration, $configs);
72
+
73
+ $container->setParameter('parameter_name.containing.service_class', 'Foo\B arBundle\S ervice\S ervice');
74
+
75
+ $loader = new Loader\X mlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
76
+ $loader->load('services.xml');
77
+ }
78
+ }
39
79
40
80
Entities & Entity mapping
41
81
-------------------------
0 commit comments