8000 bug #15380 do not dump leading backslashes in class names (xabbuh) · symfony/dependency-injection@3f85e84 · GitHub
[go: up one dir, main page]

Skip to content
10000

Commit 3f85e84

Browse files
committed
bug #15380 do not dump leading backslashes in class names (xabbuh)
This PR was merged into the 2.3 branch. Discussion ---------- do not dump leading backslashes in class names | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #15001 | License | MIT | Doc PR | Commits ------- ad6cb10 do not dump leading backslashes in class names
2 parents 2d2f7fd + 8a8126d commit 3f85e84

File tree

5 files changed

+28
-8
lines changed

5 files changed

+28
-8
lines changed

Dumper/GraphvizDumper.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,13 @@ private function findNodes()
165165
$container = $this->cloneContainer();
166166

167167
foreach ($container->getDefinitions() as $id => $definition) {
168-
$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')));
168+
$class = $definition->getClass();
169+
170+
if ('\\' === substr($class, 0, 1)) {
171+
$class = substr($class, 1);
172+
}
173+
174+
$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')));
169175

170176
$container->setDefinition($id, new Definition('stdClass'));
171177
}

Dumper/PhpDumper.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,13 @@ private function addServiceReturn($id, $definition)
358358
*/
359359
private function addServiceInstance($id, $definition)
360360
{
361-
$class = $this->dumpValue($definition->getClass());
361+
$class = $definition->getClass();
362+
363+
if ('\\' === substr($class, 0, 1)) {
364+
$class = substr($class, 1);
365+
}
366+
367+
$class = $this->dumpValue($class);
362368

363369
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)) {
364370
throw new InvalidArgumentException(sprintf('"%s" is not a valid class name for the "%s" service.', $class, $id));
@@ -539,7 +545,7 @@ private function addService($id, $def 10000 inition)
539545
if ($definition->isSynthetic()) {
540546
$return[] = '@throws RuntimeException always since this service is expected to be injected dynamically';
541547
} elseif ($class = $definition->getClass()) {
542-
$return[] = sprintf('@return %s A %s instance.', 0 === strpos($class, '%') ? 'object' : '\\'.$class, $class);
548+
$return[] = sprintf('@return %s A %s instance.', 0 === strpos($class, '%') ? 'object' : '\\'.ltrim($class, '\\'), ltrim($class, '\\'));
543549
} elseif ($definition->getFactoryClass()) {
544550
$return[] = sprintf('@return object An instance returned by %s::%s().', $definition->getFactoryClass(), $definition->getFactoryMethod());
545551
} elseif ($definition->getFactoryService()) {

Dumper/XmlDumper.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,12 @@ private function addService($definition, $id, \DOMElement $parent)
113113
if (null !== $id) {
114114
$service->setAttribute('id', $id);
115115
}
116-
if ($definition->getClass()) {
117-
$service->setAttribute('class', $definition->getClass());
116+
if ($class = $definition->getClass()) {
117+
if ('\\' === substr($class, 0, 1)) {
118+
$class = substr($class, 1);
119+
}
120+
121+
$service->setAttribute('class', $class);
118122
}
119123
if ($definition->getFactoryMethod()) {
120124
$service->setAttribute('factory-method', $definition->getFactoryMethod());

Dumper/YamlDumper.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,12 @@ public function dump(array $options = array())
6363
private function addService($id, $definition)
6464
{
6565
$code = " $id:\n";
66-
if ($definition->getClass()) {
67-
$code .= sprintf(" class: %s\n", $definition->getClass());
66+
if ($class = $definition->getClass()) {
67+
if ('\\' === substr($class, 0, 1)) {
68+
$class = substr($class, 1);
69+
}
70+
71+
$code .= sprintf(" class: %s\n", $class);
6872
}
6973

7074
if (!$definition->isPublic()) {

Tests/Fixtures/containers/container9.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
$container = new ContainerBuilder();
1111
$container->
12-
register('foo', 'FooClass')->
12+
register('foo', '\FooClass')->
1313
addTag('foo', array('foo' => 'foo'))->
1414
addTag('foo', array('bar' => 'bar', 'baz' => 'baz'))->
1515
setFactoryClass('FooClass')->

0 commit comments

Comments
 (0)
0