8000 [DI] Handle root namespace in service definitions by ro0NL · Pull Request #23468 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DI] Handle root namespac 8000 e in service definitions #23468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
8000
Original file line number Diff line number Diff line change
Expand Up @@ -377,15 +377,9 @@ private function addServiceReturn($id, $definition)
*/
private function addServiceInstance($id, Definition $definition)
{
$class = $definition->getClass();

if ('\\' === substr($class, 0, 1)) {
$class = substr($class, 1);
}

$class = $this->dumpValue($class);
$class = $this->dumpValue($definition->getClass());

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)) {
if (0 === strpos($class, "'") && !preg_match('/^\'(?:\\\{2})?[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 @@ -1440,11 +1434,13 @@ 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)) {
if (0 !== strpos($class, "'") || !preg_match('/^\'(?:\\\{2})?[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 RuntimeException(sprintf('Cannot dump definition because of invalid class name (%s)', $class ?: 'n/a'));
}

return '\\'.substr(str_replace('\\\\', '\\', $class), 1, -1);
$class = substr(str_replace('\\\\', '\\', $class), 1, -1);

return 0 === strpos($class, '\\') ? $class : '\\'.$class;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,4 +339,17 @@ public function testCircularReferenceAllowanceForInlinedDefinitionsForLazyServic

$this->addToAssertionCount(1);
}

public function testDumpHandlesLiteralClassWithRootNamespace()
{
$container = new ContainerBuilder();
$container->register('foo', '\\stdClass');

$dumper = new PhpDumper($container);
eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Literal_Class_With_Root_Namespace')));

$container = new \Symfony_DI_PhpDumper_Test_Literal_Class_With_Root_Namespace();

$this->assertInstanceOf('stdClass', $container->get('foo'));
}
}
0