@@ -63,7 +63,9 @@ public function getParameters(): array
63
63
public function getParameter ($ key )
64
64
{
65
65
if (!array_key_exists ($ key , $ this ->parameters )) {
66
- $ this ->parameters [$ key ] = $ this ->getDynamicParameter ($ key );
66
+ $ this ->parameters [$ key ] = $ this ->preventDeadLock ("% $ key% " , function () use ($ key ) {
67
+ return $ this ->getDynamicParameter ($ key );
68
+ });
67
69
}
68
70
return $ this ->parameters [$ key ];
69
71
}
@@ -211,22 +213,15 @@ public function createService(string $name, array $args = []): object
211
213
$ name = $ this ->aliases [$ name ] ?? $ name ;
212
214
$ method = self ::getMethodName ($ name );
213
215
$ cb = $ this ->methods [$ method ] ?? null ;
214
- if (isset ($ this ->creating [$ name ])) {
215
- throw new Nette \InvalidStateException (sprintf ('Circular reference detected for services: %s. ' , implode (', ' , array_keys ($ this ->creating ))));
216
-
217
- } elseif ($ cb === null ) {
216
+ if ($ cb === null ) {
218
217
throw new MissingServiceException (sprintf ("Service '%s' not found. " , $ name ));
219
218
}
220
219
221
- try {
222
- $ this ->creating [$ name ] = true ;
223
- $ service = $ cb instanceof \Closure
220
+ $ service = $ this ->preventDeadLock ($ name , function () use ($ cb , $ args , $ method ) {
221
+ return $ cb instanceof \Closure
224
222
? $ cb (...$ args )
225
223
: $ this ->$ method (...$ args );
226
-
227
- } finally {
228
- unset($ this ->creating [$ name ]);
229
- }
224
+ });
230
225
231
226
if (!is_object ($ service )) {
232
227
throw new Nette \UnexpectedValueException (sprintf (
@@ -317,6 +312,20 @@ public function findByTag(string $tag): array
317
312
}
318
313
319
314
315
+ private function preventDeadLock (string $ key , \Closure $ closure )
316
+ {
317
+ if (isset ($ this ->creating [$ key ])) {
318
+ throw new Nette \InvalidStateException (sprintf ('Circular reference detected for: %s. ' , implode (', ' , array_keys ($ this ->creating ))));
319
+ }
320
+ try {
321
+ $ this ->creating [$ key ] = true ;
322
+ return $ closure ();
323
+ } finally {
324
+ unset($ this ->creating [$ key ]);
325
+ }
326
+ }
327
+
328
+
320
329
/********************* autowiring ****************d*g**/
321
330
322
331
0 commit comments