@@ -30,15 +30,10 @@ until you interact with the proxy in some way.
30
30
In PHP versions prior to 8.0 lazy services do not support parameters with
31
31
default values for built-in PHP classes (e.g. ``PDO ``).
32
32
33
- Installation
34
- ------------
33
+ .. versionadded :: 6.2
35
34
36
- In order to use the lazy service instantiation, you will need to install the
37
- ``symfony/proxy-manager-bridge `` package:
38
-
39
- .. code-block :: terminal
40
-
41
- $ composer require symfony/proxy-manager-bridge
35
+ Starting from Symfony 6.2, you don't have to install any package (e.g.
36
+ ``symfony/proxy-manager-bridge ``) in order to use the lazy service instantiation.
42
37
43
38
Configuration
44
39
-------------
@@ -81,32 +76,16 @@ You can mark the service as ``lazy`` by manipulating its definition:
81
76
$services->set(AppExtension::class)->lazy();
82
77
};
83
78
79
+ Once you inject the service into another service, a lazy ghost object with the
80
+ same signature of the class representing the service should be injected. A lazy
81
+ `ghost object `_ is an object that is created empty and that is able to initialize
82
+ itself when being accessed for the first time). The same happens when calling
83
+ ``Container::get() `` directly.
84
84
85
- Once you inject the service into another service, a virtual `proxy `_ with the
86
- same signature of the class representing the service should be injected. The
87
- same happens when calling ``Container::get() `` directly.
88
-
89
- The actual class will be instantiated as soon as you try to interact with the
90
- service (e.g. call one of its methods).
91
-
92
- To check if your proxy works you can check the interface of the received object::
85
+ To check if your lazy service works you can check the interface of the received object::
93
86
94
87
dump(class_implements($service));
95
- // the output should include "ProxyManager\Proxy\LazyLoadingInterface"
96
-
97
- .. note ::
98
-
99
- If you don't install the `ProxyManager bridge `_ , the container will skip
100
- over the ``lazy `` flag and directly instantiate the service as it would
101
- normally do.
102
-
103
- Additional Resources
104
- --------------------
105
-
106
- You can read more about how proxies are instantiated, generated and initialized
107
- in the `documentation of ProxyManager `_.
88
+ // the output should include "Symfony\Component\VarExporter\LazyGhostObjectInterface"
108
89
109
- .. _`ProxyManager bridge` : https://github.com/symfony/symfony/tree/master/src/Symfony/Bridge/ProxyManager
110
- .. _`proxy` : https://en.wikipedia.org/wiki/Proxy_pattern
111
- .. _`documentation of ProxyManager` : https://github.com/Ocramius/ProxyManager/blob/master/docs/lazy-loading-value-holder.md
90
+ .. _`ghost object` : https://en.wikipedia.org/wiki/Lazy_loading#Ghost
112
91
.. _`final` : https://www.php.net/manual/en/language.oop5.final.php
0 commit comments