From 41376f73d105c106af7ff1d646f453596283d03d Mon Sep 17 00:00:00 2001 From: Grayson Koonce Date: Mon, 3 Sep 2012 16:35:57 -0700 Subject: [PATCH 1/3] adding ->compile to parent services docs, adding missing use statements --- components/dependency_injection/parentservices.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/components/dependency_injection/parentservices.rst b/components/dependency_injection/parentservices.rst index bc21cc2761f..303fe0aaffa 100644 --- a/components/dependency_injection/parentservices.rst +++ b/components/dependency_injection/parentservices.rst @@ -236,6 +236,7 @@ a parent for a service. .. code-block:: php use Symfony\Component\DependencyInjection\Definition; + use Symfony\Component\DependencyInjection\DefinitionDecorator; use Symfony\Component\DependencyInjection\Reference; // ... @@ -265,6 +266,8 @@ a parent for a service. '%greeting_card_manager.class%' ); + $container->compile(); + In this context, having a ``parent`` service implies that the arguments and method calls of the parent service should be used for the child services. Specifically, the setter methods defined for the parent service will be called @@ -482,6 +485,7 @@ If you had the following config: .. code-block:: php use Symfony\Component\DependencyInjection\Definition; + use Symfony\Component\DependencyInjection\DefinitionDecorator; use Symfony\Component\DependencyInjection\Reference; // ... @@ -505,6 +509,8 @@ If you had the following config: new Reference('another_filter') )); + $container->compile(); + In this example, the ``setFilter`` of the ``newsletter_manager`` service will be called twice, resulting in the ``$filters`` array containing both ``my_filter`` and ``another_filter`` objects. This is great if you just want From c99cce51d35a117727a990f5a1544491f6e7d3b4 Mon Sep 17 00:00:00 2001 From: Grayson Koonce Date: Tue, 4 Sep 2012 11:25:55 -0700 Subject: [PATCH 2/3] adding compile call to overriding parent services section --- components/dependency_injection/parentservices.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/dependency_injection/parentservices.rst b/components/dependency_injection/parentservices.rst index 303fe0aaffa..3282584314b 100644 --- a/components/dependency_injection/parentservices.rst +++ b/components/dependency_injection/parentservices.rst @@ -367,6 +367,7 @@ to the ``NewsletterManager`` class, the config would look like this: .. code-block:: php use Symfony\Component\DependencyInjection\Definition; + use Symfony\Component\DependencyInjection\DefinitionDecorator; use Symfony\Component\DependencyInjection\Reference; // ... @@ -399,6 +400,8 @@ to the ``NewsletterManager`` class, the config would look like this: '%greeting_card_manager.class%' ); + $container->compile(); + The ``GreetingCardManager`` will receive the same dependencies as before, but the ``NewsletterManager`` will be passed the ``my_alternative_mailer`` instead of the ``my_mailer`` service. From 174136ef737cd5b02286764fc6d5e64087aa2696 Mon Sep 17 00:00:00 2001 From: Grayson Koonce Date: Fri, 14 Sep 2012 11:07:28 -0700 Subject: [PATCH 3/3] using note to indicate container needing to be compiled --- components/dependency_injection/parentservices.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/components/dependency_injection/parentservices.rst b/components/dependency_injection/parentservices.rst index 3282584314b..4e23b784688 100644 --- a/components/dependency_injection/parentservices.rst +++ b/components/dependency_injection/parentservices.rst @@ -266,8 +266,6 @@ a parent for a service. '%greeting_card_manager.class%' ); - $container->compile(); - In this context, having a ``parent`` service implies that the arguments and method calls of the parent service should be used for the child services. Specifically, the setter methods defined for the parent service will be called @@ -287,6 +285,12 @@ can only be used as a parent service and cannot be used directly as a service to inject and will be removed at compile time. In other words, it exists merely as a "template" that other services can use. +.. note:: + + In order for parent dependencies to resolve, the ``ContainerBuilder`` must + first be compiled. See :doc:`/components/dependency_injection/compilation` + for more details. + Overriding Parent Dependencies ------------------------------ @@ -400,8 +404,6 @@ to the ``NewsletterManager`` class, the config would look like this: '%greeting_card_manager.class%' ); - $container->compile(); - The ``GreetingCardManager`` will receive the same dependencies as before, but the ``NewsletterManager`` will be passed the ``my_alternative_mailer`` instead of the ``my_mailer`` service. @@ -512,8 +514,6 @@ If you had the following config: new Reference('another_filter') )); - $container->compile(); - In this example, the ``setFilter`` of the ``newsletter_manager`` service will be called twice, resulting in the ``$filters`` array containing both ``my_filter`` and ``another_filter`` objects. This is great if you just want