From 58b180c22277a7cfadcce9ed61af632669ef00a7 Mon Sep 17 00:00:00 2001 From: Richard Miller Date: Tue, 19 Mar 2013 11:27:13 +0000 Subject: [PATCH] Adding a bit more explanation to the config section of the DI introduction --- .../dependency_injection/introduction.rst | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/components/dependency_injection/introduction.rst b/components/dependency_injection/introduction.rst index 7ef0dcc34a1..0b6bbee06eb 100644 --- a/components/dependency_injection/introduction.rst +++ b/components/dependency_injection/introduction.rst @@ -179,8 +179,13 @@ should be as few times as possible at the entry point to your application. Setting Up the Container with Configuration Files ------------------------------------------------- -As well as setting up the services using PHP as above you can also use configuration -files. To do this you also need to install :doc:`the Config Component`. +As well as setting up the services using PHP as above you can also use +configuration files. This allows you to use XML or Yaml to write the definitions +for the services rather than using PHP to define the services as in the above +examples. In anything but the smallest applications it make sense to organise +the service definitions by moving them out into one or more configuration files. +To do this you also need to install +:doc:`the Config Component`. Loading an XML config file:: @@ -207,7 +212,19 @@ Loading a YAML config file:: If you want to load YAML config files then you will also need to install :doc:`The YAML component`. -The ``newsletter_manager`` and ``mailer`` services can be set up using config files: +If you do want to use PHP to create the services then you can move this +into a separate config file and load it in a similar way:: + + use Symfony\Component\DependencyInjection\ContainerBuilder; + use Symfony\Component\Config\FileLocator; + use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; + + $container = new ContainerBuilder(); + $loader = new PhpFileLoader($container, new FileLocator(__DIR__)); + $loader->load('services.php'); + +You can now set up the ``newsletter_manager`` and ``mailer`` services using +config files: .. configuration-block::