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

Commit89232ee

Browse files
committed
[HttpKernel] Do not attempt to register enum arguments in controller service locator
1 parent9d8638c commit89232ee

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

‎src/Symfony/Component/HttpKernel/DependencyInjection/RegisterControllerArgumentLocatorsPass.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ public function process(ContainerBuilder $container)
127127
$type =ltrim($target = (string) ProxyHelper::getTypeHint($r,$p),'\\');
128128
$invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE;
129129

130+
if (is_subclass_of($type, \UnitEnum::class,true)) {
131+
// do not attempt to register enum typed arguments
132+
continue;
133+
}
134+
130135
if (isset($arguments[$r->name][$p->name])) {
131136
$target =$arguments[$r->name][$p->name];
132137
if ('?' !==$target[0]) {

‎src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
useSymfony\Component\DependencyInjection\ServiceLocator;
2424
useSymfony\Component\DependencyInjection\TypedReference;
2525
useSymfony\Component\HttpKernel\DependencyInjection\RegisterControllerArgumentLocatorsPass;
26+
useSymfony\Component\HttpKernel\Tests\Fixtures\Suit;
2627

2728
class RegisterControllerArgumentLocatorsPassTestextends TestCase
2829
{
@@ -369,6 +370,25 @@ public function testNotTaggedControllerServiceReceivesLocatorArgument()
369370

370371
$this->assertInstanceOf(Reference::class,$locatorArgument);
371372
}
373+
374+
/**
375+
* @requires PHP 8.1
376+
*/
377+
publicfunctiontestEnumArgumentIsIgnored()
378+
{
379+
$container =newContainerBuilder();
380+
$resolver =$container->register('argument_resolver.service')->addArgument([]);
381+
382+
$container->register('foo', NonNullableEnumArgumentWithDefaultController::class)
383+
->addTag('controller.service_arguments')
384+
;
385+
386+
$pass =newRegisterControllerArgumentLocatorsPass();
387+
$pass->process($container);
388+
389+
$locator =$container->getDefinition((string)$resolver->getArgument(0))->getArgument(0);
390+
$this->assertEmpty(array_keys($locator),'enum typed argument is ignored');
391+
}
372392
}
373393

374394
class RegisterTestController
@@ -430,3 +450,10 @@ public function fooAction(string $someArg)
430450
{
431451
}
432452
}
453+
454+
class NonNullableEnumArgumentWithDefaultController
455+
{
456+
publicfunctionfooAction(Suit$suit = Suit::Spades)
457+
{
458+
}
459+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\HttpKernel\Tests\Fixtures;
13+
14+
enum Suit:string
15+
{
16+
case Hearts ='H';
17+
case Diamonds ='D';
18+
case Clubs ='C';
19+
case Spades ='S';
20+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp