File tree 2 files changed +15
-1
lines changed
2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,9 @@ class Container
32
32
/** @var array[] type => (high, low, no) => services */
33
33
protected array $ wiring = [];
34
34
35
+ /** @var object[] service name => instance */
36
+ protected array $ lazy = [];
37
+
35
38
/** @var object[] service name => instance */
36
39
private array $ instances = [];
37
40
@@ -215,7 +218,12 @@ public function createService(string $name): object
215
218
if ($ callback = ($ this ->factories [$ name ] ?? null )) {
216
219
$ service = $ this ->preventDeadLock ($ name , fn () => $ callback ());
217
220
} elseif (isset ($ this ->methods [$ method ])) {
218
- $ service = $ this ->preventDeadLock ($ name , fn () => $ this ->$ method ());
221
+ if (isset ($ this ->lazy [$ name ])) {
222
+ $ rc = new \ReflectionClass ($ this ->lazy [$ name ]);
223
+ $ service = $ rc ->newLazyProxy ($ this ->$ method (...));
224
+ } else {
225
+ $ service = $ this ->preventDeadLock ($ name , fn () => $ this ->$ method ());
226
+ }
219
227
} else {
220
228
throw new MissingServiceException (sprintf ("Service '%s' not found. " , $ name ));
221
229
}
Original file line number Diff line number Diff line change @@ -367,6 +367,12 @@ public function exportMeta(): array
367
367
$ all [$ class ][] = $ name ;
368
368
}
369
369
}
370
+
371
+ if ($ def instanceof Definitions \ServiceDefinition && PHP_VERSION_ID >= 80400 ) {
372
+ if (is_string ($ def ->getEntity ())) {
373
+ $ meta ['lazy ' ][$ name ] = $ def ->getEntity ();
374
+ }
375
+ }
370
376
}
371
377
372
378
[$ low , $ high ] = $ this ->autowiring ->getClassList ();
You can’t perform that action at this time.
0 commit comments