Issues (15)

src/Route/Route.php (4 issues)

1
<?php
2
3
namespace ByJG\RestServer\Route;
4
5
use Closure;
6
7
class Route
8
{
9
    protected $method;
10
    protected $path;
11
    protected $outputProcessor = null;
12
    protected $class = null;
13
14
    /**
15
     * Route constructor.
16
     *
17
     * @param array|string $method
18
     * @param string $path
19
     * @param string $outputProcessor
20
     * @param Closure|string $class
21
     * @param string|null $methodName
22
     */
23 20
    public function __construct($method, $path)
24
    {
25 20
        $this->setMethod($method);
26 20
        $this->setPath($path);
27
    }
28
29 4
    public function withOutputProcessor($outputProcessor)
30
    {
31 4
        $this->setOutputProcessor($outputProcessor);
32 4
        return $this;
33
    }
34
35 16
    public function withClosure(\Closure $closure)
36
    {
37 16
        $this->setClass($closure);
38 16
        return $this;
39
    }
40
41 20
    public function withClass($class, $methodName)
42
    {
43 20
        $this->setClass([$class, $methodName]);
44 20
        return $this;
45
    }
46
47
    /**
48
     * @return mixed
49
     */
50 12
    public function getMethod()
51
    {
52 12
        return $this->method;
53
    }
54
55
    /**
56
     * @param mixed $method
57
     * @return Route
58
     */
59 20
    protected function setMethod($method)
60
    {
61 20
        $this->method = $method;
62
    }
63
64
    /**
65
     * @return mixed
66
     */
67 12
    public function getPath()
68
    {
69 12
        return $this->path;
70
    }
71
72
    /**
73
     * @param mixed $path
74
     * @return Route
75
     */
76 20
    protected function setPath($path)
77
    {
78 20
        $this->path = $path;
79
    }
80
81
    /**
82
     * @return string
83
     */
84 12
    public function getOutputProcessor()
85
    {
86 12
        return $this->outputProcessor;
87
    }
88
89
    /**
90
     * @param mixed $outputProcessor
91
     * @return Route
92
     */
93 4
    protected function setOutputProcessor($outputProcessor)
94
    {
95 4
        $this->outputProcessor = $outputProcessor;
96
    }
97
98
    /**
99
     * @return mixed
100
     */
101 12
    public function getClass()
102
    {
103 12
        return $this->class;
104
    }
105
106
    /**
107
     * @param mixed $class
108
     * @return Route
109
     */
110 20
    protected function setClass($class)
111
    {
112 20
        $this->class = $class;
113
    }
114
115
116
    /**
117
     * Route Factory for "GET" method
118
     *
119
     * @param string $path
120
     * @param string $outputProcessor
121
     * @param string $class
122
     * @param null $methodName
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $methodName is correct as it would always require null to be passed?
Loading history...
123
     * @return Route
124
     */
125 16
    public static function get($path)
126
    {
127 16
        return new Route('GET', $path);
128
    }
129
130
    /**
131
     * Route Factory for "POST" method
132
     *
133
     * @param string $path
134
     * @param string $outputProcessor
135
     * @param string $class
136
     * @param null $methodName
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $methodName is correct as it would always require null to be passed?
Loading history...
137
     * @return Route
138
     */
139
    public static function post($path)
140
    {
141
        return new Route('POST', $path);
142
    }
143
144
    /**
145
     * Route Factory for "PUT" method
146
     *
147
     * @param string $path
148
     * @param string $outputProcessor
149
     * @param string $class
150
     * @param null $methodName
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $methodName is correct as it would always require null to be passed?
Loading history...
151
     * @return Route
152
     */
153
    public static function put($path)
154
    {
155
        return new Route('PUT', $path);
156
    }
157
158
    /**
159
     * Route Factory for "DELETE" method
160
     *
161
     * @param string $path
162
     * @param string $outputProcessor
163
     * @param string $class
164
     * @param null $methodName
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $methodName is correct as it would always require null to be passed?
Loading history...
165
     * @return Route
166
     */
167
    public static function delete($path)
168
    {
169
        return new Route('DELETE', $path);
170
    }
171
}
172