diff --git a/components/dependency_injection/advanced.rst b/components/dependency_injection/advanced.rst index 82263ca6e66..d333a38de74 100644 --- a/components/dependency_injection/advanced.rst +++ b/components/dependency_injection/advanced.rst @@ -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 - - - - - - - %kernel.root_dir%/src/path/to/file/foo.php - - - - - .. 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. diff --git a/components/dependency_injection/definitions.rst b/components/dependency_injection/definitions.rst index c9d1e72cb3d..9c9574c7b9b 100644 --- a/components/dependency_injection/definitions.rst +++ b/components/dependency_injection/definitions.rst @@ -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.