@@ -759,6 +759,10 @@ private function addNewInstance($id, Definition $definition, $return, $instantia
759759 if (null !== $ definition ->getFactory ()) {
760760 $ callable = $ definition ->getFactory ();
761761 if (is_array ($ callable )) {
762+ if (!preg_match ('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/ ' , $ callable [1 ])) {
763+ throw new RuntimeException (sprintf ('Cannot dump definition because of invalid factory method (%s) ' , $ callable [1 ] ?: 'n/a ' ));
764+ }
765+
762766 if ($ callable [0 ] instanceof Reference
763767 || ($ callable [0 ] instanceof Definition && $ this ->definitionVariables ->contains ($ callable [0 ]))) {
764768 return sprintf (" $ return {$ instantiation }%s->%s(%s); \n" , $ this ->dumpValue ($ callable [0 ]), $ callable [1 ], $ arguments ? implode (', ' , $ arguments ) : '' );
@@ -1310,8 +1314,12 @@ private function dumpValue($value, $interpolate = true)
13101314 }
13111315
13121316 if (is_array ($ factory )) {
1317+ if (!preg_match ('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/ ' , $ factory [1 ])) {
1318+ throw new RuntimeException (sprintf ('Cannot dump definition because of invalid factory method (%s) ' , $ factory [1 ] ?: 'n/a ' ));
1319+ }
1320+
13131321 if (is_string ($ factory [0 ])) {
1314- return sprintf ('\\ %s::%s(%s) ' , $ factory [0 ], $ factory [1 ], implode (', ' , $ arguments ));
1322+ return sprintf ('%s::%s(%s) ' , $ this -> dumpLiteralClass ( $ this -> dumpValue ( $ factory [0 ])) , $ factory [1 ], implode (', ' , $ arguments ));
13151323 }
13161324
13171325 if ($ factory [0 ] instanceof Definition) {
@@ -1342,12 +1350,8 @@ private function dumpValue($value, $interpolate = true)
13421350 if (null === $ class ) {
13431351 throw new RuntimeException ('Cannot dump definitions which have no class nor factory. ' );
13441352 }
1345- $ class = $ this ->dumpValue ($ class );
1346- if (false !== strpos ($ class , '$ ' )) {
1347- throw new RuntimeException ('Cannot dump definitions which have a variable class name. ' );
1348- }
13491353
1350- return sprintf ('new \\ %s(%s) ' , substr ( str_replace ( '\\\\' , '\\' , $ class ), 1 , - 1 ), implode (', ' , $ arguments ));
1354+ return sprintf ('new %s(%s) ' , $ this -> dumpLiteralClass ( $ this -> dumpValue ( $ class )), implode (', ' , $ arguments ));
13511355 } elseif ($ value instanceof Variable) {
13521356 return '$ ' .$ value ;
13531357 } elseif ($ value instanceof Reference) {
@@ -1388,9 +1392,18 @@ private function dumpValue($value, $interpolate = true)
13881392 * @param string $class
13891393 *
13901394 * @return string
1395+ *
1396+ * @throws RuntimeException
13911397 */
13921398 private function dumpLiteralClass ($ class )
13931399 {
1400+ if (false !== strpos ($ class , '$ ' )) {
1401+ throw new RuntimeException ('Cannot dump definitions which have a variable class name. ' );
1402+ }
1403+ if (0 !== strpos ($ class , "' " ) || !preg_match ('/^ \'[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*( \\\{2}[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)* \'$/ ' , $ class )) {
1404+ throw new RuntimeException (sprintf ('Cannot dump definition because of invalid class name (%s) ' , $ class ?: 'n/a ' ));
1405+ }
1406+
13941407 return '\\' .substr (str_replace ('\\\\' , '\\' , $ class ), 1 , -1 );
13951408 }
13961409
0 commit comments