[DI] Handle root namespace in service definitions
This commit is contained in:
parent
3c9958cbc3
commit
05170c84a2
@ -377,15 +377,9 @@ class PhpDumper extends Dumper
|
|||||||
*/
|
*/
|
||||||
private function addServiceInstance($id, Definition $definition)
|
private function addServiceInstance($id, Definition $definition)
|
||||||
{
|
{
|
||||||
$class = $definition->getClass();
|
$class = $this->dumpValue($definition->getClass());
|
||||||
|
|
||||||
if ('\\' === substr($class, 0, 1)) {
|
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)) {
|
||||||
$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));
|
throw new InvalidArgumentException(sprintf('"%s" is not a valid class name for the "%s" service.', $class, $id));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1440,11 +1434,13 @@ EOF;
|
|||||||
if (false !== strpos($class, '$')) {
|
if (false !== strpos($class, '$')) {
|
||||||
throw new RuntimeException('Cannot dump definitions which have a variable class name.');
|
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'));
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -339,4 +339,17 @@ class PhpDumperTest extends TestCase
|
|||||||
|
|
||||||
$this->addToAssertionCount(1);
|
$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'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user