1 | <?php |
||
41 | class RoutingFailedResponder |
||
42 | { |
||
43 | /** |
||
44 | * Factories indexed by rule name |
||
45 | * |
||
46 | * @var array |
||
47 | * |
||
48 | * @access protected |
||
49 | */ |
||
50 | protected $factories = []; |
||
51 | |||
52 | /** |
||
53 | * Default methods to respond with if no factory present |
||
54 | * |
||
55 | * @var array |
||
56 | * |
||
57 | * @access protected |
||
58 | */ |
||
59 | protected $defaults = [ |
||
60 | Allows::class => 'methodNotAllowed', |
||
61 | Accepts::class => 'notAcceptable', |
||
62 | Host::class => 'notFound', |
||
63 | Path::class => 'notFound', |
||
64 | ]; |
||
65 | |||
66 | /** |
||
67 | * Create a routing failed responder |
||
68 | * |
||
69 | * @param array $factories array of rule name to responder factories |
||
70 | * |
||
71 | * @access public |
||
72 | */ |
||
73 | 9 | public function __construct(array $factories = null) |
|
79 | |||
80 | /** |
||
81 | * Respond to route based on failed rule |
||
82 | * |
||
83 | * @param Request $request PSR7 Request |
||
84 | * @param Response $response PSR7 Response |
||
85 | * @param Route $route Failed rule |
||
86 | * |
||
87 | * @return Respone |
||
88 | * |
||
89 | * @access public |
||
90 | */ |
||
91 | 7 | public function __invoke( |
|
99 | |||
100 | /** |
||
101 | * Does a responder exist for name? |
||
102 | * |
||
103 | * @param string $name Name of rule for which to check |
||
104 | * |
||
105 | * @return bool |
||
106 | * |
||
107 | * @access public |
||
108 | */ |
||
109 | 9 | public function has($name) |
|
113 | |||
114 | /** |
||
115 | * Set a factory for a name |
||
116 | * |
||
117 | * @param string $name Name of rule for responder |
||
118 | * @param callable $factory Callable factory for responder |
||
119 | * |
||
120 | * @return $this |
||
121 | * |
||
122 | * @access public |
||
123 | */ |
||
124 | 8 | public function set($name, callable $factory) |
|
129 | |||
130 | /** |
||
131 | * Get |
||
132 | * |
||
133 | * @param string $name Name of rule for which to get responder |
||
134 | * |
||
135 | * @return callable |
||
136 | * @throws Exception if no factory available for rule |
||
137 | * |
||
138 | * @access public |
||
139 | */ |
||
140 | 3 | public function get($name) |
|
149 | |||
150 | /** |
||
151 | * Get responder for failed route |
||
152 | * |
||
153 | * @param Route $route Failed Route |
||
154 | * |
||
155 | * @return callable |
||
156 | * |
||
157 | * @access protected |
||
158 | */ |
||
159 | 7 | protected function getResponderForFailedRoute(Route $route) |
|
172 | |||
173 | /** |
||
174 | * Method not allowed |
||
175 | * |
||
176 | * Builds the Response when the failed route method was not allowed. |
||
177 | * |
||
178 | * @param Request $request PSR7 Request |
||
179 | * @param Response $response PSR7 Response |
||
180 | * @param Route $route Failed Route |
||
181 | * |
||
182 | * @return Response |
||
183 | * |
||
184 | * @access protected |
||
185 | */ |
||
186 | 1 | protected function methodNotAllowed( |
|
198 | |||
199 | /** |
||
200 | * Not Acceptable |
||
201 | * |
||
202 | * Builds the Response when the failed route could not accept the media type. |
||
203 | * |
||
204 | * @param Request $request PSR7 Request |
||
205 | * @param Response $response PSR7 Response |
||
206 | * @param Route $route Failed Route |
||
207 | * |
||
208 | * @return Response |
||
209 | * |
||
210 | * @access protected |
||
211 | */ |
||
212 | 1 | protected function notAcceptable( |
|
224 | |||
225 | /** |
||
226 | * Resource not found |
||
227 | * |
||
228 | * Builds the Response when the failed route host or path was not found. |
||
229 | * |
||
230 | * @param Request $request PSR7 Request |
||
231 | * @param Response $response PSR7 Response |
||
232 | * @param Route $route Failed Route |
||
233 | * |
||
234 | * @return Response |
||
235 | * |
||
236 | * @access protected |
||
237 | */ |
||
238 | 2 | protected function notFound(Request $request, Response $response, Route $route) |
|
245 | |||
246 | /** |
||
247 | * Other rule failed |
||
248 | * |
||
249 | * Builds the Response when routing failed for some other reason. |
||
250 | * |
||
251 | * @param Request $request PSR7 Request |
||
252 | * @param Response $response PSR7 Response |
||
253 | * @param Route $route Failed Route |
||
254 | * |
||
255 | * @return Response |
||
256 | * |
||
257 | * @access protected |
||
258 | */ |
||
259 | 1 | protected function other(Request $request, Response $response, Route $route) |
|
272 | } |
||
273 |