@@ -680,6 +680,7 @@ private function addServices()
680
680
private function addNewInstance (Definition $ definition , $ return , $ instantiation , $ id )
681
681
{
682
682
$ class = $ this ->dumpValue ($ definition ->getClass ());
683
+ $ return = ' ' .$ return .$ instantiation ;
683
684
684
685
$ arguments = array ();
685
686
foreach ($ definition ->getArguments () as $ value ) {
@@ -695,7 +696,7 @@ private function addNewInstance(Definition $definition, $return, $instantiation,
695
696
696
697
if ($ callable [0 ] instanceof Reference
697
698
|| ($ callable [0 ] instanceof Definition && $ this ->definitionVariables ->contains ($ callable [0 ]))) {
698
- return sprintf (" $ return { $ instantiation } %s->%s(%s); \n" , $ this ->dumpValue ($ callable [0 ]), $ callable [1 ], $ arguments ? implode (', ' , $ arguments ) : '' );
699
+ return $ return . sprintf ("%s->%s(%s); \n" , $ this ->dumpValue ($ callable [0 ]), $ callable [1 ], $ arguments ? implode (', ' , $ arguments ) : '' );
699
700
}
700
701
701
702
$ class = $ this ->dumpValue ($ callable [0 ]);
@@ -705,24 +706,24 @@ private function addNewInstance(Definition $definition, $return, $instantiation,
705
706
throw new RuntimeException (sprintf ('Cannot dump definition: The "%s" service is defined to be created by a factory but is missing the service reference, did you forget to define the factory service id or class? ' , $ id ));
706
707
}
707
708
708
- return sprintf (" $ return { $ instantiation } %s::%s(%s); \n" , $ this ->dumpLiteralClass ($ class ), $ callable [1 ], $ arguments ? implode (', ' , $ arguments ) : '' );
709
+ return $ return . sprintf ("%s::%s(%s); \n" , $ this ->dumpLiteralClass ($ class ), $ callable [1 ], $ arguments ? implode (', ' , $ arguments ) : '' );
709
710
}
710
711
711
712
if (0 === strpos ($ class , 'new ' )) {
712
- return sprintf (" $ return { $ instantiation } (%s)->%s(%s); \n" , $ this ->dumpValue ($ callable [0 ]), $ callable [1 ], $ arguments ? implode (', ' , $ arguments ) : '' );
713
+ return $ return . sprintf ("(%s)->%s(%s); \n" , $ this ->dumpValue ($ callable [0 ]), $ callable [1 ], $ arguments ? implode (', ' , $ arguments ) : '' );
713
714
}
714
715
715
- return sprintf (" $ return { $ instantiation } call_user_func(array(%s, '%s')%s); \n" , $ this ->dumpValue ($ callable [0 ]), $ callable [1 ], $ arguments ? ', ' .implode (', ' , $ arguments ) : '' );
716
+ return $ return . sprintf ("call_user_func(array(%s, '%s')%s); \n" , $ this ->dumpValue ($ callable [0 ]), $ callable [1 ], $ arguments ? ', ' .implode (', ' , $ arguments ) : '' );
716
717
}
717
718
718
- return sprintf (" $ return { $ instantiation } %s(%s); \n" , $ this ->dumpLiteralClass ($ this ->dumpValue ($ callable )), $ arguments ? implode (', ' , $ arguments ) : '' );
719
+ return $ return . sprintf ("%s(%s); \n" , $ this ->dumpLiteralClass ($ this ->dumpValue ($ callable )), $ arguments ? implode (', ' , $ arguments ) : '' );
719
720
}
720
721
721
722
if (false !== strpos ($ class , '$ ' )) {
722
- return sprintf (" \$class = %s; \n\n $ return { $ instantiation } new \$class(%s); \n" , $ class , implode (', ' , $ arguments ));
723
+ return sprintf (" \$class = %s; \n\n%snew \$class(%s); \n" , $ class, $ return , implode (', ' , $ arguments ));
723
724
}
724
725
725
- return sprintf (" $ return { $ instantiation } new %s(%s); \n" , $ this ->dumpLiteralClass ($ class ), implode (', ' , $ arguments ));
726
+ return $ return . sprintf ("new %s(%s); \n" , $ this ->dumpLiteralClass ($ class ), implode (', ' , $ arguments ));
726
727
}
727
728
728
729
/**
@@ -890,7 +891,7 @@ private function addNormalizedIds()
890
891
ksort ($ normalizedIds );
891
892
foreach ($ normalizedIds as $ id => $ normalizedId ) {
892
893
if ($ this ->container ->has ($ normalizedId )) {
893
- $ code .= ' ' .$ this ->export ($ id ).' => ' .$ this ->export ($ normalizedId ).", \n" ;
894
+ $ code .= ' ' .$ this ->doExport ($ id ).' => ' .$ this ->doExport ($ normalizedId ).", \n" ;
894
895
}
895
896
}
896
897
@@ -912,7 +913,7 @@ private function addMethodMap()
912
913
$ code = " \$this->methodMap = array( \n" ;
913
914
ksort ($ definitions );
914
915
foreach ($ definitions as $ id => $ definition ) {
915
- $ code .= ' ' .$ this ->export ($ id ).' => ' .$ this ->export ($ this ->generateMethodName ($ id )).", \n" ;
916
+ $ code .= ' ' .$ this ->doExport ($ id ).' => ' .$ this ->doExport ($ this ->generateMethodName ($ id )).", \n" ;
916
917
}
917
918
918
919
return $ code ." ); \n" ;
@@ -933,7 +934,7 @@ private function addPrivateServices()
933
934
ksort ($ definitions );
934
935
foreach ($ definitions as $ id => $ definition ) {
935
936
if (!$ definition ->isPublic ()) {
936
- $ code .= ' ' .$ this ->export ($ id )." => true, \n" ;
937
+ $ code .= ' ' .$ this ->doExport ($ id )." => true, \n" ;
937
938
}
938
939
}
939
940
@@ -966,7 +967,7 @@ private function addAliases()
966
967
while (isset ($ aliases [$ id ])) {
967
968
$ id = (string ) $ aliases [$ id ];
968
969
}
969
- $ code .= ' ' .$ this ->export ($ alias ).' => ' .$ this ->export ($ id ).", \n" ;
970
+ $ code .= ' ' .$ this ->doExport ($ alias ).' => ' .$ this ->doExport ($ id ).", \n" ;
970
971
}
971
972
972
973
return $ code ." ); \n" ;
@@ -1688,9 +1689,9 @@ private function exportTargetDirs()
1688
1689
private function export ($ value )
1689
1690
{
1690
1691
if (null !== $ this ->targetDirRegex && is_string ($ value ) && preg_match ($ this ->targetDirRegex , $ value , $ matches , PREG_OFFSET_CAPTURE )) {
1691
- $ prefix = $ matches [0 ][1 ] ? $ this ->doExport (substr ($ value , 0 , $ matches [0 ][1 ])).'. ' : '' ;
1692
+ $ prefix = $ matches [0 ][1 ] ? $ this ->doExport (substr ($ value , 0 , $ matches [0 ][1 ]), true ).'. ' : '' ;
1692
1693
$ suffix = $ matches [0 ][1 ] + strlen ($ matches [0 ][0 ]);
1693
- $ suffix = isset ($ value [$ suffix ]) ? '. ' .$ this ->doExport (substr ($ value , $ suffix )) : '' ;
1694
+ $ suffix = isset ($ value [$ suffix ]) ? '. ' .$ this ->doExport (substr ($ value , $ suffix ), true ) : '' ;
1694
1695
$ dirname = '__DIR__ ' ;
1695
1696
1696
1697
if (0 < $ offset = 1 + $ this ->targetDirMaxMatches - count ($ matches )) {
@@ -1704,10 +1705,10 @@ private function export($value)
1704
1705
return $ dirname ;
1705
1706
}
1706
1707
1707
- return $ this ->doExport ($ value );
1708
+ return $ this ->doExport ($ value, true );
1708
1709
}
1709
1710
1710
- private function doExport ($ value )
1711
+ private function doExport ($ value, $ resolveEnv = false )
1711
1712
{
1712
1713
if (is_string ($ value ) && false !== strpos ($ value , "\n" )) {
1713
1714
$ cleanParts = explode ("\n" , $ value );
@@ -1717,7 +1718,7 @@ private function doExport($value)
1717
1718
$ export = var_export ($ value , true );
1718
1719
}
1719
1720
1720
- if ("' " === $ export [0 ] && $ export !== $ resolvedExport = $ this ->container ->resolveEnvPlaceholders ($ export , "'. \$this->getEnv('%s').' " )) {
1721
+ if ($ resolveEnv && "' " === $ export [0 ] && $ export !== $ resolvedExport = $ this ->container ->resolveEnvPlaceholders ($ export , "'. \$this->getEnv('%s').' " )) {
1721
1722
$ export = $ resolvedExport ;
1722
1723
if ("' " === $ export [1 ]) {
1723
1724
$ export = substr ($ export , 3 );
0 commit comments