do not dump leading backslashes in class names

This commit is contained in:
Christian Flothmann 2015-07-28 09:17:47 +02:00
parent e60795691c
commit ad6cb10e63
5 changed files with 28 additions and 8 deletions

View File

@ -165,7 +165,13 @@ class GraphvizDumper extends Dumper
$container = $this->cloneContainer();
foreach ($container->getDefinitions() as $id => $definition) {
$nodes[$id] = array('class' => str_replace('\\', '\\\\', $this->container->getParameterBag()->resolveValue($definition->getClass())), 'attributes' => array_merge($this->options['node.definition'], array('style' => ContainerInterface::SCOPE_PROTOTYPE !== $definition->getScope() ? 'filled' : 'dotted')));
$class = $definition->getClass();
if ('\\' === substr($class, 0, 1)) {
$class = substr($class, 1);
}
$nodes[$id] = array('class' => str_replace('\\', '\\\\', $this->container->getParameterBag()->resolveValue($class)), 'attributes' => array_merge($this->options['node.definition'], array('style' => ContainerInterface::SCOPE_PROTOTYPE !== $definition->getScope() ? 'filled' : 'dotted')));
$container->setDefinition($id, new Definition('stdClass'));
}

View File

@ -358,7 +358,13 @@ class PhpDumper extends Dumper
*/
private function addServiceInstance($id, $definition)
{
$class = $this->dumpValue($definition->getClass());
$class = $definition->getClass();
if ('\\' === substr($class, 0, 1)) {
$class = substr($class, 1);
}
$class = $this->dumpValue($class);
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)) {
throw new InvalidArgumentException(sprintf('"%s" is not a valid class name for the "%s" service.', $class, $id));
@ -539,7 +545,7 @@ class PhpDumper extends Dumper
if ($definition->isSynthetic()) {
$return[] = '@throws RuntimeException always since this service is expected to be injected dynamically';
} elseif ($class = $definition->getClass()) {
$return[] = sprintf('@return %s A %s instance.', 0 === strpos($class, '%') ? 'object' : '\\'.$class, $class);
$return[] = sprintf('@return %s A %s instance.', 0 === strpos($class, '%') ? 'object' : '\\'.ltrim($class, '\\'), ltrim($class, '\\'));
} elseif ($definition->getFactoryClass()) {
$return[] = sprintf('@return object An instance returned by %s::%s().', $definition->getFactoryClass(), $definition->getFactoryMethod());
} elseif ($definition->getFactoryService()) {

View File

@ -113,8 +113,12 @@ class XmlDumper extends Dumper
if (null !== $id) {
$service->setAttribute('id', $id);
}
if ($definition->getClass()) {
$service->setAttribute('class', $definition->getClass());
if ($class = $definition->getClass()) {
if ('\\' === substr($class, 0, 1)) {
$class = substr($class, 1);
}
$service->setAttribute('class', $class);
}
if ($definition->getFactoryMethod()) {
$service->setAttribute('factory-method', $definition->getFactoryMethod());

View File

@ -63,8 +63,12 @@ class YamlDumper extends Dumper
private function addService($id, $definition)
{
$code = " $id:\n";
if ($definition->getClass()) {
$code .= sprintf(" class: %s\n", $definition->getClass());
if ($class = $definition->getClass()) {
if ('\\' === substr($class, 0, 1)) {
$class = substr($class, 1);
}
$code .= sprintf(" class: %s\n", $class);
}
if (!$definition->isPublic()) {

View File

@ -9,7 +9,7 @@ use Symfony\Component\DependencyInjection\Parameter;
$container = new ContainerBuilder();
$container->
register('foo', 'FooClass')->
register('foo', '\FooClass')->
addTag('foo', array('foo' => 'foo'))->
addTag('foo', array('bar' => 'bar', 'baz' => 'baz'))->
setFactoryClass('FooClass')->