Skip to content

Commit 6cf404c

Browse files
bug #40801 [Routing] Fix supporting string "methods" and "schemes" on the Route annotation (fancyweb)
This PR was merged into the 5.3-dev branch. Discussion ---------- [Routing] Fix supporting string "methods" and "schemes" on the Route annotation | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | symfony/symfony#40796 | License | MIT | Doc PR | - Commits ------- b5f61c31e5 [Routing] Fix supporting string "methods" and "schemes" on the Route annotation
2 parents 4518784 + e598bf1 commit 6cf404c

File tree

4 files changed

+68
-4
lines changed

4 files changed

+68
-4
lines changed

Annotation/Route.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class Route
4141
* @param array|string $data data array managed by the Doctrine Annotations library or the path
4242
* @param array|string|null $path
4343
* @param string[] $requirements
44-
* @param string[] $methods
45-
* @param string[] $schemes
44+
* @param string[]|string $methods
45+
* @param string[]|string $schemes
4646
*
4747
* @throws \BadMethodCallException
4848
*/
@@ -54,8 +54,8 @@ public function __construct(
5454
array $options = [],
5555
array $defaults = [],
5656
string $host = null,
57-
array $methods = [],
58-
array $schemes = [],
57+
$methods = [],
58+
$schemes = [],
5959
string $condition = null,
6060
int $priority = null,
6161
string $locale = null,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures;
4+
5+
use Symfony\Component\Routing\Annotation\Route;
6+
7+
final class MethodsAndSchemes
8+
{
9+
/**
10+
* @Route("/array-many", name="array_many", methods={"GET", "POST"}, schemes={"http", "https"})
11+
*/
12+
public function arrayMany(): void
13+
{
14+
}
15+
16+
/**
17+
* @Route("/array-one", name="array_one", methods={"GET"}, schemes={"http"})
18+
*/
19+
public function arrayOne(): void
20+
{
21+
}
22+
23+
/**
24+
* @Route("/string", name="string", methods="POST", schemes="https")
25+
*/
26+
public function string(): void
27+
{
28+
}
29+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Symfony\Component\Routing\Tests\Fixtures\AttributeFixtures;
4+
5+
use Symfony\Component\Routing\Annotation\Route;
6+
7+
final class MethodsAndSchemes
8+
{
9+
#[Route(path: '/array-many', name: 'array_many', methods: ['GET', 'POST'], schemes: ['http', 'https'])]
10+
public function arrayMany(): void
11+
{
12+
}
13+
14+
#[Route(path: '/array-one', name: 'array_one', methods: ['GET'], schemes: ['http'])]
15+
public function arrayOne(): void
16+
{
17+
}
18+
19+
#[Route(path: '/string', name: 'string', methods: 'POST', schemes: 'https')]
20+
public function string(): void
21+
{
22+
}
23+
}

Tests/Loader/AnnotationClassLoaderTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,5 +258,17 @@ public function testWhenEnv()
258258
$this->assertSame('/path', $routes->get('action')->getPath());
259259
}
260260

261+
public function testMethodsAndSchemes()
262+
{
263+
$routes = $this->loader->load($this->getNamespace().'\MethodsAndSchemes');
264+
265+
$this->assertSame(['GET', 'POST'], $routes->get('array_many')->getMethods());
266+
$this->assertSame(['http', 'https'], $routes->get('array_many')->getSchemes());
267+
$this->assertSame(['GET'], $routes->get('array_one')->getMethods());
268+
$this->assertSame(['http'], $routes->get('array_one')->getSchemes());
269+
$this->assertSame(['POST'], $routes->get('string')->getMethods());
270+
$this->assertSame(['https'], $routes->get('string')->getSchemes());
271+
}
272+
261273
abstract protected function getNamespace(): string;
262274
}

0 commit comments

Comments
 (0)