Skip to content

Commit ba5bfda

Browse files
Merge branch '3.2' into 3.3
* 3.2: [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 2862829 + 4c540dc commit ba5bfda

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
@@ -397,15 +397,9 @@ private function addServiceReturn($id, $isSimpleInstance)
397397
*/
398398
private function addServiceInstance($id, Definition $definition, $isSimpleInstance)
399399
{
400-
$class = $definition->getClass();
401-
402-
if ('\\' === substr($class, 0, 1)) {
403-
$class = substr($class, 1);
404-
}
405-
406-
$class = $this->dumpValue($class);
400+
$class = $this->dumpValue($definition->getClass());
407401

408-
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)) {
402+
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)) {
409403
throw new InvalidArgumentException(sprintf('"%s" is not a valid class name for the "%s" service.', $class, $id));
410404
}
411405

@@ -1564,11 +1558,13 @@ private function dumpLiteralClass($class)
15641558
if (false !== strpos($class, '$')) {
15651559
return sprintf('${($_ = %s) && false ?: "_"}', $class);
15661560
}
1567-
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)) {
1561+
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)) {
15681562
throw new RuntimeException(sprintf('Cannot dump definition because of invalid class name (%s)', $class ?: 'n/a'));
15691563
}
15701564

1571-
return '\\'.substr(str_replace('\\\\', '\\', $class), 1, -1);
1565+
$class = substr(str_replace('\\\\', '\\', $class), 1, -1);
1566+
1567+
return 0 === strpos($class, '\\') ? $class : '\\'.$class;
15721568
}
15731569

15741570
/**

Tests/Dumper/PhpDumperTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,4 +584,17 @@ public function testPrivateWithIgnoreOnInvalidReference()
584584
$container = new \Symfony_DI_PhpDumper_Test_Private_With_Ignore_On_Invalid_Reference();
585585
$this->assertInstanceOf('BazClass', $container->get('bar')->getBaz());
586586
}
587+
588+
public function testDumpHandlesLiteralClassWithRootNamespace()
589+
{
590+
$container = new ContainerBuilder();
591+
$container->register('foo', '\\stdClass');
592+
593+
$dumper = new PhpDumper($container);
594+
eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Literal_Class_With_Root_Namespace')));
595+
596+
$container = new \Symfony_DI_PhpDumper_Test_Literal_Class_With_Root_Namespace();
597+
598+
$this->assertInstanceOf('stdClass', $container->get('foo'));
599+
}
587600
}

0 commit comments

Comments
 (0)