Skip to content

Commit

Permalink
do not dump leading backslashes in class names
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Jul 28, 2015
1 parent e607956 commit ad6cb10
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
Expand Up @@ -165,7 +165,13 @@ private function findNodes()
$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'));
}
Expand Down
10 changes: 8 additions & 2 deletions src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
Expand Up @@ -358,7 +358,13 @@ private function addServiceReturn($id, $definition)
*/
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));
Expand Down Expand Up @@ -539,7 +545,7 @@ private function addService($id, $definition)
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()) {
Expand Down
Expand Up @@ -113,8 +113,12 @@ private function addService($definition, $id, \DOMElement $parent)
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());
Expand Down
Expand Up @@ -63,8 +63,12 @@ public function dump(array $options = array())
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()) {
Expand Down
Expand Up @@ -9,7 +9,7 @@

$container = new ContainerBuilder();
$container->
register('foo', 'FooClass')->
register('foo', '\FooClass')->
addTag('foo', array('foo' => 'foo'))->
addTag('foo', array('bar' => 'bar', 'baz' => 'baz'))->
setFactoryClass('FooClass')->
Expand Down

0 comments on commit ad6cb10

Please sign in to comment.