@@ -503,10 +503,6 @@ private function isTrivialInstance(Definition $definition)
503503 }
504504 }
505505
506- if (false !== strpos ($ this ->dumpLiteralClass ($ this ->dumpValue ($ definition ->getClass ())), '$ ' )) {
507- return false ;
508- }
509-
510506 return true ;
511507 }
512508
@@ -598,18 +594,16 @@ private function addService($id, Definition $definition, &$file = null)
598594 $ return = array ();
599595
600596 if ($ class = $ definition ->getClass ()) {
601- $ class = $ this ->container ->resolveEnvPlaceholders ($ class );
597+ $ class = $ class instanceof Parameter ? ' % ' . $ class . ' % ' : $ this ->container ->resolveEnvPlaceholders ($ class );
602598 $ return [] = sprintf (0 === strpos ($ class , '% ' ) ? '@return object A %1$s instance ' : '@return \%s ' , ltrim ($ class , '\\' ));
603599 } elseif ($ definition ->getFactory ()) {
604600 $ factory = $ definition ->getFactory ();
605601 if (\is_string ($ factory )) {
606602 $ return [] = sprintf ('@return object An instance returned by %s() ' , $ factory );
607603 } 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 ]);
613607 }
614608 }
615609
@@ -704,7 +698,7 @@ private function addInlineVariables(&$head, &$tail, $id, array $arguments, $forC
704698 if (\is_array ($ argument )) {
705699 $ hasSelfRef = $ this ->addInlineVariables ($ head , $ tail , $ id , $ argument , $ forConstructor ) || $ hasSelfRef ;
706700 } 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 ;
708702 } elseif ($ argument instanceof Definition) {
709703 $ hasSelfRef = $ this ->addInlineService ($ head , $ tail , $ id , $ argument , $ forConstructor ) || $ hasSelfRef ;
710704 }
@@ -713,37 +707,31 @@ private function addInlineVariables(&$head, &$tail, $id, array $arguments, $forC
713707 return $ hasSelfRef ;
714708 }
715709
716- private function addInlineReference (&$ head , & $ tail , $ id , $ targetId , $ forConstructor )
710+ private function addInlineReference (&$ code , $ id , $ targetId , $ forConstructor )
717711 {
712+ $ hasSelfRef = isset ($ this ->circularReferences [$ id ][$ targetId ]);
713+
718714 if ('service_container ' === $ targetId || isset ($ this ->referenceVariables [$ targetId ])) {
719- return isset ( $ this -> circularReferences [ $ id ][ $ targetId ]) ;
715+ return $ hasSelfRef ;
720716 }
721717
722718 list ($ callCount , $ behavior ) = $ this ->serviceCalls [$ targetId ];
723719
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 ;
726722 }
727723
728724 $ name = $ this ->getNextVariableName ();
729725 $ this ->referenceVariables [$ targetId ] = new Variable ($ name );
730726
731727 $ 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 ));
736729
737- return false ;
730+ if (!$ hasSelfRef || !$ forConstructor ) {
731+ return $ hasSelfRef ;
738732 }
739733
740- if (!$ forConstructor ) {
741- $ tail .= $ code ;
742-
743- return true ;
744- }
745-
746- $ head .= $ code .sprintf (<<<'EOTXT'
734+ $ code .= sprintf (<<<'EOTXT'
747735
748736 if (isset($this->%s['%s'])) {
749737 return $this->%1$s['%2$s'];
@@ -766,17 +754,21 @@ private function addInlineService(&$head, &$tail, $id, Definition $definition, $
766754
767755 $ arguments = array ($ definition ->getArguments (), $ definition ->getFactory ());
768756
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 ()) {
770758 return $ this ->addInlineVariables ($ head , $ tail , $ id , $ arguments , $ forConstructor );
771759 }
772760
773761 $ name = $ this ->getNextVariableName ();
774762 $ this ->definitionVariables [$ definition ] = new Variable ($ name );
775763
776764 $ 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+ }
778770 $ 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 ;
780772
781773 $ code = '' ;
782774 $ arguments = array ($ definition ->getProperties (), $ definition ->getMethodCalls (), $ definition ->getConfigurator ());
0 commit comments