@@ -489,10 +489,6 @@ private function isTrivialInstance(Definition $definition): bool
489
489
}
490
490
}
491
491
492
- if (false !== strpos ($ this ->dumpLiteralClass ($ this ->dumpValue ($ definition ->getClass ())), '$ ' )) {
493
- return false ;
494
- }
495
-
496
492
return true ;
497
493
}
498
494
@@ -559,18 +555,16 @@ private function addService(string $id, Definition $definition, string &$file =
559
555
$ return = array ();
560
556
561
557
if ($ class = $ definition ->getClass ()) {
562
- $ class = $ this ->container ->resolveEnvPlaceholders ($ class );
558
+ $ class = $ class instanceof Parameter ? ' % ' . $ class . ' % ' : $ this ->container ->resolveEnvPlaceholders ($ class );
563
559
$ return [] = sprintf (0 === strpos ($ class , '% ' ) ? '@return object A %1$s instance ' : '@return \%s ' , ltrim ($ class , '\\' ));
564
560
} elseif ($ definition ->getFactory ()) {
565
561
$ factory = $ definition ->getFactory ();
566
562
if (\is_string ($ factory )) {
567
563
$ return [] = sprintf ('@return object An instance returned by %s() ' , $ factory );
568
564
} elseif (\is_array ($ factory ) && (\is_string ($ factory [0 ]) || $ factory [0 ] instanceof Definition || $ factory [0 ] instanceof Reference)) {
569
- if (\is_string ($ factory [0 ]) || $ factory [0 ] instanceof Reference) {
570
- $ return [] = sprintf ('@return object An instance returned by %s::%s() ' , (string ) $ factory [0 ], $ factory [1 ]);
571
- } elseif ($ factory [0 ] instanceof Definition) {
572
- $ return [] = sprintf ('@return object An instance returned by %s::%s() ' , $ factory [0 ]->getClass (), $ factory [1 ]);
573
- }
565
+ $ class = $ factory [0 ] instanceof Definition ? $ factory [0 ]->getClass () : (string ) $ factory [0 ];
566
+ $ class = $ class instanceof Parameter ? '% ' .$ class .'% ' : $ this ->container ->resolveEnvPlaceholders ($ class );
567
+ $ return [] = sprintf ('@return object An instance returned by %s::%s() ' , $ class , $ factory [1 ]);
574
568
}
575
569
}
576
570
@@ -671,7 +665,7 @@ private function addInlineVariables(string &$head, string &$tail, string $id, ar
671
665
if (\is_array ($ argument )) {
672
666
$ hasSelfRef = $ this ->addInlineVariables ($ head , $ tail , $ id , $ argument , $ forConstructor ) || $ hasSelfRef ;
673
667
} elseif ($ argument instanceof Reference) {
674
- $ hasSelfRef = $ this ->addInlineReference ($ head , $ tail , $ id , $ argument , $ forConstructor ) || $ hasSelfRef ;
668
+ $ hasSelfRef = $ this ->addInlineReference ($ head , $ id , $ argument , $ forConstructor ) || $ hasSelfRef ;
675
669
} elseif ($ argument instanceof Definition) {
676
670
$ hasSelfRef = $ this ->addInlineService ($ head , $ tail , $ id , $ argument , $ forConstructor ) || $ hasSelfRef ;
677
671
}
@@ -680,37 +674,31 @@ private function addInlineVariables(string &$head, string &$tail, string $id, ar
680
674
return $ hasSelfRef ;
681
675
}
682
676
683
- private function addInlineReference (string &$ head , string & $ tail , string $ id , string $ targetId , bool $ forConstructor ): bool
677
+ private function addInlineReference (string &$ code , string $ id , string $ targetId , bool $ forConstructor ): bool
684
678
{
679
+ $ hasSelfRef = isset ($ this ->circularReferences [$ id ][$ targetId ]);
680
+
685
681
if ('service_container ' === $ targetId || isset ($ this ->referenceVariables [$ targetId ])) {
686
- return isset ( $ this -> circularReferences [ $ id ][ $ targetId ]) ;
682
+ return $ hasSelfRef ;
687
683
}
688
684
689
685
list ($ callCount , $ behavior ) = $ this ->serviceCalls [$ targetId ];
690
686
691
- if (2 > $ callCount && (!$ forConstructor || !isset ( $ this -> circularReferences [ $ id ][ $ targetId ]) )) {
692
- return isset ( $ this -> circularReferences [ $ id ][ $ targetId ]) ;
687
+ if (2 > $ callCount && (!$ hasSelfRef || !$ forConstructor )) {
688
+ return $ hasSelfRef ;
693
689
}
694
690
695
691
$ name = $ this ->getNextVariableName ();
696
692
$ this ->referenceVariables [$ targetId ] = new Variable ($ name );
697
693
698
694
$ reference = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE >= $ behavior ? new Reference ($ targetId , $ behavior ) : null ;
699
- $ code = sprintf (" \$%s = %s; \n" , $ name , $ this ->getServiceCall ($ targetId , $ reference ));
700
-
701
- if (!isset ($ this ->circularReferences [$ id ][$ targetId ])) {
702
- $ head .= $ code ;
695
+ $ code .= sprintf (" \$%s = %s; \n" , $ name , $ this ->getServiceCall ($ targetId , $ reference ));
703
696
704
- return false ;
697
+ if (!$ hasSelfRef || !$ forConstructor ) {
698
+ return $ hasSelfRef ;
705
699
}
706
700
707
- if (!$ forConstructor ) {
708
- $ tail .= $ code ;
709
-
710
- return true ;
711
- }
712
-
713
- $ head .= $ code .sprintf (<<<'EOTXT'
701
+ $ code .= sprintf (<<<'EOTXT'
714
702
715
703
if (isset($this->%s['%s'])) {
716
704
return $this->%1$s['%2$s'];
@@ -733,17 +721,21 @@ private function addInlineService(string &$head, string &$tail, string $id, Defi
733
721
734
722
$ arguments = array ($ definition ->getArguments (), $ definition ->getFactory ());
735
723
736
- if (2 > $ this ->inlinedDefinitions [$ definition ] && !$ definition ->getMethodCalls () && !$ definition ->getProperties () && !$ definition ->getConfigurator () && false === strpos ( $ this -> dumpValue ( $ definition -> getClass ()), ' $ ' ) ) {
724
+ if (2 > $ this ->inlinedDefinitions [$ definition ] && !$ definition ->getMethodCalls () && !$ definition ->getProperties () && !$ definition ->getConfigurator ()) {
737
725
return $ this ->addInlineVariables ($ head , $ tail , $ id , $ arguments , $ forConstructor );
738
726
}
739
727
740
728
$ name = $ this ->getNextVariableName ();
741
729
$ this ->definitionVariables [$ definition ] = new Variable ($ name );
742
730
743
731
$ code = '' ;
744
- $ hasSelfRef = $ this ->addInlineVariables ($ code , $ tail , $ id , $ arguments , $ forConstructor );
732
+ if ($ forConstructor ) {
733
+ $ hasSelfRef = $ this ->addInlineVariables ($ code , $ tail , $ id , $ arguments , $ forConstructor );
734
+ } else {
735
+ $ hasSelfRef = $ this ->addInlineVariables ($ code , $ code , $ id , $ arguments , $ forConstructor );
736
+ }
745
737
$ code .= $ this ->addNewInstance ($ definition , '$ ' .$ name , ' = ' , $ id );
746
- $ hasSelfRef ? $ tail .= ('' !== $ tail ? "\n" : '' ).$ code : $ head .= ('' !== $ head ? "\n" : '' ).$ code ;
738
+ $ hasSelfRef && ! $ forConstructor ? $ tail .= ('' !== $ tail ? "\n" : '' ).$ code : $ head .= ('' !== $ head ? "\n" : '' ).$ code ;
747
739
748
740
$ code = '' ;
749
741
$ arguments = array ($ definition ->getProperties (), $ definition ->getMethodCalls (), $ definition ->getConfigurator ());
0 commit comments