|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Flight Routing. |
|
5
|
|
|
* |
|
6
|
|
|
* PHP version 8.0 and above required |
|
7
|
|
|
* |
|
8
|
|
|
* @author Divine Niiquaye Ibok <[email protected]> |
|
9
|
|
|
* @copyright 2019 Divine Niiquaye Ibok (https://divinenii.com/) |
|
10
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause License |
|
11
|
|
|
* |
|
12
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
13
|
|
|
* file that was distributed with this source code. |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace Flight\Routing\Annotation; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Annotation class for @Route(). |
|
20
|
|
|
* |
|
21
|
|
|
* @Annotation |
|
22
|
|
|
* @NamedArgumentConstructor |
|
23
|
|
|
* |
|
24
|
|
|
* On PHP 7.2+ Attributes are supported except you want to use Doctrine annotations: |
|
25
|
|
|
* ```php |
|
26
|
|
|
* #[Route('/blog/{_locale}', name: 'blog', defaults: ['_locale' => 'en'])] |
|
27
|
|
|
* class Blog |
|
28
|
|
|
* { |
|
29
|
|
|
* #[Route('/', name: '_index', methods: ['GET', 'HEAD'] schemes: 'https')] |
|
30
|
|
|
* public function index() |
|
31
|
|
|
* { |
|
32
|
|
|
* } |
|
33
|
|
|
* #[Route('/{id}', name: '_post', methods: 'POST' where: ["id" => '\d+'])] |
|
34
|
|
|
* public function show() |
|
35
|
|
|
* { |
|
36
|
|
|
* } |
|
37
|
|
|
* } |
|
38
|
|
|
* ``` |
|
39
|
|
|
* |
|
40
|
|
|
* @Target({"CLASS", "METHOD", "FUNCTION"}) |
|
41
|
|
|
*/ |
|
42
|
|
|
#[\Spiral\Attributes\NamedArgumentConstructor] |
|
43
|
|
|
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::TARGET_FUNCTION)] |
|
44
|
|
|
final class Route |
|
45
|
|
|
{ |
|
46
|
|
|
/** @var array<int,string> */ |
|
47
|
|
|
public array $methods, $hosts, $schemes; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param array<int,string>|string $methods |
|
51
|
|
|
* @param array<int,string>|string $schemes |
|
52
|
|
|
* @param array<int,string>|string $hosts |
|
53
|
|
|
* @param array<string,mixed> $where |
|
54
|
|
|
* @param array<string,mixed> $defaults |
|
55
|
|
|
* @param array<string,mixed> $arguments |
|
56
|
|
|
*/ |
|
57
|
5 |
|
public function __construct( |
|
58
|
|
|
public ?string $path = null, |
|
59
|
|
|
public ?string $name = null, |
|
60
|
|
|
string|array $methods = [], |
|
61
|
|
|
string|array $schemes = [], |
|
62
|
|
|
string|array $hosts = [], |
|
63
|
|
|
public array $where = [], |
|
64
|
|
|
public array $defaults = [], |
|
65
|
|
|
public array $arguments = [], |
|
66
|
|
|
public ?string $resource = null |
|
67
|
|
|
) { |
|
68
|
5 |
|
$this->methods = (array) $methods; |
|
69
|
5 |
|
$this->schemes = (array) $schemes; |
|
70
|
5 |
|
$this->hosts = (array) $hosts; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|