Created
December 8, 2017 20:15
-
-
Save ppeiris/190d3c8ebc7e3172c47538d83a707256 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Zend\Expressive\Helper\ServerUrlMiddleware; | |
use Zend\Expressive\Helper\UrlHelperMiddleware; | |
use Zend\Expressive\Middleware\ImplicitHeadMiddleware; | |
use Zend\Expressive\Middleware\ImplicitOptionsMiddleware; | |
use Zend\Expressive\Middleware\NotFoundHandler; | |
use Zend\Stratigility\Middleware\ErrorHandler; | |
use Logging\Middleware\LoggingMiddleware; | |
use ValidateHttpHeaders\Middleware\ValidateHttpHeadersMiddleware; | |
/** | |
* Setup middleware pipeline: | |
*/ | |
// The error handler should be the first (most outer) middleware to catch | |
// all Exceptions. | |
$app->pipe(ErrorHandler::class); | |
$app->pipe(ServerUrlMiddleware::class); | |
// Pipe more middleware here that you want to execute on every request: | |
// - bootstrapping | |
// - pre-conditions | |
// - modifications to outgoing responses | |
// | |
// Piped Middleware may be either callables or service names. Middleware may | |
// also be passed as an array; each item in the array must resolve to | |
// middleware eventually (i.e., callable or service name). | |
// | |
// Middleware can be attached to specific paths, allowing you to mix and match | |
// applications under a common domain. The handlers in each middleware | |
// attached this way will see a URI with the MATCHED PATH SEGMENT REMOVED!!! | |
// | |
// - $app->pipe('/api', $apiMiddleware); | |
// - $app->pipe('/docs', $apiDocMiddleware); | |
// - $app->pipe('/files', $filesMiddleware); | |
// Register the routing middleware in the middleware pipeline | |
$app->pipeRoutingMiddleware(); | |
$app->pipe(ImplicitHeadMiddleware::class); | |
$app->pipe(ImplicitOptionsMiddleware::class); | |
$app->pipe(UrlHelperMiddleware::class); | |
// Add more middleware here that needs to introspect the routing results; this | |
// might include: | |
// | |
$app->pipe(LoggingMiddleware::class); | |
$app->pipe(ValidateHttpHeadersMiddleware::class); | |
// - route-based authentication | |
// - route-based validation | |
// - etc. | |
// Register the dispatch middleware in the middleware pipeline | |
$app->pipeDispatchMiddleware(); | |
// At this point, if no Response is return by any middleware, the | |
// NotFoundHandler kicks in; alternately, you can provide other fallback | |
// middleware to execute. | |
$app->pipe(NotFoundHandler::class); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment