@@ -503,10 +503,6 @@ private function isTrivialInstance(Definition $definition)
503
503
}
504
504
}
505
505
506
- if (false !== strpos ($ this ->dumpLiteralClass ($ this ->dumpValue ($ definition ->getClass ())), '$ ' )) {
507
- return false ;
508
- }
509
-
510
506
return true ;
511
507
}
512
508
@@ -598,18 +594,16 @@ private function addService($id, Definition $definition, &$file = null)
598
594
$ return = array ();
599
595
600
596
if ($ class = $ definition ->getClass ()) {
601
- $ class = $ this ->container ->resolveEnvPlaceholders ($ class );
597
+ $ class = $ class instanceof Parameter ? ' % ' . $ class . ' % ' : $ this ->container ->resolveEnvPlaceholders ($ class );
602
598
$ return [] = sprintf (0 === strpos ($ class , '% ' ) ? '@return object A %1$s instance ' : '@return \%s ' , ltrim ($ class , '\\' ));
603
599
} elseif ($ definition ->getFactory ()) {
604
600
$ factory = $ definition ->getFactory ();
605
601
if (\is_string ($ factory )) {
606
602
$ return [] = sprintf ('@return object An instance returned by %s() ' , $ factory );
607
603
} elseif (\is_array ($ factory ) && (\is_string ($ factory [0 ]) || $ factory [0 ] instanceof Definition || $ factory [0 ] instanceof Reference)) {
608
- if (\is_string ($ factory [0 ]) || $ factory [0 ] instanceof Reference) {
609
- $ return [] = sprintf ('@return object An instance returned by %s::%s() ' , (string ) $ factory [0 ], $ factory [1 ]);
610
- } elseif ($ factory [0 ] instanceof Definition) {
611
- $ return [] = sprintf ('@return object An instance returned by %s::%s() ' , $ factory [0 ]->getClass (), $ factory [1 ]);
612
- }
604
+ $ class = $ factory [0 ] instanceof Definition ? $ factory [0 ]->getClass () : (string ) $ factory [0 ];
605
+ $ class = $ class instanceof Parameter ? '% ' .$ class .'% ' : $ this ->container ->resolveEnvPlaceholders ($ class );
606
+ $ return [] = sprintf ('@return object An instance returned by %s::%s() ' , $ class , $ factory [1 ]);
613
607
}
614
608
}
615
609
@@ -704,7 +698,7 @@ private function addInlineVariables(&$head, &$tail, $id, array $arguments, $forC
704
698
if (\is_array ($ argument )) {
705
699
$ hasSelfRef = $ this ->addInlineVariables ($ head , $ tail , $ id , $ argument , $ forConstructor ) || $ hasSelfRef ;
706
700
} elseif ($ argument instanceof Reference) {
707
- $ hasSelfRef = $ this ->addInlineReference ($ head , $ tail , $ id , $ this ->container ->normalizeId ($ argument ), $ forConstructor ) || $ hasSelfRef ;
701
+ $ hasSelfRef = $ this ->addInlineReference ($ head , $ id , $ this ->container ->normalizeId ($ argument ), $ forConstructor ) || $ hasSelfRef ;
708
702
} elseif ($ argument instanceof Definition) {
709
703
$ hasSelfRef = $ this ->addInlineService ($ head , $ tail , $ id , $ argument , $ forConstructor ) || $ hasSelfRef ;
710
704
}
@@ -713,37 +707,31 @@ private function addInlineVariables(&$head, &$tail, $id, array $arguments, $forC
713
707
return $ hasSelfRef ;
714
708
}
715
709
716
- private function addInlineReference (&$ head , & $ tail , $ id , $ targetId , $ forConstructor )
710
+ private function addInlineReference (&$ code , $ id , $ targetId , $ forConstructor )
717
711
{
712
+ $ hasSelfRef = isset ($ this ->circularReferences [$ id ][$ targetId ]);
713
+
718
714
if ('service_container ' === $ targetId || isset ($ this ->referenceVariables [$ targetId ])) {
719
- return isset ( $ this -> circularReferences [ $ id ][ $ targetId ]) ;
715
+ return $ hasSelfRef ;
720
716
}
721
717
722
718
list ($ callCount , $ behavior ) = $ this ->serviceCalls [$ targetId ];
723
719
724
- if (2 > $ callCount && (!$ forConstructor || !isset ( $ this -> circularReferences [ $ id ][ $ targetId ]) )) {
725
- return isset ( $ this -> circularReferences [ $ id ][ $ targetId ]) ;
720
+ if (2 > $ callCount && (!$ hasSelfRef || !$ forConstructor )) {
721
+ return $ hasSelfRef ;
726
722
}
727
723
728
724
$ name = $ this ->getNextVariableName ();
729
725
$ this ->referenceVariables [$ targetId ] = new Variable ($ name );
730
726
731
727
$ reference = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE >= $ behavior ? new Reference ($ targetId , $ behavior ) : null ;
732
- $ code = sprintf (" \$%s = %s; \n" , $ name , $ this ->getServiceCall ($ targetId , $ reference ));
733
-
734
- if (!isset ($ this ->circularReferences [$ id ][$ targetId ])) {
735
- $ head .= $ code ;
728
+ $ code .= sprintf (" \$%s = %s; \n" , $ name , $ this ->getServiceCall ($ targetId , $ reference ));
736
729
737
- return false ;
730
+ if (!$ hasSelfRef || !$ forConstructor ) {
731
+ return $ hasSelfRef ;
738
732
}
739
733
740
- if (!$ forConstructor ) {
741
- $ tail .= $ code ;
742
-
743
- return true ;
744
- }
745
-
746
- $ head .= $ code .sprintf (<<<'EOTXT'
734
+ $ code .= sprintf (<<<'EOTXT'
747
735
748
736
if (isset($this->%s['%s'])) {
749
737
return $this->%1$s['%2$s'];
@@ -766,17 +754,21 @@ private function addInlineService(&$head, &$tail, $id, Definition $definition, $
766
754
767
755
$ arguments = array ($ definition ->getArguments (), $ definition ->getFactory ());
768
756
769
- if (2 > $ this ->inlinedDefinitions [$ definition ] && !$ definition ->getMethodCalls () && !$ definition ->getProperties () && !$ definition ->getConfigurator () && false === strpos ( $ this -> dumpValue ( $ definition -> getClass ()), ' $ ' ) ) {
757
+ if (2 > $ this ->inlinedDefinitions [$ definition ] && !$ definition ->getMethodCalls () && !$ definition ->getProperties () && !$ definition ->getConfigurator ()) {
770
758
return $ this ->addInlineVariables ($ head , $ tail , $ id , $ arguments , $ forConstructor );
771
759
}
772
760
773
761
$ name = $ this ->getNextVariableName ();
774
762
$ this ->definitionVariables [$ definition ] = new Variable ($ name );
775
763
776
764
$ code = '' ;
777
- $ hasSelfRef = $ this ->addInlineVariables ($ code , $ tail , $ id , $ arguments , $ forConstructor );
765
+ if ($ forConstructor ) {
766
+ $ hasSelfRef = $ this ->addInlineVariables ($ code , $ tail , $ id , $ arguments , $ forConstructor );
767
+ } else {
768
+ $ hasSelfRef = $ this ->addInlineVariables ($ code , $ code , $ id , $ arguments , $ forConstructor );
769
+ }
778
770
$ code .= $ this ->addNewInstance ($ definition , '$ ' .$ name , ' = ' , $ id );
779
- $ hasSelfRef ? $ tail .= ('' !== $ tail ? "\n" : '' ).$ code : $ head .= ('' !== $ head ? "\n" : '' ).$ code ;
771
+ $ hasSelfRef && ! $ forConstructor ? $ tail .= ('' !== $ tail ? "\n" : '' ).$ code : $ head .= ('' !== $ head ? "\n" : '' ).$ code ;
780
772
781
773
$ code = '' ;
782
774
$ arguments = array ($ definition ->getProperties (), $ definition ->getMethodCalls (), $ definition ->getConfigurator ());
0 commit comments