From 7ec7c7e13b9e182136d52b09730e800738b28e87 Mon Sep 17 00:00:00 2001 From: "Andrew (Andrius) Marcinkevicius" Date: Thu, 8 Jan 2015 13:03:57 +0200 Subject: [PATCH] Update service_container.rst | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | 2.3 | Fixed tickets | --- book/service_container.rst | 46 ++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/book/service_container.rst b/book/service_container.rst index a5253d7b3bc..fef11d05fda 100644 --- a/book/service_container.rst +++ b/book/service_container.rst @@ -121,7 +121,8 @@ be specified in YAML, XML or PHP: + xsi:schemaLocation="http://symfony.com/schema/dic/services + http://symfony.com/schema/dic/services/services-1.0.xsd"> @@ -216,7 +217,8 @@ straightforward. Parameters make defining services more organized and flexible: + xsi:schemaLocation="http://symfony.com/schema/dic/services + http://symfony.com/schema/dic/services/services-1.0.xsd"> sendmail @@ -358,7 +360,8 @@ directories don't exist, create them. + xsi:schemaLocation="http://symfony.com/schema/dic/services + http://symfony.com/schema/dic/services/services-1.0.xsd"> sendmail @@ -402,7 +405,8 @@ configuration. + xsi:schemaLocation="http://symfony.com/schema/dic/services + http://symfony.com/schema/dic/services/services-1.0.xsd"> @@ -481,8 +485,10 @@ invokes the service container extension inside the FrameworkBundle: + xsi:schemaLocation="http://symfony.com/schema/dic/services + http://symfony.com/schema/dic/services/services-1.0.xsd + http://symfony.com/schema/dic/symfony + http://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> @@ -605,6 +611,7 @@ the service container gives you a much more appealing option: services: my_mailer: # ... + newsletter_manager: class: Acme\HelloBundle\Newsletter\NewsletterManager arguments: ["@my_mailer"] @@ -615,12 +622,14 @@ the service container gives you a much more appealing option: + xsi:schemaLocation="http://symfony.com/schema/dic/services + http://symfony.com/schema/dic/services/services-1.0.xsd"> + @@ -634,6 +643,7 @@ the service container gives you a much more appealing option: use Symfony\Component\DependencyInjection\Reference; $container->setDefinition('my_mailer', ...); + $container->setDefinition('newsletter_manager', new Definition( 'Acme\HelloBundle\Newsletter\NewsletterManager', array(new Reference('my_mailer')) @@ -686,6 +696,7 @@ Injecting the dependency by the setter method just needs a change of syntax: services: my_mailer: # ... + newsletter_manager: class: Acme\HelloBundle\Newsletter\NewsletterManager calls: @@ -697,12 +708,14 @@ Injecting the dependency by the setter method just needs a change of syntax: + xsi:schemaLocation="http://symfony.com/schema/dic/services + http://symfony.com/schema/dic/services/services-1.0.xsd"> + @@ -718,6 +731,7 @@ Injecting the dependency by the setter method just needs a change of syntax: use Symfony\Component\DependencyInjection\Reference; $container->setDefinition('my_mailer', ...); + $container->setDefinition('newsletter_manager', new Definition( 'Acme\HelloBundle\Newsletter\NewsletterManager' ))->addMethodCall('setMailer', array( @@ -756,12 +770,14 @@ it exists and do nothing if it doesn't: + xsi:schemaLocation="http://symfony.com/schema/dic/services + http://symfony.com/schema/dic/services/services-1.0.xsd"> + @@ -776,6 +792,7 @@ it exists and do nothing if it doesn't: use Symfony\Component\DependencyInjection\ContainerInterface; $container->setDefinition('my_mailer', ...); + $container->setDefinition('newsletter_manager', new Definition( 'Acme\HelloBundle\Newsletter\NewsletterManager', array( @@ -863,7 +880,8 @@ Configuring the service container is easy: + xsi:schemaLocation="http://symfony.com/schema/dic/services + http://symfony.com/schema/dic/services/services-1.0.xsd"> @@ -912,6 +930,7 @@ to be used for a specific purpose. Take the following example: services: foo.twig.extension: class: Acme\HelloBundle\Extension\FooExtension + public: false tags: - { name: twig.extension } @@ -921,11 +940,13 @@ to be used for a specific purpose. Take the following example: + xsi:schemaLocation="http://symfony.com/schema/dic/services + http://symfony.com/schema/dic/services/services-1.0.xsd"> + class="Acme\HelloBundle\Extension\FooExtension" + public="false"> @@ -937,6 +958,7 @@ to be used for a specific purpose. Take the following example: use Symfony\Component\DependencyInjection\Definition; $definition = new Definition('Acme\HelloBundle\Extension\FooExtension'); + $definition->setPublic(false); $definition->addTag('twig.extension'); $container->setDefinition('foo.twig.extension', $definition);