Skip to content

Commit 65cd9e7

Browse files
Merge branch '3.3' into 3.4
* 3.3: [DI] Handle root namespace in service definitions Use rawurlencode() to transform the Cookie into a string [Process] Fix parsing args on Windows [HttpKernel][VarDumper] Truncate profiler data & optim perf [Security] Fix authentication.failure event not dispatched on AccountStatusException
2 parents fbfe4df + ba5bfda commit 65cd9e7

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-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

@@ -1566,11 +1560,13 @@ private function dumpLiteralClass($class)
15661560
if (false !== strpos($class, '$')) {
15671561
return sprintf('${($_ = %s) && false ?: "_"}', $class);
15681562
}
1569-
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)) {
1563+
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)) {
15701564
throw new RuntimeException(sprintf('Cannot dump definition because of invalid class name (%s)', $class ?: 'n/a'));
15711565
}
15721566

1573-
return '\\'.substr(str_replace('\\\\', '\\', $class), 1, -1);
1567+
$class = substr(str_replace('\\\\', '\\', $class), 1, -1);
1568+
1569+
return 0 === strpos($class, '\\') ? $class : '\\'.$class;
15741570
}
15751571

15761572
/**

Tests/Dumper/PhpDumperTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,4 +598,18 @@ public function testArrayParameters()
598598

599599
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_array_params.php', str_replace('\\\\Dumper', '/Dumper', $dumper->dump(array('file' => self::$fixturesPath.'/php/services_array_params.php'))));
600600
}
601+
602+
public function testDumpHandlesLiteralClassWithRootNamespace()
603+
{
604+
$container = new ContainerBuilder();
605+
$container->register('foo', '\\stdClass');
606+
$container->compile();
607+
608+
$dumper = new PhpDumper($container);
609+
eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Literal_Class_With_Root_Namespace')));
610+
611+
$container = new \Symfony_DI_PhpDumper_Test_Literal_Class_With_Root_Namespace();
612+
613+
$this->assertInstanceOf('stdClass', $container->get('foo'));
614+
}
601615
}

0 commit comments

Comments
 (0)