Skip to content

Commit 4a56ce4

Browse files
Merge branch '7.3' into 7.4
* 7.3: [DependencyInjection] Fix lazy proxy creation for interfaces aliased to final classes [HttpKernel] Fix StreamedResponse with chunks support in HttpKernelBrowser [HttpFoundation] Fix AcceptHeader overwrites items with different parameters [JsonStreamer] Rebuild cache on class update [Routing] Fix default value not taken if usigng name:entity.attribute [Mime] Remove unused variable in Email::prepareParts [DependencyInjection] Fix merging explicit tags and #[AsTaggeditem]
2 parents 7255c02 + 42ed1ae commit 4a56ce4

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

Loader/AttributeClassLoader.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,11 @@ protected function addRoute(RouteCollection $collection, object $attr, array $gl
219219
continue;
220220
}
221221
foreach ($paths as $locale => $path) {
222-
if (preg_match(\sprintf('/\{%s(?:<.*?>)?\}/', preg_quote($param->name)), $path)) {
222+
if (preg_match(\sprintf('/\{(?|([^\}:<]++):%s(?:\.[^\}<]++)?|(%1$s))(?:<.*?>)?\}/', preg_quote($param->name)), $path, $matches)) {
223223
if (\is_scalar($defaultValue = $param->getDefaultValue()) || null === $defaultValue) {
224-
$defaults[$param->name] = $defaultValue;
224+
$defaults[$matches[1]] = $defaultValue;
225225
} elseif ($defaultValue instanceof \BackedEnum) {
226-
$defaults[$param->name] = $defaultValue->value;
226+
$defaults[$matches[1]] = $defaultValue->value;
227227
}
228228
break;
229229
}

Tests/Fixtures/AttributeFixtures/DefaultValueController.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Symfony\Component\Routing\Tests\Fixtures\AttributeFixtures;
44

55
use Symfony\Component\Routing\Attribute\Route;
6+
use Symfony\Component\Routing\Tests\Fixtures\AttributedClasses\BarClass;
67
use Symfony\Component\Routing\Tests\Fixtures\Enum\TestIntBackedEnum;
78
use Symfony\Component\Routing\Tests\Fixtures\Enum\TestStringBackedEnum;
89

@@ -30,4 +31,14 @@ public function stringEnumAction(TestStringBackedEnum $default = TestStringBacke
3031
public function intEnumAction(TestIntBackedEnum $default = TestIntBackedEnum::Diamonds)
3132
{
3233
}
34+
35+
#[Route(path: '/defaultMappedParam/{libelle:bar}', name: 'defaultMappedParam_default')]
36+
public function defaultMappedParam(?BarClass $bar = null)
37+
{
38+
}
39+
40+
#[Route(path: '/defaultAdvancedMappedParam/{barLibelle:bar.libelle}', name: 'defaultAdvancedMappedParam_default')]
41+
public function defaultAdvancedMappedParam(?BarClass $bar = null)
42+
{
43+
}
3344
}

Tests/Loader/AttributeClassLoaderTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,16 @@ public function testLocalizedPathRoutesWithExplicitPathPropety()
170170
public function testDefaultValuesForMethods()
171171
{
172172
$routes = $this->loader->load(DefaultValueController::class);
173-
$this->assertCount(5, $routes);
173+
$this->assertCount(7, $routes);
174174
$this->assertEquals('/{default}/path', $routes->get('action')->getPath());
175175
$this->assertEquals('value', $routes->get('action')->getDefault('default'));
176176
$this->assertEquals('Symfony', $routes->get('hello_with_default')->getDefault('name'));
177177
$this->assertEquals('World', $routes->get('hello_without_default')->getDefault('name'));
178178
$this->assertEquals('diamonds', $routes->get('string_enum_action')->getDefault('default'));
179+
$this->assertArrayHasKey('libelle', $routes->get('defaultMappedParam_default')->getDefaults());
180+
$this->assertNull($routes->get('defaultMappedParam_default')->getDefault('libelle'));
181+
$this->assertArrayHasKey('barLibelle', $routes->get('defaultAdvancedMappedParam_default')->getDefaults());
182+
$this->assertNull($routes->get('defaultAdvancedMappedParam_default')->getDefault('barLibelle'));
179183
$this->assertEquals(20, $routes->get('int_enum_action')->getDefault('default'));
180184
}
181185

0 commit comments

Comments
 (0)