Skip to content

Commit 66b2469

Browse files
committed
Merge branch '2.8' into 3.0
2 parents e9a92af + b602b9c commit 66b2469

File tree

4 files changed

+99
-39
lines changed

4 files changed

+99
-39
lines changed

book/controller.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,8 @@ Just like when creating a controller for a route, the order of the arguments of
806806
order of the arguments, Symfony will still pass the correct value to each
807807
variable.
808808

809+
.. _checking-the-validity-of-a-csrf-token::
810+
809811
Validating a CSRF Token
810812
-----------------------
811813

book/routing.rst

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -812,10 +812,10 @@ Adding HTTP Method Requirements
812812
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
813813

814814
In addition to the URL, you can also match on the *method* of the incoming
815-
request (i.e. GET, HEAD, POST, PUT, DELETE). Suppose you have a contact form
816-
with two controllers - one for displaying the form (on a GET request) and one
817-
for processing the form when it's submitted (on a POST request). This can
818-
be accomplished with the following route configuration:
815+
request (i.e. GET, HEAD, POST, PUT, DELETE). Suppose you create an API for
816+
your blog and you have 2 routes: One for displaying a post (on a GET or HEAD
817+
request) and one for updating a post (on a PUT request). This can be
818+
accomplished with the following route configuration:
819819

820820
.. configuration-block::
821821

@@ -827,39 +827,39 @@ be accomplished with the following route configuration:
827827
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
828828
// ...
829829
830-
class MainController extends Controller
830+
class BlogApiController extends Controller
831831
{
832832
/**
833-
* @Route("/news")
834-
* @Method("GET")
833+
* @Route("/api/posts/{id}")
834+
* @Method({"GET","HEAD"})
835835
*/
836-
public function newsAction()
836+
public function showAction($id)
837837
{
838-
// ... display your news
838+
// ... return a JSON response with the post
839839
}
840840
841841
/**
842-
* @Route("/contact")
843-
* @Method({"GET", "POST"})
842+
* @Route("/api/posts/{id}")
843+
* @Method("PUT")
844844
*/
845-
public function contactFormAction()
845+
public function editAction($id)
846846
{
847-
// ... display and process a contact form
847+
// ... edit a post
848848
}
849849
}
850850
851851
.. code-block:: yaml
852852
853853
# app/config/routing.yml
854-
news:
855-
path: /news
856-
defaults: { _controller: AppBundle:Main:news }
857-
methods: [GET]
854+
api_post_show:
855+
path: /api/posts/{id}
856+
defaults: { _controller: AppBundle:BlogApi:show }
857+
methods: [GET, HEAD]
858858
859-
contact_form:
860-
path: /contact
861-
defaults: { _controller: AppBundle:Main:contactForm }
862-
methods: [GET, POST]
859+
api_post_edit:
860+
path: /api/posts/{id}
861+
defaults: { _controller: AppBundle:BlogApi:edit }
862+
methods: [PUT]
863863
864864
.. code-block:: xml
865865
@@ -870,12 +870,12 @@ be accomplished with the following route configuration:
870870
xsi:schemaLocation="http://symfony.com/schema/routing
871871
http://symfony.com/schema/routing/routing-1.0.xsd">
872872
873-
<route id="news" path="/news" methods="GET">
874-
<default key="_controller">AppBundle:Main:news</default>
873+
<route id="api_post_show" path="/api/posts/{id}" methods="GET|HEAD">
874+
<default key="_controller">AppBundle:BlogApi:show</default>
875875
</route>
876876
877-
<route id="contact_form" path="/contact" methods="GET|POST">
878-
<default key="_controller">AppBundle:Main:contactForm</default>
877+
<route id="api_post_edit" path="/api/posts/{id}" methods="PUT">
878+
<default key="_controller">AppBundle:BlogApi:edit</default>
879879
</route>
880880
</routes>
881881
@@ -886,20 +886,21 @@ be accomplished with the following route configuration:
886886
use Symfony\Component\Routing\Route;
887887
888888
$collection = new RouteCollection();
889-
$collection->add('news', new Route('/news', array(
890-
'_controller' => 'AppBundle:Main:contact',
891-
), array(), array(), '', array(), array('GET')));
889+
$collection->add('api_post_show', new Route('/api/posts/{id}', array(
890+
'_controller' => 'AppBundle:BlogApi:show',
891+
), array(), array(), '', array(), array('GET', 'HEAD')));
892892
893-
$collection->add('contact_form', new Route('/contact', array(
894-
'_controller' => 'AppBundle:Main:contactForm',
895-
), array(), array(), '', array(), array('GET', 'POST')));
893+
$collection->add('api_post_edit', new Route('/api/posts/{id}', array(
894+
'_controller' => 'AppBundle:BlogApi:edit',
895+
), array(), array(), '', array(), array('PUT')));
896896
897897
return $collection;
898898
899-
Despite the fact that these two routes have identical paths (``/contact``),
900-
the first route will match only GET requests and the second route will match
901-
only POST requests. This means that you can display the form and submit the
902-
form via the same URL, while using distinct controllers for the two actions.
899+
Despite the fact that these two routes have identical paths
900+
(``/api/posts/{id}``), the first route will match only GET or HEAD requests and
901+
the second route will match only PUT requests. This means that you can display
902+
and edit the post with the same URL, while using distinct controllers for the
903+
two actions.
903904

904905
.. note::
905906

components/routing/introduction.rst

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,15 @@ URL path and some array of custom variables in its constructor. This array
6262
of custom variables can be *anything* that's significant to your application,
6363
and is returned when that route is matched.
6464

65-
If no matching route can be found a
66-
:class:`Symfony\\Component\\Routing\\Exception\\ResourceNotFoundException` will be thrown.
65+
The :method:`UrlMatcher::match() <Symfony\\Component\\Routing\\UrlMatcher::match>`
66+
returns the variables you set on the route as well as the wildcard placeholders
67+
(see below). Your application can now use this information to continue
68+
processing the request. In addition to the configured variables, a ``_route``
69+
key is added, which holds the name of the matched route.
6770

68-
In addition to your array of custom variables, a ``_route`` key is added,
69-
which holds the name of the matched route.
71+
If no matching route can be found, a
72+
:class:`Symfony\\Component\\Routing\\Exception\\ResourceNotFoundException` will
73+
be thrown.
7074

7175
Defining Routes
7276
~~~~~~~~~~~~~~~
@@ -123,6 +127,10 @@ In this case, the route is matched by ``/archive/2012-01``, because the ``{month
123127
wildcard matches the regular expression wildcard given. However, ``/archive/foo``
124128
does *not* match, because "foo" fails the month wildcard.
125129

130+
When using wildcards, these are returned in the array result when calling
131+
``match``. The part of the path that the wildcard matched (e.g. ``2012-01``) is used
132+
as value.
133+
126134
.. tip::
127135

128136
If you want to match all URLs which start with a certain path and end in an

components/security/authentication.rst

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,5 +269,54 @@ in) is correct, you can use::
269269
$user->getSalt()
270270
);
271271

272+
Authentication Events
273+
---------------------
274+
275+
The security component provides 4 related authentication events:
276+
277+
=============================== ================================================ =========================================================================
278+
Name Event Constant Argument Passed to the Listener
279+
=============================== ================================================ =========================================================================
280+
security.authentication.success ``AuthenticationEvents::AUTHENTICATION_SUCCESS`` :class:`Symfony\Component\Security\Core\Event\AuthenticationEvent`
281+
security.authentication.failure ``AuthenticationEvents::AUTHENTICATION_FAILURE`` :class:`Symfony\Component\Security\Core\Event\AuthenticationFailureEvent`
282+
security.interactive_login ``SecurityEvents::INTERACTIVE_LOGIN`` :class:`Symfony\Component\Security\Http\Event\InteractiveLoginEvent`
283+
security.switch_user ``SecurityEvents::SWITCH_USER`` :class:`Symfony\Component\Security\Http\Event\SwitchUserEvent`
284+
=============================== ================================================ =========================================================================
285+
286+
Authentication Success and Failure Events
287+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
288+
289+
When a provider authenticates the user, a ``security.authentication.success``
290+
event is dispatched. But beware - this event will fire, for example, on *every*
291+
request if you have session-based authentication. See ``security.interactive_login``
292+
below if you need to do something when a user *actually* logs in.
293+
294+
When a provider attempts authentication but fails (i.e. throws an ``AuthenticationException``),
295+
a ``security.authentication.failure`` event is dispatched. You could listen on
296+
the ``security.authentication.failure`` event, for example, in order to log
297+
failed login attempts.
298+
299+
Security Events
300+
~~~~~~~~~~~~~~~
301+
302+
The ``security.interactive_login`` event is triggered after a user has actively
303+
logged into your website. It is important to distinguish this action from
304+
non-interactive authentication methods, such as:
305+
306+
* authentication based on a "remember me" cookie.
307+
* authentication based on your session.
308+
* authentication using a HTTP basic or HTTP digest header.
309+
310+
You could listen on the ``security.interactive_login`` event, for example, in
311+
order to give your user a welcome flash message every time they log in.
312+
313+
The ``security.switch_user`` event is triggered every time you activate
314+
the ``switch_user`` firewall listener.
315+
316+
.. seealso::
317+
318+
For more information on switching users, see
319+
:doc:`/cookbook/security/impersonating_user`.
320+
272321
.. _`CVE-2013-5750`: https://symfony.com/blog/cve-2013-5750-security-issue-in-fosuserbundle-login-form
273322
.. _`BasePasswordEncoder::checkPasswordLength`: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Security/Core/Encoder/BasePasswordEncoder.php

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy