Skip to content

Commit 58b180c

Browse files
Adding a bit more explanation to the config section of the DI introduction
1 parent 9dfb144 commit 58b180c

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

components/dependency_injection/introduction.rst

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,13 @@ should be as few times as possible at the entry point to your application.
179179
Setting Up the Container with Configuration Files
180180
-------------------------------------------------
181181

182-
As well as setting up the services using PHP as above you can also use configuration
183-
files. To do this you also need to install :doc:`the Config Component</components/config/introduction>`.
182+
As well as setting up the services using PHP as above you can also use
183+
configuration files. This allows you to use XML or Yaml to write the definitions
184+
for the services rather than using PHP to define the services as in the above
185+
examples. In anything but the smallest applications it make sense to organise
186+
the service definitions by moving them out into one or more configuration files.
187+
To do this you also need to install
188+
:doc:`the Config Component</components/config/introduction>`.
184189

185190
Loading an XML config file::
186191

@@ -207,7 +212,19 @@ Loading a YAML config file::
207212
If you want to load YAML config files then you will also need to install
208213
:doc:`The YAML component</components/yaml/introduction>`.
209214

210-
The ``newsletter_manager`` and ``mailer`` services can be set up using config files:
215+
If you do want to use PHP to create the services then you can move this
216+
into a separate config file and load it in a similar way::
217+
218+
use Symfony\Component\DependencyInjection\ContainerBuilder;
219+
use Symfony\Component\Config\FileLocator;
220+
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
221+
222+
$container = new ContainerBuilder();
223+
$loader = new PhpFileLoader($container, new FileLocator(__DIR__));
224+
$loader->load('services.php');
225+
226+
You can now set up the ``newsletter_manager`` and ``mailer`` services using
227+
config files:
211228

212229
.. configuration-block::
213230

0 commit comments

Comments
 (0)