Skip to content

Commit 8a5a660

Browse files
Merge branch '2.7' into 2.8
* 2.7: [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 66d2e25 + cd15edf commit 8a5a660

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
@@ -377,15 +377,9 @@ private function addServiceReturn($id, $definition)
377377
*/
378378
private function addServiceInstance($id, Definition $definition)
379379
{
380-
$class = $definition->getClass();
381-
382-
if ('\\' === substr($class, 0, 1)) {
383-
$class = substr($class, 1);
384-
}
385-
386-
$class = $this->dumpValue($class);
380+
$class = $this->dumpValue($definition->getClass());
387381

388-
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)) {
382+
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)) {
389383
throw new InvalidArgumentException(sprintf('"%s" is not a valid class name for the "%s" service.', $class, $id));
390384
}
391385

@@ -1460,11 +1454,13 @@ private function dumpLiteralClass($class)
14601454
if (false !== strpos($class, '$')) {
14611455
throw new RuntimeException('Cannot dump definitions which have a variable class name.');
14621456
}
1463-
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)) {
1457+
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)) {
14641458
throw new RuntimeException(sprintf('Cannot dump definition because of invalid class name (%s)', $class ?: 'n/a'));
14651459
}
14661460

1467-
return '\\'.substr(str_replace('\\\\', '\\', $class), 1, -1);
1461+
$class = substr(str_replace('\\\\', '\\', $class), 1, -1);
1462+
1463+
return 0 === strpos($class, '\\') ? $class : '\\'.$class;
14681464
}
14691465

14701466
/**

Tests/Dumper/PhpDumperTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,4 +347,17 @@ public function testCircularReferenceAllowanceForInlinedDefinitionsForLazyServic
347347

348348
$this->addToAssertionCount(1);
349349
}
350+
351+
public function testDumpHandlesLiteralClassWithRootNamespace()
352+
{
353+
$container = new ContainerBuilder();
354+
$container->register('foo', '\\stdClass');
355+
356+
$dumper = new PhpDumper($container);
357+
eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Literal_Class_With_Root_Namespace')));
358+
359+
$container = new \Symfony_DI_PhpDumper_Test_Literal_Class_With_Root_Namespace();
360+
361+
$this->assertInstanceOf('stdClass', $container->get('foo'));
362+
}
350363
}

0 commit comments

Comments
 (0)