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