|
21 | 21 | */ |
22 | 22 | function get_example_inputs(): iterable |
23 | 23 | { |
24 | | - yield array(HttpMethod::GET, '/'); |
25 | | - yield array(HttpMethod::GET, '/user/foo'); |
26 | | - yield array(HttpMethod::GET, '/user/bar'); |
27 | | - yield array(HttpMethod::GET, '/contact-us'); |
28 | | - yield array(HttpMethod::GET, '/about-us'); |
29 | | - yield array(HttpMethod::POST, '/'); |
| 24 | + yield [HttpMethod::GET, '/']; |
| 25 | + yield [HttpMethod::GET, '/user/foo']; |
| 26 | + yield [HttpMethod::GET, '/user/bar']; |
| 27 | + yield [HttpMethod::GET, '/contact-us']; |
| 28 | + yield [HttpMethod::GET, '/about-us']; |
| 29 | + yield [HttpMethod::POST, '/']; |
| 30 | + |
| 31 | + // known 404 |
| 32 | + yield [HttpMethod::GET, '/user/31']; |
| 33 | + yield [HttpMethod::GET, '/user/HELLO']; |
| 34 | + yield [HttpMethod::GET, '/user/Hans8']; |
| 35 | + |
| 36 | + // known 403 |
| 37 | + yield [HttpMethod::PUT, '/user/azjezz']; |
30 | 38 | } |
31 | 39 |
|
32 | 40 | (static function (): void { |
@@ -60,20 +68,18 @@ function get_example_inputs(): iterable |
60 | 68 | [$responder, $parameters] = $router->match($method, $path); |
61 | 69 |
|
62 | 70 | $response = $responder($parameters); |
63 | | - |
64 | | - $method = Str\pad_right(Str\format('[%s]', $method), 8); |
65 | | - $request = Str\pad_right(Str\format('%s %s', $method, $path), 25); |
66 | | - |
67 | | - $output->write(Str\format("%s -> %s\n", $request, $response)); |
68 | 71 | } catch (HttpException\MethodNotAllowedException $e) { |
69 | | - $allowed_methods = $e->getAllowedMethods(); |
70 | | - |
71 | | - // Handle 403. |
| 72 | + $response = 'Error[403]: allowed methods "' . Str\join($e->getAllowedMethods(), '", "') . '"'; |
72 | 73 | } catch (HttpException\NotFoundException) { |
73 | | - // Handle 404. |
| 74 | + $response = 'Error[404]'; |
74 | 75 | } catch (HttpException\InternalServerErrorException) { |
75 | | - // Handle 500. |
| 76 | + $response = 'Error[500]'; |
76 | 77 | } |
| 78 | + |
| 79 | + $method = Str\pad_right(Str\format('[%s]', $method), 8); |
| 80 | + $request = Str\pad_right(Str\format('%s %s', $method, $path), 25); |
| 81 | + |
| 82 | + $output->write(Str\format("%s -> %s\n", $request, $response)); |
77 | 83 | } |
78 | 84 |
|
79 | 85 | exit(0); |
|
0 commit comments