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
670fd5d3
Commit
670fd5d3
authored
May 01, 2016
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.3'
* 1.3: fixed typo s/middlewares/middleware
parents
bade8a07
4d45eafa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
18 deletions
+18
-18
doc/middlewares.rst
doc/middlewares.rst
+18
-18
No files found.
doc/middlewares.rst
View file @
670fd5d3
Middleware
s
Middleware
==========
=
==========
Silex allows you to run code, that changes the default Silex behavior, at
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;
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
Before Middleware
~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~
...
@@ -73,10 +73,10 @@ Response has been sent to the client (like sending emails or logging)::
...
@@ -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*
The finish middleware is an event registered on the Symfony *terminate*
event.
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::
triggered when the corresponding route is matched. You can also stack them::
$app->get('/somewhere', function () {
$app->get('/somewhere', function () {
...
@@ -92,7 +92,7 @@ Before Middleware
...
@@ -92,7 +92,7 @@ Before Middleware
~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~
A *before* route middleware is fired just before the route callback, but after
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) {
$before = function (Request $request, Application $app) {
// ...
// ...
...
@@ -107,7 +107,7 @@ After Middleware
...
@@ -107,7 +107,7 @@ After Middleware
~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~
An *after* route middleware is fired just after the route callback, but before
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) {
$after = function (Request $request, Response $response, Application $app) {
// ...
// ...
...
@@ -118,10 +118,10 @@ the application *after* application middlewares::
...
@@ -118,10 +118,10 @@ the application *after* application middlewares::
})
})
->after($after);
->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.
in the same order as you added them.
You can explicitly control the priority of your middleware by passing an
You can explicitly control the priority of your middleware by passing an
...
@@ -146,8 +146,8 @@ Short-circuiting the Controller
...
@@ -146,8 +146,8 @@ Short-circuiting the Controller
-------------------------------
-------------------------------
If a *before* middleware returns a ``Response`` object, the request handling is
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
short-circuited (the next middleware won't be run, nor the route
callback), and the Response is passed to the *after* middleware
s
right away::
callback), and the Response is passed to the *after* middleware right away::
$app->before(function (Request $request) {
$app->before(function (Request $request) {
// redirect the user to the login screen if access to the Resource is protected
// 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