Skip to content

Commit

Permalink
[symfony#4228] Moved requiring files to definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed May 23, 2015
1 parent 12ed2e6 commit 26c7813
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 41 deletions.
41 changes: 0 additions & 41 deletions components/dependency_injection/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -182,44 +182,3 @@ service by asking for the ``bar`` service like this::
foo:
class: Example\Foo
bar: "@foo"
Requiring Files
---------------

There might be use cases when you need to include another file just before
the service itself gets loaded. To do so, you can use the ``file`` directive.

.. configuration-block::

.. code-block:: yaml
services:
foo:
class: Example\Foo\Bar
file: "%kernel.root_dir%/src/path/to/file/foo.php"
.. code-block:: xml
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="foo" class="Example\Foo\Bar">
<file>%kernel.root_dir%/src/path/to/file/foo.php</file>
</service>
</services>
</container>
.. code-block:: php
use Symfony\Component\DependencyInjection\Definition;
$definition = new Definition('Example\Foo\Bar');
$definition->setFile('%kernel.root_dir%/src/path/to/file/foo.php');
$container->setDefinition('foo', $definition);
Notice that Symfony will internally call the PHP statement ``require_once``,
which means that your file will be included only once per request.
12 changes: 12 additions & 0 deletions components/dependency_injection/definitions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,15 @@ You can also replace any existing method calls with an array of new ones with::
the container is compiled. Once the container is compiled you cannot
manipulate service definitions further. To learn more about compiling
the container see :doc:`/components/dependency_injection/compilation`.

Requiring Files
~~~~~~~~~~~~~~~

There might be use cases when you need to include another file just before
the service itself gets loaded. To do so, you can use the
:method:`Symfony\\Component\\DependencyInjection\\Definition::setFile` method::

$definition->setFile('/src/path/to/file/foo.php');

Notice that Symfony will internally call the PHP statement ``require_once``,
which means that your file will be included only once per request.

0 comments on commit 26c7813

Please sign in to comment.