Skip to content

Commit fa04d14

Browse files
Merge branch '4.4' into 5.3
* 4.4: [DomCrawler] Fix HTML5 parser charset option cs fix [HttpKernel] Do not attempt to register enum arguments in controller service locator [Cache] Don't lock when doing nested computations [Messenger] fix Redis support on 32b arch [HttpFoundation] Fix notice when HTTP_PHP_AUTH_USER passed without pass
2 parents 504310b + 1f0c4e1 commit fa04d14

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

DependencyInjection/RegisterControllerArgumentLocatorsPass.php

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

143+
if (is_subclass_of($type, \UnitEnum::class)) {
144+
// do not attempt to register enum typed arguments
145+
continue;
146+
}
147+
143148
if (isset($arguments[$r->name][$p->name])) {
144149
$target = $arguments[$r->name][$p->name];
145150
if ('?' !== $target[0]) {

Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Symfony\Component\DependencyInjection\ServiceLocator;
2525
use Symfony\Component\DependencyInjection\TypedReference;
2626
use Symfony\Component\HttpKernel\DependencyInjection\RegisterControllerArgumentLocatorsPass;
27+
use Symfony\Component\HttpKernel\Tests\Fixtures\Suit;
2728

2829
class RegisterControllerArgumentLocatorsPassTest extends TestCase
2930
{
@@ -400,6 +401,25 @@ public function testAlias()
400401
$this->assertEqualsCanonicalizing([RegisterTestController::class.'::fooAction', 'foo::fooAction'], array_keys($locator));
401402
}
402403

404+
/**
405+
* @requires PHP 8.1
406+
*/
407+
public function testEnumArgumentIsIgnored()
408+
{
409+
$container = new ContainerBuilder();
410+
$resolver = $container->register('argument_resolver.service')->addArgument([]);
411+
412+
$container->register('foo', NonNullableEnumArgumentWithDefaultController::class)
413+
->addTag('controller.service_arguments')
414+
;
415+
416+
$pass = new RegisterControllerArgumentLocatorsPass();
417+
$pass->process($container);
418+
419+
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
420+
$this->assertEmpty(array_keys($locator), 'enum typed argument is ignored');
421+
}
422+
403423
/**
404424
* @requires PHP 8
405425
*/
@@ -482,6 +502,13 @@ public function fooAction(string $someArg)
482502
}
483503
}
484504

505+
class NonNullableEnumArgumentWithDefaultController
506+
{
507+
public function fooAction(Suit $suit = Suit::Spades)
508+
{
509+
}
510+
}
511+
485512
class WithTarget
486513
{
487514
public function fooAction(

Tests/Fixtures/Suit.php

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+
namespace Symfony\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)