Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit05170c8

Browse files
ro0NLnicolas-grekas
authored andcommitted
[DI] Handle root namespace in service definitions
1 parent3c9958c commit05170c8

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

‎src/Symfony/Component/DependencyInjection/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
privatefunctionaddServiceInstance($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
thrownewInvalidArgumentException(sprintf('"%s" is not a valid class name for the "%s" service.',$class,$id));
390384
}
391385

@@ -1440,11 +1434,13 @@ private function dumpLiteralClass($class)
14401434
if (false !==strpos($class,'$')) {
14411435
thrownewRuntimeException('Cannot dump definitions which have a variable class name.');
14421436
}
1443-
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)) {
1437+
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)) {
14441438
thrownewRuntimeException(sprintf('Cannot dump definition because of invalid class name (%s)',$class ?:'n/a'));
14451439
}
14461440

1447-
return'\\'.substr(str_replace('\\\\','\\',$class),1, -1);
1441+
$class =substr(str_replace('\\\\','\\',$class),1, -1);
1442+
1443+
return0 ===strpos($class,'\\') ?$class :'\\'.$class;
14481444
}
14491445

14501446
/**

‎src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php‎

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

340340
$this->addToAssertionCount(1);
341341
}
342+
343+
publicfunctiontestDumpHandlesLiteralClassWithRootNamespace()
344+
{
345+
$container =newContainerBuilder();
346+
$container->register('foo','\\stdClass');
347+
348+
$dumper =newPhpDumper($container);
349+
eval('?>'.$dumper->dump(array('class' =>'Symfony_DI_PhpDumper_Test_Literal_Class_With_Root_Namespace')));
350+
351+
$container =new \Symfony_DI_PhpDumper_Test_Literal_Class_With_Root_Namespace();
352+
353+
$this->assertInstanceOf('stdClass',$container->get('foo'));
354+
}
342355
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp