Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
06374dc8
Commit
06374dc8
authored
Nov 13, 2015
by
Nicolas Dermine
Committed by
Fabien Potencier
Apr 29, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
s/middlewares/middleware
parent
c5fabd12
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
17 deletions
+17
-17
doc/middlewares.rst
doc/middlewares.rst
+17
-17
No files found.
doc/middlewares.rst
View file @
06374dc8
Middleware
s
Middleware
===========
Silex allows you to run code, that changes the default Silex behavior, at
different stages during the handling of a request through *middleware
s
*:
different stages during the handling of a request through *middleware*:
* *Application middleware
s* are
triggered independently of the current handled
* *Application middleware
* is
triggered independently of the current handled
request;
* *Route middleware
s* are triggered when their
associated route is matched.
* *Route middleware
* is triggered when its
associated route is matched.
Application Middleware
s
----------------------
-
Application Middleware
----------------------
The application middlewares are
only run for the "master" Request.
Application middleware is
only run for the "master" Request.
Before Middleware
~~~~~~~~~~~~~~~~~
...
...
@@ -73,10 +73,10 @@ Response has been sent to the client (like sending emails or logging)::
The finish middleware is an event registered on the Symfony *terminate*
event.
Route Middleware
s
----------------
-
Route Middleware
----------------
Route middleware
s are added to routes or route collections and they are
only
Route middleware
is added to routes or route collections and it is
only
triggered when the corresponding route is matched. You can also stack them::
$app->get('/somewhere', function () {
...
...
@@ -92,7 +92,7 @@ Before Middleware
~~~~~~~~~~~~~~~~~
A *before* route middleware is fired just before the route callback, but after
the *before* application middleware
s
::
the *before* application middleware::
$before = function (Request $request, Application $app) {
// ...
...
...
@@ -107,7 +107,7 @@ After Middleware
~~~~~~~~~~~~~~~~
An *after* route middleware is fired just after the route callback, but before
the application *after* application middleware
s
::
the application *after* application middleware::
$after = function (Request $request, Response $response, Application $app) {
// ...
...
...
@@ -118,10 +118,10 @@ the application *after* application middlewares::
})
->after($after);
Middleware
s
Priority
-------------------
-
Middleware Priority
-------------------
You can add as m
any middlewares
as you want, in which case they are triggered
You can add as m
uch middleware
as you want, in which case they are triggered
in the same order as you added them.
You can explicitly control the priority of your middleware by passing an
...
...
@@ -146,8 +146,8 @@ Short-circuiting the Controller
-------------------------------
If a *before* middleware returns a ``Response`` object, the request handling is
short-circuited (the next middleware
s
won't be run, nor the route
callback), and the Response is passed to the *after* middleware
s
right away::
short-circuited (the next middleware won't be run, nor the route
callback), and the Response is passed to the *after* middleware right away::
$app->before(function (Request $request) {
// redirect the user to the login screen if access to the Resource is protected
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment