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

Commit7f836be

Browse files
committed
deprecate non string requirement names
1 parent02daeb2 commit7f836be

File tree

7 files changed

+68
-1
lines changed

7 files changed

+68
-1
lines changed

‎src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,16 @@ protected function addRoute(RouteCollection $collection, $annot, $globals, \Refl
142142
}
143143
$name =$globals['name'].$name;
144144

145+
$requirements =$annot->getRequirements();
146+
147+
foreach ($requirementsas$placeholder =>$requirement) {
148+
if (is_int($placeholder)) {
149+
@trigger_error(sprintf('A placeholder name must be a string (%d given). Did you forget to specify the placeholder key for the requirement "%s" of route "%s" in "%s::%s()"?',$placeholder,$requirement,$name,$class->getName(),$method->getName()),E_USER_DEPRECATED);
150+
}
151+
}
152+
145153
$defaults =array_replace($globals['defaults'],$annot->getDefaults());
146-
$requirements =array_replace($globals['requirements'],$annot->getRequirements());
154+
$requirements =array_replace($globals['requirements'],$requirements);
147155
$options =array_replace($globals['options'],$annot->getOptions());
148156
$schemes =array_merge($globals['schemes'],$annot->getSchemes());
149157
$methods =array_merge($globals['methods'],$annot->getMethods());

‎src/Symfony/Component/Routing/Loader/YamlFileLoader.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ protected function parseRoute(RouteCollection $collection, $name, array $config,
116116
$methods =isset($config['methods']) ?$config['methods'] :array();
117117
$condition =isset($config['condition']) ?$config['condition'] :null;
118118

119+
foreach ($requirementsas$placeholder =>$requirement) {
120+
if (is_int($placeholder)) {
121+
@trigger_error(sprintf('A placeholder name must be a string (%d given). Did you forget to specify the placeholder key for the requirement "%s" of route "%s" in "%s"?',$placeholder,$requirement,$name,$path),E_USER_DEPRECATED);
122+
}
123+
}
124+
119125
if (isset($config['controller'])) {
120126
$defaults['_controller'] =$config['controller'];
121127
}

‎src/Symfony/Component/Routing/Route.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,10 @@ public function setRequirements(array $requirements)
453453
publicfunctionaddRequirements(array$requirements)
454454
{
455455
foreach ($requirementsas$key =>$regex) {
456+
if (is_int($key)) {
457+
@trigger_error(sprintf('Support for numeric requirements ("%d" given) is deprecated since Symfony 4.2 and will trigger an error in 5.0.'),E_USER_DEPRECATED);
458+
}
459+
456460
$this->requirements[$key] =$this->sanitizeRequirement($key,$regex);
457461
}
458462
$this->compiled =null;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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\Routing\Tests\Fixtures\AnnotationFixtures;
13+
14+
useSymfony\Component\Routing\Annotation\Route;
15+
16+
class RequirementsWithoutPlaceholderNameController
17+
{
18+
/**
19+
* @Route("/{foo}", name="foo", requirements={"foo", "\d+"})
20+
*/
21+
publicfunctionfoo()
22+
{
23+
}
24+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
foo:
2+
path:'/{foo}'
3+
requirements:
4+
-'\d+'

‎src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
useSymfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\NothingButNameController;
3434
useSymfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\PrefixedActionLocalizedRouteController;
3535
useSymfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\PrefixedActionPathController;
36+
useSymfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\RequirementsWithoutPlaceholderNameController;
3637
useSymfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\RouteWithPrefixController;
3738

3839
class AnnotationClassLoaderTestextends AbstractAnnotationLoaderTest
@@ -87,6 +88,16 @@ public function testSimplePathRoute()
8788
$this->assertEquals('/path',$routes->get('action')->getPath());
8889
}
8990

91+
/**
92+
* @group legacy
93+
* @expectedDeprecation A placeholder name must be a string (0 given). Did you forget to specify the placeholder key for the requirement "foo" of route "foo" in "Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\RequirementsWithoutPlaceholderNameController::foo()"?
94+
* @expectedDeprecation A placeholder name must be a string (1 given). Did you forget to specify the placeholder key for the requirement "\d+" of route "foo" in "Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\RequirementsWithoutPlaceholderNameController::foo()"?
95+
*/
96+
publicfunctiontestMisconfiguredPlaceholderRequirements()
97+
{
98+
$this->loader->load(RequirementsWithoutPlaceholderNameController::class);
99+
}
100+
90101
publicfunctiontestInvokableControllerLoader()
91102
{
92103
$routes =$this->loader->load(InvokableController::class);

‎src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,14 @@ public function testImportRouteWithNoTrailingSlash()
304304
$this->assertEquals('/slash/',$routeCollection->get('a_app_homepage')->getPath());
305305
$this->assertEquals('/no-slash',$routeCollection->get('b_app_homepage')->getPath());
306306
}
307+
308+
/**
309+
* @group legacy
310+
* @expectedDeprecation A placeholder name must be a string (0 given). Did you forget to specify the placeholder key for the requirement "\d+" of route "foo" in "%srequirements_without_placeholder_name.yml"?
311+
*/
312+
publicfunctiontestRequirementsWithoutPlaceholderName()
313+
{
314+
$loader =newYamlFileLoader(newFileLocator(array(__DIR__.'/../Fixtures')));
315+
$loader->load('requirements_without_placeholder_name.yml');
316+
}
307317
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp