Ecodev /
my-ichtus
| 1 | <?php |
||||
| 2 | |||||
| 3 | declare(strict_types=1); |
||||
| 4 | |||||
| 5 | use Application\Middleware\AuthenticationMiddleware; |
||||
| 6 | use Laminas\Stratigility\Middleware\ErrorHandler; |
||||
| 7 | use Mezzio\Application; |
||||
| 8 | use Mezzio\Handler\NotFoundHandler; |
||||
| 9 | use Mezzio\Helper\ServerUrlMiddleware; |
||||
| 10 | use Mezzio\Helper\UrlHelperMiddleware; |
||||
| 11 | use Mezzio\MiddlewareFactory; |
||||
| 12 | use Mezzio\Router\Middleware\DispatchMiddleware; |
||||
| 13 | use Mezzio\Router\Middleware\ImplicitHeadMiddleware; |
||||
| 14 | use Mezzio\Router\Middleware\ImplicitOptionsMiddleware; |
||||
| 15 | use Mezzio\Router\Middleware\MethodNotAllowedMiddleware; |
||||
| 16 | use Mezzio\Router\Middleware\RouteMiddleware; |
||||
| 17 | use Mezzio\Session\SessionMiddleware; |
||||
| 18 | use Psr\Container\ContainerInterface; |
||||
| 19 | use Psr\Http\Message\ResponseInterface; |
||||
| 20 | use Psr\Http\Message\ServerRequestInterface; |
||||
| 21 | |||||
| 22 | // Setup middleware pipeline: |
||||
| 23 | return function (Application $app, MiddlewareFactory $factory, ContainerInterface $container): void { |
||||
| 24 | /** @var ErrorHandler $errorHandler */ |
||||
| 25 | $errorHandler = $container->get(ErrorHandler::class); |
||||
| 26 | $errorHandler->attachListener(function (Throwable $throwable, ServerRequestInterface $request, ResponseInterface $response): void { |
||||
|
0 ignored issues
–
show
The parameter
$response is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 27 | _log()->error($throwable->getMessage() . "\n" . $throwable->getTraceAsString()); |
||||
| 28 | }); |
||||
| 29 | |||||
| 30 | // The error handler should be the first (most outer) middleware to catch |
||||
| 31 | // all Exceptions. |
||||
| 32 | $app->pipe($errorHandler); |
||||
| 33 | $app->pipe(ServerUrlMiddleware::class); |
||||
| 34 | |||||
| 35 | // Pipe more middleware here that you want to execute on every request: |
||||
| 36 | // - bootstrapping |
||||
| 37 | // - pre-conditions |
||||
| 38 | // - modifications to outgoing responses |
||||
| 39 | // |
||||
| 40 | // Piped Middleware may be either callables or service names. Middleware may |
||||
| 41 | // also be passed as an array; each item in the array must resolve to |
||||
| 42 | // middleware eventually (i.e., callable or service name). |
||||
| 43 | // |
||||
| 44 | // Middleware can be attached to specific paths, allowing you to mix and match |
||||
| 45 | // applications under a common domain. The handlers in each middleware |
||||
| 46 | // attached this way will see a URI with the matched path segment removed. |
||||
| 47 | // |
||||
| 48 | // i.e., path of "/api/member/profile" only passes "/member/profile" to $apiMiddleware |
||||
| 49 | // - $app->pipe('/api', $apiMiddleware); |
||||
| 50 | // - $app->pipe('/docs', $apiDocMiddleware); |
||||
| 51 | // - $app->pipe('/files', $filesMiddleware); |
||||
| 52 | |||||
| 53 | // Register the routing middleware in the middleware pipeline. |
||||
| 54 | // This middleware registers the Mezzio\Router\RouteResult request attribute. |
||||
| 55 | $app->pipe(RouteMiddleware::class); |
||||
| 56 | |||||
| 57 | // The following handle routing failures for common conditions: |
||||
| 58 | // - HEAD request but no routes answer that method |
||||
| 59 | // - OPTIONS request but no routes answer that method |
||||
| 60 | // - method not allowed |
||||
| 61 | // Order here matters; the MethodNotAllowedMiddleware should be placed |
||||
| 62 | // after the Implicit*Middleware. |
||||
| 63 | $app->pipe(ImplicitHeadMiddleware::class); |
||||
| 64 | $app->pipe(ImplicitOptionsMiddleware::class); |
||||
| 65 | $app->pipe(MethodNotAllowedMiddleware::class); |
||||
| 66 | |||||
| 67 | // Seed the UrlHelper with the routing results: |
||||
| 68 | $app->pipe(UrlHelperMiddleware::class); |
||||
| 69 | |||||
| 70 | $app->pipe(SessionMiddleware::class); |
||||
| 71 | $app->pipe(AuthenticationMiddleware::class); |
||||
| 72 | |||||
| 73 | // Add more middleware here that needs to introspect the routing results; this |
||||
| 74 | // might include: |
||||
| 75 | // |
||||
| 76 | // - route-based authentication |
||||
| 77 | // - route-based validation |
||||
| 78 | // - etc. |
||||
| 79 | |||||
| 80 | // Register the dispatch middleware in the middleware pipeline |
||||
| 81 | $app->pipe(DispatchMiddleware::class); |
||||
| 82 | |||||
| 83 | // At this point, if no Response is returned by any middleware, the |
||||
| 84 | // NotFoundHandler kicks in; alternately, you can provide other fallback |
||||
| 85 | // middleware to execute. |
||||
| 86 | $app->pipe(NotFoundHandler::class); |
||||
| 87 | }; |
||||
| 88 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.