Completed
Push — master ( a0167e...162b39 )
by Eric
09:38
created

Route::end()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Jarvis\Skill\Routing;
6
7
use Jarvis\Jarvis;
8
9
/**
10
 * @author Eric Chau <[email protected]>
11
 */
12
class Route
13
{
14
    private $name;
15
    private $method = 'get';
16
    private $pattern = '/';
17
    private $handler;
18
    private $scope = Jarvis::DEFAULT_SCOPE;
19
    private $router;
20
21
    public function __construct(string $name = null, Router $router)
22
    {
23
        $this->name = $name;
24
        $this->router = $router;
25
    }
26
27
    public function name()
28
    {
29
        return $this->name;
30
    }
31
32
    public function method() : string
33
    {
34
        return $this->method;
35
    }
36
37
    public function setMethod(string $method) : Route
38
    {
39
        $this->method = strtolower($method);
40
41
        return $this;
42
    }
43
44
    public function pattern() : string
45
    {
46
        return $this->pattern;
47
    }
48
49
    public function setPattern(string $pattern) : Route
50
    {
51
        $this->pattern = $pattern;
52
53
        return $this;
54
    }
55
56
    public function handler()
57
    {
58
        return $this->handler;
59
    }
60
61
    public function setHandler($handler) : Route
62
    {
63
        $this->handler = $handler;
64
65
        return $this;
66
    }
67
68
    public function scope() : string
69
    {
70
        return $this->scope;
71
    }
72
73
    public function setScope(string $scope) : Route
74
    {
75
        $this->scope = $scope;
76
77
        return $this;
78
    }
79
80
    public function end()
81
    {
82
        return $this->router->addRoute($this);
83
    }
84
}
85