@@ -202,19 +202,19 @@ 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 array $localDefinitions
207
+ * @param Definition|null $definition
207
208
*
208
209
* @return string
209
210
*/
210
- private function addServiceLocalTempVariables ($ cId , $ definition )
211
+ private function addServiceLocalTempVariables ($ cId , array $ localDefinitions , Definition $ definition = null )
211
212
{
212
213
static $ template = " \$%s = %s; \n" ;
213
214
214
- $ localDefinitions = array_merge (
215
- array ($ definition ),
216
- $ this ->getInlinedDefinitions ($ definition )
217
- );
215
+ if (null !== $ definition ) {
216
+ array_unshift ($ localDefinitions , $ definition );
217
+ }
218
218
219
219
$ calls = $ behavior = array ();
220
220
foreach ($ localDefinitions as $ iDefinition ) {
@@ -280,12 +280,13 @@ private function addProxyClasses()
280
280
/**
281
281
* Generates the require_once statement for service includes.
282
282
*
283
- * @param string $id The service id
283
+ * @param string $id
284
284
* @param Definition $definition
285
+ * @param array $inlinedDefinitions
285
286
*
286
287
* @return string
287
288
*/
288
- private function addServiceInclude ($ id , $ definition )
289
+ private function addServiceInclude ($ id , Definition $ definition, array $ inlinedDefinitions )
289
290
{
290
291
$ template = " require_once %s; \n" ;
291
292
$ code = '' ;
@@ -294,7 +295,7 @@ private function addServiceInclude($id, $definition)
294
295
$ code .= sprintf ($ template , $ this ->dumpValue ($ file ));
295
296
}
296
297
297
- foreach ($ this -> getInlinedDefinitions ( $ definition ) as $ definition ) {
298
+ foreach ($ inlinedDefinitions as $ definition ) {
298
299
if (null !== $ file = $ definition ->getFile ()) {
299
300
$ code .= sprintf ($ template , $ this ->dumpValue ($ file ));
300
301
}
@@ -310,21 +311,20 @@ private function addServiceInclude($id, $definition)
310
311
/**
311
312
* Generates the inline definition of a service.
312
313
*
313
- * @param string $id
314
- * @param Definition $definition
314
+ * @param string $id
315
+ * @param array $inlinedDefinitions
315
316
*
316
317
* @return string
317
318
*
318
319
* @throws RuntimeException When the factory definition is incomplete
319
320
* @throws ServiceCircularReferenceException When a circular reference is detected
320
321
*/
321
- private function addServiceInlinedDefinitions ($ id , $ definition )
322
+ private function addServiceInlinedDefinitions ($ id , array $ inlinedDefinitions )
322
323
{
323
324
$ code = '' ;
324
325
$ variableMap = $ this ->definitionVariables ;
325
326
$ nbOccurrences = new \SplObjectStorage ();
326
327
$ processed = new \SplObjectStorage ();
327
- $ inlinedDefinitions = $ this ->getInlinedDefinitions ($ definition );
328
328
329
329
foreach ($ inlinedDefinitions as $ definition ) {
330
330
if (false === $ nbOccurrences ->contains ($ definition )) {
@@ -375,14 +375,14 @@ private function addServiceInlinedDefinitions($id, $definition)
375
375
/**
376
376
* Adds the service return statement.
377
377
*
378
- * @param string $id Service id
379
- * @param Definition $definition
378
+ * @param string $ id
379
+ * @param bool $isSimpleInstance
380
380
*
381
381
* @return string
382
382
*/
383
- private function addServiceReturn ($ id , $ definition )
383
+ private function addServiceReturn ($ id , $ isSimpleInstance )
384
384
{
385
- if ($ this -> isSimpleInstance ( $ id , $ definition ) ) {
385
+ if ($ isSimpleInstance ) {
386
386
return " } \n" ;
387
387
}
388
388
@@ -394,13 +394,14 @@ private function addServiceReturn($id, $definition)
394
394
*
395
395
* @param string $id
396
396
* @param Definition $definition
397
+ * @param bool $simple
397
398
*
398
399
* @return string
399
400
*
400
401
* @throws InvalidArgumentException
401
402
* @throws RuntimeException
402
403
*/
403
- private function addServiceInstance ($ id , Definition $ definition )
404
+ private function addServiceInstance ($ id , Definition $ definition, $ simple )
404
405
{
405
406
$ class = $ definition ->getClass ();
406
407
@@ -414,7 +415,6 @@ private function addServiceInstance($id, Definition $definition)
414
415
throw new InvalidArgumentException (sprintf ('"%s" is not a valid class name for the "%s" service. ' , $ class , $ id ));
415
416
}
416
417
417
- $ simple = $ this ->isSimpleInstance ($ id , $ definition );
418
418
$ isProxyCandidate = $ this ->getProxyDumper ()->isProxyCandidate ($ definition );
419
419
$ instantiation = '' ;
420
420
@@ -500,20 +500,21 @@ private function addServiceProperties($id, Definition $definition, $variableName
500
500
/**
501
501
* Generates the inline definition setup.
502
502
*
503
- * @param string $id
504
- * @param Definition $definition
503
+ * @param string $id
504
+ * @param array $inlinedDefinitions
505
+ * @param bool $isSimpleInstance
505
506
*
506
507
* @return string
507
508
*
508
509
* @throws ServiceCircularReferenceException when the container contains a circular reference
509
510
*/
510
- private function addServiceInlinedDefinitionsSetup ($ id , Definition $ definition )
511
+ private function addServiceInlinedDefinitionsSetup ($ id , array $ inlinedDefinitions , $ isSimpleInstance )
511
512
{
512
513
$ this ->referenceVariables [$ id ] = new Variable ('instance ' );
513
514
514
515
$ code = '' ;
515
516
$ processed = new \SplObjectStorage ();
516
- foreach ($ this -> getInlinedDefinitions ( $ definition ) as $ iDefinition ) {
517
+ foreach ($ inlinedDefinitions as $ iDefinition ) {
517
518
if ($ processed ->contains ($ iDefinition )) {
518
519
continue ;
519
520
}
@@ -525,7 +526,7 @@ private function addServiceInlinedDefinitionsSetup($id, Definition $definition)
525
526
526
527
// if the instance is simple, the return statement has already been generated
527
528
// so, the only possible way to get there is because of a circular reference
528
- if ($ this -> isSimpleInstance ( $ id , $ definition ) ) {
529
+ if ($ isSimpleInstance ) {
529
530
throw new ServiceCircularReferenceException ($ id , array ($ id ));
530
531
}
531
532
@@ -683,16 +684,19 @@ private function addService($id, Definition $definition)
683
684
$ code .= sprintf (" @trigger_error(%s, E_USER_DEPRECATED); \n\n" , $ this ->export ($ definition ->getDeprecationMessage ($ id )));
684
685
}
685
686
687
+ $ inlinedDefinitions = $ this ->getInlinedDefinitions ($ definition );
688
+ $ isSimpleInstance = $ this ->isSimpleInstance ($ id , $ definition , $ inlinedDefinitions );
689
+
686
690
$ 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 ).
691
+ $ this ->addServiceInclude ($ id , $ definition, $ inlinedDefinitions ).
692
+ $ this ->addServiceLocalTempVariables ($ id , $ inlinedDefinitions , $ definition ).
693
+ $ this ->addServiceInlinedDefinitions ($ id , $ inlinedDefinitions ).
694
+ $ this ->addServiceInstance ($ id , $ definition, $ isSimpleInstance ).
695
+ $ this ->addServiceInlinedDefinitionsSetup ($ id , $ inlinedDefinitions , $ isSimpleInstance ).
692
696
$ this ->addServiceProperties ($ id , $ definition ).
693
697
$ this ->addServiceMethodCalls ($ id , $ definition ).
694
698
$ this ->addServiceConfigurator ($ id , $ definition ).
695
- $ this ->addServiceReturn ($ id , $ definition )
699
+ $ this ->addServiceReturn ($ id , $ isSimpleInstance )
696
700
;
697
701
698
702
$ this ->definitionVariables = null ;
@@ -1332,8 +1336,6 @@ private function getDefinitionsFromArguments(array $arguments)
1332
1336
foreach ($ arguments as $ argument ) {
1333
1337
if (is_array ($ argument )) {
1334
1338
$ definitions = array_merge ($ definitions , $ this ->getDefinitionsFromArguments ($ argument ));
1335
- } elseif ($ argument instanceof ArgumentInterface) {
1336
- $ definitions = array_merge ($ definitions , $ this ->getDefinitionsFromArguments ($ argument ->getValues ()));
1337
1339
} elseif ($ argument instanceof Definition) {
1338
1340
$ definitions = array_merge (
1339
1341
$ definitions ,
@@ -1452,6 +1454,9 @@ private function dumpValue($value, $interpolate = true)
1452
1454
if ($ value ->getMethodCalls ()) {
1453
1455
throw new RuntimeException ('Cannot dump definitions which have method calls. ' );
1454
1456
}
1457
+ if ($ value ->getProperties ()) {
1458
+ throw new RuntimeException ('Cannot dump definitions which have properties. ' );
1459
+ }
1455
1460
if (null !== $ value ->getConfigurator ()) {
1456
1461
throw new RuntimeException ('Cannot dump definitions which have a configurator. ' );
1457
1462
}
0 commit comments