summaryrefslogtreecommitdiff
path: root/index.php
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@webtrees.net>2019-03-13 13:40:42 +0000
committerGreg Roach <fisharebest@webtrees.net>2019-03-13 13:40:42 +0000
commitb0c01d0c28a4ee291803e9f36bcb20e3f916c3da (patch)
treed83447ba34e9516691b9e65dec5ca50667dfd5c4 /index.php
parentfcc78dae1f7ecef76abacadc98657d5780a713f0 (diff)
downloadwebtrees-b0c01d0c28a4ee291803e9f36bcb20e3f916c3da.tar.gz
webtrees-b0c01d0c28a4ee291803e9f36bcb20e3f916c3da.tar.bz2
webtrees-b0c01d0c28a4ee291803e9f36bcb20e3f916c3da.zip
Comments
Diffstat (limited to 'index.php')
-rw-r--r--index.php28
1 files changed, 25 insertions, 3 deletions
diff --git a/index.php b/index.php
index 94be0270d1..8c2925725f 100644
--- a/index.php
+++ b/index.php
@@ -96,6 +96,23 @@ try {
// Update the database schema, if necessary.
app(MigrationService::class)->updateSchema('\Fisharebest\Webtrees\Schema', 'WT_SCHEMA_VERSION', Webtrees::SCHEMA_VERSION);
+ // Middleware allows code to intercept the request before it reaches the controller, and to
+ // intercept the response afterwards.
+ //
+ // +----------------------------------+
+ // | Middleware1 |
+ // | +------------------------------+ |
+ // | | Middleware2 | |
+ // | | +--------------------------+ | |
+ // | | | | | |
+ // Request ----|-|-|-> Controller::action() --|-|-|---> Response
+ // | | | | | |
+ // | | +--------------------------+ | |
+ // | | | |
+ // | +------------------------------+ |
+ // | |
+ // +----------------------------------+
+
$middleware_stack = [
CheckForMaintenanceMode::class,
UseFilesystem::class,
@@ -124,15 +141,20 @@ try {
$middleware_stack[] = $middleware;
}
- // We build the "onion" from the inside outwards, and some middlewares are dependant on others.
+ // We build the pipeline from controller outwards, so process the last middleware first.
+
$middleware_stack = array_reverse($middleware_stack);
- // Create the middleware *after* loading the modules, to give modules the opportunity to replace middleware.
+ // Construct the core middleware *after* loading the modules, to reduce dependencies.
+
$middleware_stack = array_map(function ($middleware): MiddlewareInterface {
return $middleware instanceof MiddlewareInterface ? $middleware : app($middleware);
}, $middleware_stack);
- // Apply the middleware using the "onion" pattern.
+ // Create a pipleline, which applies the middleware as a nested function call.
+ //
+ // Response = Middleware1(Middleware2(Controller::action(Request)))
+
$pipeline = array_reduce($middleware_stack, function (Closure $next, MiddlewareInterface $middleware): Closure {
// Create a closure to apply the middleware.
return function (Request $request) use ($middleware, $next): Response {