Skip to content

Commit 155f0a5

Browse files
Merge branch '7.4' into 8.0
* 7.4: [Translation][Lokalise] fix "Project too big for sync export" [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 0f6c879 + 4a56ce4 commit 155f0a5

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
@@ -202,11 +202,11 @@ protected function addRoute(RouteCollection $collection, object $attr, array $gl
202202
continue;
203203
}
204204
foreach ($paths as $locale => $path) {
205-
if (preg_match(\sprintf('/\{%s(?:<.*?>)?\}/', preg_quote($param->name)), $path)) {
205+
if (preg_match(\sprintf('/\{(?|([^\}:<]++):%s(?:\.[^\}<]++)?|(%1$s))(?:<.*?>)?\}/', preg_quote($param->name)), $path, $matches)) {
206206
if (\is_scalar($defaultValue = $param->getDefaultValue()) || null === $defaultValue) {
207-
$defaults[$param->name] = $defaultValue;
207+
$defaults[$matches[1]] = $defaultValue;
208208
} elseif ($defaultValue instanceof \BackedEnum) {
209-
$defaults[$param->name] = $defaultValue->value;
209+
$defaults[$matches[1]] = $defaultValue->value;
210210
}
211211
break;
212212
}

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)