@@ -14,35 +14,35 @@ In some particular cases where a very heavy service is always requested,
14
14
but not always used, you may want to mark it as ``lazy `` to delay its instantiation.
15
15
16
16
In order to have services to lazily instantiate, you will first need to install
17
- the `ProxyManager bridge `_::
17
+ the `ProxyManager bridge `_:
18
18
19
- php composer.phar require symfony/proxy-manager-bridge:2.3.*
19
+ .. code-block :: bash
20
+ $ php composer.phar require symfony/proxy-manager-bridge:2.3.*
20
21
21
22
You can mark the service as ``lazy `` by manipulating its definitions:
22
23
23
-
24
24
.. configuration-block ::
25
25
26
26
.. code-block :: yaml
27
27
28
28
services :
29
29
foo :
30
- class : Example \Foo
30
+ class : Acme \Foo
31
31
lazy : true
32
32
33
33
.. code-block :: xml
34
34
35
- <service id =" foo" class =" Example \Foo" lazy =" true" />
35
+ <service id =" foo" class =" Acme \Foo" lazy =" true" />
36
36
37
37
.. code-block :: php
38
38
39
- $definition = new Definition('Example \Foo');
39
+ $definition = new Definition('Acme \Foo');
40
40
$definition->setLazy(true);
41
41
$container->setDefinition('foo', $definition);
42
42
43
43
You can then require the service from the container::
44
44
45
- $service = $container->get($serviceId );
45
+ $service = $container->get('foo' );
46
46
47
47
At this point the retrieved ``$service `` should be a virtual `proxy `_ with the same
48
48
signature of the class representing the service.
@@ -55,10 +55,9 @@ signature of the class representing the service.
55
55
The proxy gets initialized and the actual service is instantiated as soon as you interact
56
56
in any way with this object.
57
57
58
- Additional resources
58
+ Additional Resources
59
59
--------------------
60
60
61
-
62
61
You can read more about how proxies are instantiated, generated and initialized in
63
62
the `documentation of ProxyManager `_.
64
63
0 commit comments