Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -759,6 +759,10 @@ private function addNewInstance($id, Definition $definition, $return, $instantia | |
if (null !== $definition->getFactory()) { | ||
$callable = $definition->getFactory(); | ||
if (is_array($callable)) { | ||
if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $callable[1])) { | ||
throw new RuntimeException(sprintf('Cannot dump definition because of invalid factory method (%s)', $callable[1] ?: 'n/a')); | ||
} | ||
|
||
if ($callable[0] instanceof Reference | ||
|| ($callable[0] instanceof Definition && $this->definitionVariables->contains($callable[0]))) { | ||
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) | |
} | ||
|
||
if (is_array($factory)) { | ||
if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $factory[1])) { | ||
throw new RuntimeException(sprintf('Cannot dump definition because of invalid factory method (%s)', $factory[1] ?: 'n/a')); | ||
} | ||
|
||
if (is_string($factory[0])) { | ||
return sprintf('\\%s::%s(%s)', $factory[0], $factory[1], implode(', ', $arguments)); | ||
return sprintf('%s::%s(%s)', $this->dumpLiteralClass($this->dumpValue($factory[0])), $factory[1], implode(', ', $arguments)); | ||
} | ||
|
||
if ($factory[0] instanceof Definition) { | ||
|
@@ -1342,12 +1350,8 @@ private function dumpValue($value, $interpolate = true) | |
if (null === $class) { | ||
throw new RuntimeException('Cannot dump definitions which have no class nor factory.'); | ||
} | ||
$class = $this->dumpValue($class); | ||
if (false !== strpos($class, '$')) { | ||
throw new RuntimeException('Cannot dump definitions which have a variable class name.'); | ||
} | ||
|
||
return sprintf('new \\%s(%s)', substr(str_replace('\\\\', '\\', $class), 1, -1), implode(', ', $arguments)); | ||
return sprintf('new %s(%s)', $this->dumpLiteralClass($this->dumpValue($class)), implode(', ', $arguments)); | ||
} elseif ($value instanceof Variable) { | ||
return '$'.$value; | ||
} elseif ($value instanceof Reference) { | ||
|
@@ -1388,9 +1392,18 @@ private function dumpValue($value, $interpolate = true) | |
* @param string $class | ||
* | ||
* @return string | ||
* | ||
* @throws RuntimeException | ||
*/ | ||
private function dumpLiteralClass($class) | ||
{ | ||
if (false !== strpos($class, '$')) { | ||
throw new RuntimeException('Cannot dump definitions which have a variable class name.'); | ||
} | ||
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)) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
stof
Member
|
||
throw new RuntimeException(sprintf('Cannot dump definition because of invalid class name (%s)', $class ?: 'n/a')); | ||
} | ||
|
||
return '\\'.substr(str_replace('\\\\', '\\', $class), 1, -1); | ||
} | ||
|
||
|
This is failing for valid class names. A simple project that uses JMS Serializer, for example, will complaining that 'Metadata\MetadataFactory' is an invalid class name.