@@ -780,6 +780,10 @@ private function addNewInstance($id, Definition $definition, $return, $instantia
780
780
if (null !== $ definition ->getFactory ()) {
781
781
$ callable = $ definition ->getFactory ();
782
782
if (is_array ($ callable )) {
783
+ if (!preg_match ('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/ ' , $ callable [1 ])) {
784
+ throw new RuntimeException (sprintf ('Cannot dump definition because of invalid factory method (%s) ' , $ callable [1 ] ?: 'n/a ' ));
785
+ }
786
+
783
787
if ($ callable [0 ] instanceof Reference
784
788
|| ($ callable [0 ] instanceof Definition && $ this ->definitionVariables ->contains ($ callable [0 ]))) {
785
789
return sprintf (" $ return {$ instantiation }%s->%s(%s); \n" , $ this ->dumpValue ($ callable [0 ]), $ callable [1 ], $ arguments ? implode (', ' , $ arguments ) : '' );
@@ -1331,8 +1335,12 @@ private function dumpValue($value, $interpolate = true)
1331
1335
}
1332
1336
1333
1337
if (is_array ($ factory )) {
1338
+ if (!preg_match ('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/ ' , $ factory [1 ])) {
1339
+ throw new RuntimeException (sprintf ('Cannot dump definition because of invalid factory method (%s) ' , $ factory [1 ] ?: 'n/a ' ));
1340
+ }
1341
+
1334
1342
if (is_string ($ factory [0 ])) {
1335
- return sprintf ('\\ %s::%s(%s) ' , $ factory [0 ], $ factory [1 ], implode (', ' , $ arguments ));
1343
+ return sprintf ('%s::%s(%s) ' , $ this -> dumpLiteralClass ( $ this -> dumpValue ( $ factory [0 ])) , $ factory [1 ], implode (', ' , $ arguments ));
1336
1344
}
1337
1345
1338
1346
if ($ factory [0 ] instanceof Definition) {
@@ -1363,12 +1371,8 @@ private function dumpValue($value, $interpolate = true)
1363
1371
if (null === $ class ) {
1364
1372
throw new RuntimeException ('Cannot dump definitions which have no class nor factory. ' );
1365
1373
}
1366
- $ class = $ this ->dumpValue ($ class );
1367
- if (false !== strpos ($ class , '$ ' )) {
1368
- throw new RuntimeException ('Cannot dump definitions which have a variable class name. ' );
1369
- }
1370
1374
1371
- return sprintf ('new \\ %s(%s) ' , substr ( str_replace ( '\\\\' , '\\' , $ class ), 1 , - 1 ), implode (', ' , $ arguments ));
1375
+ return sprintf ('new %s(%s) ' , $ this -> dumpLiteralClass ( $ this -> dumpValue ( $ class )), implode (', ' , $ arguments ));
1372
1376
} elseif ($ value instanceof Variable) {
1373
1377
return '$ ' .$ value ;
1374
1378
} elseif ($ value instanceof Reference) {
@@ -1409,9 +1413,18 @@ private function dumpValue($value, $interpolate = true)
1409
1413
* @param string $class
1410
1414
*
1411
1415
* @return string
1416
+ *
1417
+ * @throws RuntimeException
1412
1418
*/
1413
1419
private function dumpLiteralClass ($ class )
1414
1420
{
1421
+ if (false !== strpos ($ class , '$ ' )) {
1422
+ throw new RuntimeException ('Cannot dump definitions which have a variable class name. ' );
1423
+ }
1424
+ 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 )) {
1425
+ throw new RuntimeException (sprintf ('Cannot dump definition because of invalid class name (%s) ' , $ class ?: 'n/a ' ));
1426
+ }
1427
+
1415
1428
return '\\' .substr (str_replace ('\\\\' , '\\' , $ class ), 1 , -1 );
1416
1429
}
1417
1430
0 commit comments