Skip to content

Commit 53ab044

Browse files
committed
Merge pull request #2320 from richardmiller/adding_to_config_in_di_intro
Adding a bit more explanation to the config section of the DI introducti...
2 parents 8e530de + 58b180c commit 53ab044

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
@@ -178,8 +178,13 @@ should be as few times as possible at the entry point to your application.
178178
Setting Up the Container with Configuration Files
179179
-------------------------------------------------
180180

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

184189
Loading an XML config file::
185190

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

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

211228
.. configuration-block::
212229

0 commit comments

Comments
 (0)