Skip to content

Commit b2b53d5

Browse files
committed
Merge pull request #2316 from richardmiller/adding_parent_service_note
Adding a tip to the parent services definition page
2 parents 99add41 + be178d7 commit b2b53d5

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

components/dependency_injection/parentservices.rst

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,15 @@ a parent for a service.
196196
calls:
197197
- [ setMailer, [ @my_mailer ] ]
198198
- [ setEmailFormatter, [ @my_email_formatter] ]
199-
199+
200200
newsletter_manager:
201201
class: "%newsletter_manager.class%"
202202
parent: mail_manager
203-
203+
204204
greeting_card_manager:
205205
class: "%greeting_card_manager.class%"
206206
parent: mail_manager
207-
207+
208208
.. code-block:: xml
209209
210210
<parameters>
@@ -287,8 +287,8 @@ as a "template" that other services can use.
287287

288288
.. note::
289289

290-
In order for parent dependencies to resolve, the ``ContainerBuilder`` must
291-
first be compiled. See :doc:`/components/dependency_injection/compilation`
290+
In order for parent dependencies to resolve, the ``ContainerBuilder`` must
291+
first be compiled. See :doc:`/components/dependency_injection/compilation`
292292
for more details.
293293

294294
Overriding Parent Dependencies
@@ -322,17 +322,17 @@ to the ``NewsletterManager`` class, the config would look like this:
322322
calls:
323323
- [ setMailer, [ @my_mailer ] ]
324324
- [ setEmailFormatter, [ @my_email_formatter] ]
325-
325+
326326
newsletter_manager:
327327
class: "%newsletter_manager.class%"
328328
parent: mail_manager
329329
calls:
330330
- [ setMailer, [ @my_alternative_mailer ] ]
331-
331+
332332
greeting_card_manager:
333333
class: "%greeting_card_manager.class%"
334334
parent: mail_manager
335-
335+
336336
.. code-block:: xml
337337
338338
<parameters>
@@ -453,13 +453,13 @@ If you had the following config:
453453
abstract: true
454454
calls:
455455
- [ setFilter, [ @my_filter ] ]
456-
456+
457457
newsletter_manager:
458458
class: "%newsletter_manager.class%"
459459
parent: mail_manager
460460
calls:
461461
- [ setFilter, [ @another_filter ] ]
462-
462+
463463
.. code-block:: xml
464464
465465
<parameters>
@@ -518,5 +518,13 @@ In this example, the ``setFilter`` of the ``newsletter_manager`` service
518518
will be called twice, resulting in the ``$filters`` array containing both
519519
``my_filter`` and ``another_filter`` objects. This is great if you just want
520520
to add additional filters to the subclasses. If you want to replace the filters
521-
passed to the subclass, removing the parent setting from the config will
521+
passed to the subclass, removing the parent setting from the config will
522522
prevent the base class from calling ``setFilter``.
523+
524+
.. tip::
525+
526+
In the examples shown there is a similar relationship between the parent
527+
and child services and the underlying parent and child classes. This does
528+
not need to be the case though, you can extract common parts of similar
529+
service definitions into a parent service without also extracting a parent
530+
class.

0 commit comments

Comments
 (0)