Passed
Pull Request — master (#439)
by Kirill
06:35
created

Route::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 7
dl 0
loc 16
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Router\Annotation;
13
14
use Attribute;
15
use Doctrine\Common\Annotations\Annotation;
16
use Spiral\Attributes\NamedArgumentConstructor;
17
use Spiral\Attributes\NamedArgumentConstructorAttribute;
18
19
/**
20
 * @Annotation()
21
 * @Annotation\Target({"METHOD"})
22
 * @NamedArgumentConstructor()
23
 */
24
#[Attribute(Attribute::TARGET_METHOD)]
25
#[NamedArgumentConstructor()]
26
final class Route implements NamedArgumentConstructorAttribute
27
{
28
    public const DEFAULT_GROUP = 'default';
29
30
    /**
31
     * @Annotation\Attribute(name="route", type="string", required=true)
32
     * @var string
33
     */
34
    public $route;
35
36
    /**
37
     * @Attribute(name="name", type="string")
38
     * @var string
39
     */
40
    public $name = null;
41
42
    /**
43
     * @Annotation\Attribute(name="verbs", type="mixed", required=true)
44
     * @var mixed
45
     */
46
    public $methods;
47
48
    /**
49
     * Default match options.
50
     *
51
     * @Annotation\Attribute(name="defaults", type="array")
52
     * @var array
53
     */
54
    public $defaults;
55
56
    /**
57
     * Route group (set of middlewere), groups can be configured using MiddlewareRegistry.
58
     *
59
     * @Annotation\Attribute(name="group", type="string")
60
     * @var null|string
61
     */
62
    public $group;
63
64
    /**
65
     * Route specific middleware set, if any.
66
     *
67
     * @Annotation\Attribute(name="middleware", type="array")
68
     * @var array
69
     */
70
    public $middleware;
71
72
    /**
73
     * @Annotation\Attribute(name="priority", type="int")
74
     * @var int
75
     */
76
    public $priority;
77
78
    /**
79
     * @param array|string $methods
80
     */
81
    public function __construct(
82
        string $route,
83
        string $name,
84
        $methods = \Spiral\Router\Route::VERBS,
85
        array $defaults = [],
86
        string $group = self::DEFAULT_GROUP,
87
        array $middleware = [],
88
        int $priority = 0
89
    ) {
90
        $this->route = $route;
91
        $this->name = $name;
92
        $this->methods = $methods;
93
        $this->defaults = $defaults;
94
        $this->group = $group;
95
        $this->middleware = $middleware;
96
        $this->priority = $priority;
97
    }
98
}
99