Skip to content

Commit b762d37

Browse files
committed
Merge branch '3.4' into 4.0
* 3.4: Use escaped backslashes Don't mention the UserInterface type-hinting Add information about default value for decoration_priority Adding the missing attr option to the ChoiceType Update choice.rst Minor fixes in the bundles article
2 parents e8a4d96 + 29cae98 commit b762d37

File tree

5 files changed

+33
-19
lines changed

5 files changed

+33
-19
lines changed

bundles.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ file::
4444
Creating a Bundle
4545
-----------------
4646

47-
This section creates and enables a new bundle to show how simple is to do it.
47+
This section creates and enables a new bundle to show how simple it is to do it.
4848
The new bundle is called AcmeTestBundle, where the ``Acme`` portion is just a
4949
dummy name that should be replaced by some "vendor" name that represents you or
5050
your organization (e.g. ABCTestBundle for some company named ``ABC``).

reference/forms/types/choice.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ To use this field, you must specify *either* ``choices`` or ``choice_loader`` op
2929
| options | - `empty_data`_ |
3030
| | - `error_bubbling`_ |
3131
+-------------+------------------------------------------------------------------------------+
32-
| Inherited | - `by_reference`_ |
33-
| options | - `data`_ |
32+
| Inherited | - `attr`_ |
33+
| options | - `by_reference`_ |
34+
| | - `data`_ |
3435
| | - `disabled`_ |
3536
| | - `error_mapping`_ |
3637
| | - `inherit_data`_ |
@@ -98,6 +99,7 @@ method::
9899
'choice_attr' => function($category, $key, $index) {
99100
return ['class' => 'category_'.strtolower($category->getName())];
100101
},
102+
101103
'group_by' => function($category, $key, $index) {
102104
// randomly assign things into 2 groups
103105
return rand(0, 1) == 1 ? 'Group A' : 'Group B';
@@ -252,6 +254,8 @@ Inherited Options
252254

253255
These options inherit from the :doc:`FormType </reference/forms/types/form>`:
254256

257+
.. include:: /reference/forms/types/options/attr.rst.inc
258+
255259
.. include:: /reference/forms/types/options/by_reference.rst.inc
256260

257261
.. include:: /reference/forms/types/options/data.rst.inc

routing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ Troubleshooting
616616

617617
Here are some common errors you might see while working with routing:
618618

619-
Controller "App\Controller\BlogController::show()" requires that you
619+
Controller "App\\Controller\\BlogController::show()" requires that you
620620
provide a value for the "$slug" argument.
621621

622622
This happens when your controller method has an argument (e.g. ``$slug``)::

security.rst

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,16 +1007,14 @@ If you still prefer to use traditional ACLs, refer to the `Symfony ACL bundle`_.
10071007
-----------------------------
10081008

10091009
After authentication, the ``User`` object of the current user can be accessed
1010-
via the ``security.token_storage`` service. From inside a controller, this will
1011-
look like::
1010+
via the ``getUser()`` shortcut (which uses the ``security.token_storage``
1011+
service). From inside a controller, this will look like::
10121012

10131013
public function index()
10141014
{
10151015
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
10161016

10171017
$user = $this->getUser();
1018-
// or you can also type-hint a method argument with this class:
1019-
// Symfony\Component\Security\Core\User\UserInterface (e.g. "UserInterface $user")
10201018
}
10211019

10221020
.. tip::
@@ -1044,14 +1042,7 @@ It's important to check if the user is authenticated first. If they're not,
10441042
``$user`` will either be ``null`` or the string ``anon.``. Wait, what? Yes,
10451043
this is a quirk. If you're not logged in, the user is technically the string
10461044
``anon.``, though the ``getUser()`` controller shortcut converts this to
1047-
``null`` for convenience. When type-hinting the
1048-
:class:`Symfony\\Component\\Security\\Core\\User\\UserInterface\\UserInterface`
1049-
and being logged-in is optional, you can allow a null value for the argument::
1050-
1051-
public function index(UserInterface $user = null)
1052-
{
1053-
// $user is null when not logged-in or anon.
1054-
}
1045+
``null`` for convenience.
10551046

10561047
The point is this: always check to see if the user is logged in before using
10571048
the User object, and use the ``isGranted()`` method (or
@@ -1065,6 +1056,25 @@ the User object, and use the ``isGranted()`` method (or
10651056
// ...
10661057
}
10671058

1059+
.. note::
1060+
1061+
An alternative way to get the current user in a controller is to type-hint
1062+
the controller argument with
1063+
:class:`Symfony\\Component\\Security\\Core\\User\\UserInterface\\UserInterface`
1064+
(and default it to ``null`` if being logged-in is optional)::
1065+
1066+
use Symfony\Component\Security\Core\User\UserInterface\UserInterface;
1067+
1068+
public function indexAction(UserInterface $user = null)
1069+
{
1070+
// $user is null when not logged-in or anon.
1071+
}
1072+
1073+
This is only recommended for experienced developers who don't extend from the
1074+
:ref:`Symfony base controller <the-base-controller-class-services>` and
1075+
don't use the :class:`Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait`
1076+
either. Otherwise, it's recommended to keep using the ``getUser()`` shortcut.
1077+
10681078
Retrieving the User in a Template
10691079
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10701080

service_container/service_decoration.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ replaces the ``app.mailer`` service. The old ``app.mailer`` service is renamed t
179179
Decoration Priority
180180
-------------------
181181

182-
If you want to apply more than one decorator to a service, you can control their
183-
order by configuring the priority of decoration, this can be any integer number
184-
(decorators with higher priorities will be applied first).
182+
When applying multiple decorators to a service, you can control their order with
183+
the ``decoration_priority`` option. Its value is an integer that defaults to
184+
``0`` and higher priorities mean that decorators will be applied earlier.
185185

186186
.. configuration-block::
187187

0 commit comments

Comments
 (0)