Skip to content

Commit 4c540dc

Browse files
Merge branch '2.8' into 3.2
* 2.8: [DI] Handle root namespace in service definitions Use rawurlencode() to transform the Cookie into a string [Security] Fix authentication.failure event not dispatched on AccountStatusException
2 parents 236644f + 8a5a660 commit 4c540dc

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

Dumper/PhpDumper.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -389,15 +389,9 @@ private function addServiceReturn($id, $definition)
389389
*/
390390
private function addServiceInstance($id, Definition $definition)
391391
{
392-
$class = $definition->getClass();
393-
394-
if ('\\' === substr($class, 0, 1)) {
395-
$class = substr($class, 1);
396-
}
397-
398-
$class = $this->dumpValue($class);
392+
$class = $this->dumpValue($definition->getClass());
399393

400-
if (0 === strpos($class, "'") && false === 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)) {
394+
if (0 === strpos($class, "'") && false === 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)) {
401395
throw new InvalidArgumentException(sprintf('"%s" is not a valid class name for the "%s" service.', $class, $id));
402396
}
403397

@@ -1453,11 +1447,13 @@ private function dumpLiteralClass($class)
14531447
if (false !== strpos($class, '$')) {
14541448
return sprintf('${($_ = %s) && false ?: "_"}', $class);
14551449
}
1456-
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)) {
1450+
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)) {
14571451
throw new RuntimeException(sprintf('Cannot dump definition because of invalid class name (%s)', $class ?: 'n/a'));
14581452
}
14591453

1460-
return '\\'.substr(str_replace('\\\\', '\\', $class), 1, -1);
1454+
$class = substr(str_replace('\\\\', '\\', $class), 1, -1);
1455+
1456+
return 0 === strpos($class, '\\') ? $class : '\\'.$class;
14611457
}
14621458

14631459
/**

Tests/Dumper/PhpDumperTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,4 +424,17 @@ public function testPrivateWithIgnoreOnInvalidReference()
424424
$container = new \Symfony_DI_PhpDumper_Test_Private_With_Ignore_On_Invalid_Reference();
425425
$this->assertInstanceOf('BazClass', $container->get('bar')->getBaz());
426426
}
427+
428+
public function testDumpHandlesLiteralClassWithRootNamespace()
429+
{
430+
$container = new ContainerBuilder();
431+
$container->register('foo', '\\stdClass');
432+
433+
$dumper = new PhpDumper($container);
434+
eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Literal_Class_With_Root_Namespace')));
435+
436+
$container = new \Symfony_DI_PhpDumper_Test_Literal_Class_With_Root_Namespace();
437+
438+
$this->assertInstanceOf('stdClass', $container->get('foo'));
439+
}
427440
}

0 commit comments

Comments
 (0)