@@ -202,22 +202,20 @@ private function getProxyDumper()
202
202
/**
203
203
* Generates Service local temp variables.
204
204
*
205
- * @param string $cId
206
- * @param string $definition
205
+ * @param string $cId
206
+ * @param Definition $definition
207
+ * @param array $inlinedDefinitions
207
208
*
208
209
* @return string
209
210
*/
210
- private function addServiceLocalTempVariables ($ cId , $ definition )
211
+ private function addServiceLocalTempVariables ($ cId , Definition $ definition, array $ inlinedDefinitions )
211
212
{
212
213
static $ template = " \$%s = %s; \n" ;
213
214
214
- $ localDefinitions = array_merge (
215
- array ($ definition ),
216
- $ this ->getInlinedDefinitions ($ definition )
217
- );
215
+ array_unshift ($ inlinedDefinitions , $ definition );
218
216
219
217
$ calls = $ behavior = array ();
220
- foreach ($ localDefinitions as $ iDefinition ) {
218
+ foreach ($ inlinedDefinitions as $ iDefinition ) {
221
219
$ this ->getServiceCallsFromArguments ($ iDefinition ->getArguments (), $ calls , $ behavior );
222
220
$ this ->getServiceCallsFromArguments ($ iDefinition ->getMethodCalls (), $ calls , $ behavior );
223
221
$ this ->getServiceCallsFromArguments ($ iDefinition ->getProperties (), $ calls , $ behavior );
@@ -280,12 +278,13 @@ private function addProxyClasses()
280
278
/**
281
279
* Generates the require_once statement for service includes.
282
280
*
283
- * @param string $id The service id
281
+ * @param string $id
284
282
* @param Definition $definition
283
+ * @param array $inlinedDefinitions
285
284
*
286
285
* @return string
287
286
*/
288
- private function addServiceInclude ($ id , $ definition )
287
+ private function addServiceInclude ($ id , Definition $ definition, array $ inlinedDefinitions )
289
288
{
290
289
$ template = " require_once %s; \n" ;
291
290
$ code = '' ;
@@ -294,7 +293,7 @@ private function addServiceInclude($id, $definition)
294
293
$ code .= sprintf ($ template , $ this ->dumpValue ($ file ));
295
294
}
296
295
297
- foreach ($ this -> getInlinedDefinitions ( $ definition ) as $ definition ) {
296
+ foreach ($ inlinedDefinitions as $ definition ) {
298
297
if (null !== $ file = $ definition ->getFile ()) {
299
298
$ code .= sprintf ($ template , $ this ->dumpValue ($ file ));
300
299
}
@@ -310,21 +309,20 @@ private function addServiceInclude($id, $definition)
310
309
/**
311
310
* Generates the inline definition of a service.
312
311
*
313
- * @param string $id
314
- * @param Definition $definition
312
+ * @param string $id
313
+ * @param array $inlinedDefinitions
315
314
*
316
315
* @return string
317
316
*
318
317
* @throws RuntimeException When the factory definition is incomplete
319
318
* @throws ServiceCircularReferenceException When a circular reference is detected
320
319
*/
321
- private function addServiceInlinedDefinitions ($ id , $ definition )
320
+ private function addServiceInlinedDefinitions ($ id , array $ inlinedDefinitions )
322
321
{
323
322
$ code = '' ;
324
323
$ variableMap = $ this ->definitionVariables ;
325
324
$ nbOccurrences = new \SplObjectStorage ();
326
325
$ processed = new \SplObjectStorage ();
327
- $ inlinedDefinitions = $ this ->getInlinedDefinitions ($ definition );
328
326
329
327
foreach ($ inlinedDefinitions as $ definition ) {
330
328
if (false === $ nbOccurrences ->contains ($ definition )) {
@@ -375,14 +373,14 @@ private function addServiceInlinedDefinitions($id, $definition)
375
373
/**
376
374
* Adds the service return statement.
377
375
*
378
- * @param string $id Service id
379
- * @param Definition $definition
376
+ * @param string $ id
377
+ * @param bool $isSimpleInstance
380
378
*
381
379
* @return string
382
380
*/
383
- private function addServiceReturn ($ id , $ definition )
381
+ private function addServiceReturn ($ id , $ isSimpleInstance )
384
382
{
385
- if ($ this -> isSimpleInstance ( $ id , $ definition ) ) {
383
+ if ($ isSimpleInstance ) {
386
384
return " } \n" ;
387
385
}
388
386
@@ -394,13 +392,14 @@ private function addServiceReturn($id, $definition)
394
392
*
395
393
* @param string $id
396
394
* @param Definition $definition
395
+ * @param bool $isSimpleInstance
397
396
*
398
397
* @return string
399
398
*
400
399
* @throws InvalidArgumentException
401
400
* @throws RuntimeException
402
401
*/
403
- private function addServiceInstance ($ id , Definition $ definition )
402
+ private function addServiceInstance ($ id , Definition $ definition, $ isSimpleInstance )
404
403
{
405
404
$ class = $ definition ->getClass ();
406
405
@@ -414,26 +413,25 @@ private function addServiceInstance($id, Definition $definition)
414
413
throw new InvalidArgumentException (sprintf ('"%s" is not a valid class name for the "%s" service. ' , $ class , $ id ));
415
414
}
416
415
417
- $ simple = $ this ->isSimpleInstance ($ id , $ definition );
418
416
$ isProxyCandidate = $ this ->getProxyDumper ()->isProxyCandidate ($ definition );
419
417
$ instantiation = '' ;
420
418
421
419
if (!$ isProxyCandidate && $ definition ->isShared ()) {
422
- $ instantiation = "\$this->services[' $ id'] = " .($ simple ? '' : '$instance ' );
423
- } elseif (!$ simple ) {
420
+ $ instantiation = "\$this->services[' $ id'] = " .($ isSimpleInstance ? '' : '$instance ' );
421
+ } elseif (!$ isSimpleInstance ) {
424
422
$ instantiation = '$instance ' ;
425
423
}
426
424
427
425
$ return = '' ;
428
- if ($ simple ) {
426
+ if ($ isSimpleInstance ) {
429
427
$ return = 'return ' ;
430
428
} else {
431
429
$ instantiation .= ' = ' ;
432
430
}
433
431
434
432
$ code = $ this ->addNewInstance ($ definition , $ return , $ instantiation , $ id );
435
433
436
- if (!$ simple ) {
434
+ if (!$ isSimpleInstance ) {
437
435
$ code .= "\n" ;
438
436
}
439
437
@@ -500,20 +498,21 @@ private function addServiceProperties($id, Definition $definition, $variableName
500
498
/**
501
499
* Generates the inline definition setup.
502
500
*
503
- * @param string $id
504
- * @param Definition $definition
501
+ * @param string $id
502
+ * @param array $inlinedDefinitions
503
+ * @param bool $isSimpleInstance
505
504
*
506
505
* @return string
507
506
*
508
507
* @throws ServiceCircularReferenceException when the container contains a circular reference
509
508
*/
510
- private function addServiceInlinedDefinitionsSetup ($ id , Definition $ definition )
509
+ private function addServiceInlinedDefinitionsSetup ($ id , array $ inlinedDefinitions , $ isSimpleInstance )
511
510
{
512
511
$ this ->referenceVariables [$ id ] = new Variable ('instance ' );
513
512
514
513
$ code = '' ;
515
514
$ processed = new \SplObjectStorage ();
516
- foreach ($ this -> getInlinedDefinitions ( $ definition ) as $ iDefinition ) {
515
+ foreach ($ inlinedDefinitions as $ iDefinition ) {
517
516
if ($ processed ->contains ($ iDefinition )) {
518
517
continue ;
519
518
}
@@ -525,7 +524,7 @@ private function addServiceInlinedDefinitionsSetup($id, Definition $definition)
525
524
526
525
// if the instance is simple, the return statement has already been generated
527
526
// so, the only possible way to get there is because of a circular reference
528
- if ($ this -> isSimpleInstance ( $ id , $ definition ) ) {
527
+ if ($ isSimpleInstance ) {
529
528
throw new ServiceCircularReferenceException ($ id , array ($ id ));
530
529
}
531
530
@@ -683,16 +682,19 @@ private function addService($id, Definition $definition)
683
682
$ code .= sprintf (" @trigger_error(%s, E_USER_DEPRECATED); \n\n" , $ this ->export ($ definition ->getDeprecationMessage ($ id )));
684
683
}
685
684
685
+ $ inlinedDefinitions = $ this ->getInlinedDefinitions ($ definition );
686
+ $ isSimpleInstance = $ this ->isSimpleInstance ($ id , $ definition , $ inlinedDefinitions );
687
+
686
688
$ code .=
687
- $ this ->addServiceInclude ($ id , $ definition ).
688
- $ this ->addServiceLocalTempVariables ($ id , $ definition ).
689
- $ this ->addServiceInlinedDefinitions ($ id , $ definition ).
690
- $ this ->addServiceInstance ($ id , $ definition ).
691
- $ this ->addServiceInlinedDefinitionsSetup ($ id , $ definition ).
689
+ $ this ->addServiceInclude ($ id , $ definition, $ inlinedDefinitions ).
690
+ $ this ->addServiceLocalTempVariables ($ id , $ definition, $ inlinedDefinitions ).
691
+ $ this ->addServiceInlinedDefinitions ($ id , $ inlinedDefinitions ).
692
+ $ this ->addServiceInstance ($ id , $ definition, $ isSimpleInstance ).
693
+ $ this ->addServiceInlinedDefinitionsSetup ($ id , $ inlinedDefinitions , $ isSimpleInstance ).
692
694
$ this ->addServiceProperties ($ id , $ definition ).
693
695
$ this ->addServiceMethodCalls ($ id , $ definition ).
694
696
$ this ->addServiceConfigurator ($ id , $ definition ).
695
- $ this ->addServiceReturn ($ id , $ definition )
697
+ $ this ->addServiceReturn ($ id , $ isSimpleInstance )
696
698
;
697
699
698
700
$ this ->definitionVariables = null ;
@@ -1332,8 +1334,6 @@ private function getDefinitionsFromArguments(array $arguments)
1332
1334
foreach ($ arguments as $ argument ) {
1333
1335
if (is_array ($ argument )) {
1334
1336
$ definitions = array_merge ($ definitions , $ this ->getDefinitionsFromArguments ($ argument ));
1335
- } elseif ($ argument instanceof ArgumentInterface) {
1336
- $ definitions = array_merge ($ definitions , $ this ->getDefinitionsFromArguments ($ argument ->getValues ()));
1337
1337
} elseif ($ argument instanceof Definition) {
1338
1338
$ definitions = array_merge (
1339
1339
$ definitions ,
0 commit comments