|
7 | 7 | use Api\App\Middleware\AuthorizationMiddleware; |
8 | 8 | use Api\App\Middleware\ContentNegotiationMiddleware; |
9 | 9 | use Api\App\Middleware\DeprecationMiddleware; |
10 | | -use Api\App\Middleware\ResponseMiddleware; |
11 | | -use Dot\ErrorHandler\ErrorHandlerInterface; |
12 | 10 | use Dot\ResponseHeader\Middleware\ResponseHeaderMiddleware; |
13 | 11 | use Mezzio\Application; |
14 | 12 | use Mezzio\Cors\Middleware\CorsMiddleware; |
|
24 | 22 | use Mezzio\Router\Middleware\RouteMiddleware; |
25 | 23 |
|
26 | 24 | return function (Application $app): void { |
27 | | - // The error handler should be the first (most outer) middleware to catch |
28 | | - // all Exceptions. |
29 | | - $app->pipe(ErrorHandlerInterface::class); |
| 25 | + // This middleware must be the outest layer because - on error occurrence - it will: |
| 26 | + // - call \Dot\ErrorHandler\ErrorHandlerInterface::class |
| 27 | + // - return ProblemDetails response |
30 | 28 | $app->pipe(ProblemDetailsMiddleware::class); |
31 | 29 |
|
32 | 30 | $app->pipe(BodyParamsMiddleware::class); |
|
38 | 36 | // - pre-conditions |
39 | 37 | // - modifications to outgoing responses |
40 | 38 | // |
41 | | - // Piped Middleware may be either callables or service names. Middleware may |
42 | | - // also be passed as an array; each item in the array must resolve to |
43 | | - // middleware eventually (i.e., callable or service name). |
| 39 | + // Piped Middleware may be either callables or service names. |
| 40 | + // Middleware may also be passed as an array; each item in the array must resolve to middleware eventually |
| 41 | + // (i.e., callable or service name). |
44 | 42 | // |
45 | | - // Middleware can be attached to specific paths, allowing you to mix and match |
46 | | - // applications under a common domain. The handlers in each middleware |
47 | | - // attached this way will see a URI with the matched path segment removed. |
| 43 | + // Middleware can be attached to specific paths, allowing you to mix and match applications under a common domain. |
| 44 | + // The handlers in each middleware attached this way will see a URI with the matched path segment removed. |
48 | 45 | // |
49 | | - // i.e., path of "/api/member/profile" only passes "/member/profile" to $apiMiddleware |
| 46 | + // For example, the path of "/api/member/profile" only passes "/member/profile" to $apiMiddleware |
50 | 47 | // - $app->pipe('/api', $apiMiddleware); |
51 | 48 | // - $app->pipe('/docs', $apiDocMiddleware); |
52 | 49 | // - $app->pipe('/files', $filesMiddleware); |
|
83 | 80 | // - route-based validation |
84 | 81 | // - etc. |
85 | 82 |
|
86 | | - $app->pipe(ResponseMiddleware::class); |
87 | | - |
88 | 83 | // Register the dispatch middleware in the middleware pipeline |
89 | 84 | $app->pipe(DispatchMiddleware::class); |
90 | 85 | // At this point, if no Response is returned by any middleware, the |
|
0 commit comments