@@ -73,61 +73,6 @@ below) to access this service (via the alias).
7373
7474 Services are by default public.
7575
76- Synthetic Services
77- ------------------
78-
79- Synthetic services are services that are injected into the container instead
80- of being created by the container.
81-
82- For example, if you're using the :doc: `HttpKernel </components/http_kernel/introduction >`
83- component with the DependencyInjection component, then the ``request ``
84- service is injected in the
85- :method: `ContainerAwareHttpKernel::handle() <Symfony\\ Component\\ HttpKernel\\ DependencyInjection\\ ContainerAwareHttpKernel::handle> `
86- method when entering the request :doc: `scope </cookbook/service_container/scopes >`.
87- The class does not exist when there is no request, so it can't be included in
88- the container configuration. Also, the service should be different for every
89- subrequest in the application.
90-
91- To create a synthetic service, set ``synthetic `` to ``true ``:
92-
93- .. configuration-block ::
94-
95- .. code-block :: yaml
96-
97- services :
98- request :
99- synthetic : true
100-
101- .. code-block :: xml
102-
103- <?xml version =" 1.0" encoding =" UTF-8" ?>
104- <container xmlns =" http://symfony.com/schema/dic/services"
105- xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
106- xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" >
107-
108- <services >
109- <service id =" request" synthetic =" true" />
110- </services >
111- </container >
112-
113- .. code-block :: php
114-
115- use Symfony\Component\DependencyInjection\Definition;
116-
117- $container
118- ->setDefinition('request', new Definition())
119- ->setSynthetic(true);
120-
121- As you see, only the ``synthetic `` option is set. All other options are only used
122- to configure how a service is created by the container. As the service isn't
123- created by the container, these options are omitted.
124-
125- Now, you can inject the class by using
126- :method: `Container::set <Symfony\\ Component\\ DependencyInjection\\ Container::set> `::
127-
128- // ...
129- $container->set('request', new MyRequest(...));
130-
13176Aliasing
13277--------
13378
@@ -182,44 +127,3 @@ service by asking for the ``bar`` service like this::
182127 foo :
183128 class : Example\Foo
184129 bar : " @foo"
185-
186-
187- Requiring Files
188- ---------------
189-
190- There might be use cases when you need to include another file just before
191- the service itself gets loaded. To do so, you can use the ``file `` directive.
192-
193- .. configuration-block ::
194-
195- .. code-block :: yaml
196-
197- services :
198- foo :
199- class : Example\Foo\Bar
200- file : " %kernel.root_dir%/src/path/to/file/foo.php"
201-
202- .. code-block :: xml
203-
204- <?xml version =" 1.0" encoding =" UTF-8" ?>
205- <container xmlns =" http://symfony.com/schema/dic/services"
206- xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
207- xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" >
208-
209- <services >
210- <service id =" foo" class =" Example\Foo\Bar" >
211- <file >%kernel.root_dir%/src/path/to/file/foo.php</file >
212- </service >
213- </services >
214- </container >
215-
216- .. code-block :: php
217-
218- use Symfony\Component\DependencyInjection\Definition;
219-
220- $definition = new Definition('Example\Foo\Bar');
221- $definition->setFile('%kernel.root_dir%/src/path/to/file/foo.php');
222- $container->setDefinition('foo', $definition);
223-
224- Notice that Symfony will internally call the PHP statement ``require_once ``,
225- which means that your file will be included only once per request.
0 commit comments