8000 Merge branch '3.3' into 3.4 · symfony/symfony-docs@29cae98 · GitHub
[go: up one dir, main page]

Skip to content

Commit 29cae98

Browse files
committed
Merge branch '3.3' into 3.4
* 3.3: 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 ebf7654 + b8d7a49 commit 29cae98

File tree

5 files changed

+34
-25
lines changed

5 files changed

+34
-25
lines changed

bundles.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Creating a Bundle
7373
`SensioGeneratorBundle`_ is an optional bundle that includes commands to create
7474
different elements of your application, such as bundles. If you create lots of
7575
bundles, consider using it. However, this section creates and enables a new
76-
bundle by hand to show how simple is to do it.
76+
bundle by hand to show how simple it is to do it.
7777

7878
The new bundle is called AcmeTestBundle, where the ``Acme`` portion is just a
7979
dummy name that should be replaced by some "vendor" name that represents you or
@@ -185,4 +185,4 @@ Learn more
185185
bundles/*
186186

187187
.. _`third-party bundles`: https://github.com/search?q=topic%3Asymfony-bundle&type=Repositories
188-
.. _`SensioGeneratorBundle`: https://github.com/sensiolabs/SensioGeneratorBundle
188+
.. _`SensioGeneratorBundle`: https://symfony.com/doc/current/bundles/SensioGeneratorBundle/index.html

reference/forms/types/choice.rst

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

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

268+
.. include:: /reference/forms/types/options/attr.rst.inc
269+
266270
.. include:: /reference/forms/types/options/by_reference.rst.inc
267271

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

routing.rst

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

697697
Here are some common errors you might see while working with routing:
698698

699-
Controller "AppBundle\Controller\BlogController::showAction()" requires that you
699+
Controller "AppBundle\\Controller\\BlogController::showAction()" requires that you
700700
provide a value for the "$slug" argument.
701701

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

security.rst

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -997,28 +997,21 @@ shown above.
997997
-----------------------------
998998

999999
After authentication, the ``User`` object of the current user can be accessed
1000-
via the ``security.token_storage`` service. From inside a controller, this will
1001-
look like::
1002-
1003-
use Symfony\Component\Security\Core\User\UserInterface;
1000+
via the ``getUser()`` shortcut (which uses the ``security.token_storage``
1001+
service). From inside a controller, this will look like::
10041002

10051003
public function indexAction()
10061004
{
10071005
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
10081006

10091007
$user = $this->getUser();
1010-
// or you can also type-hint a method argument with UserInterface: e.g. "UserInterface $user"
10111008
}
10121009

10131010
.. tip::
10141011

10151012
The user will be an object and the class of that object will depend on
10161013
your :ref:`user provider <security-user-providers>`.
10171014

1018-
.. versionadded:: 3.2
1019-
The ability to get the user by type-hinting an argument with UserInterface
1020-
was introduced in Symfony 3.2.
1021-
10221015
Now you can call whatever methods are on *your* User object. For example,
10231016
if your User object has a ``getFirstName()`` method, you could use that::
10241017

@@ -1039,14 +1032,7 @@ It's important to check if the user is authenticated first. If they're not,
10391032
``$user`` will either be ``null`` or the string ``anon.``. Wait, what? Yes,
10401033
this is a quirk. If you're not logged in, the user is technically the string
10411034
``anon.``, though the ``getUser()`` controller shortcut converts this to
1042-
``null`` for convenience. When type-hinting the
1043-
:class:`Symfony\\Component\\Security\\Core\\User\\UserInterface\\UserInterface`
1044-
and being logged-in is optional, you can allow a null value for the argument::
1045-
1046-
public function indexAction(UserInterface $user = null)
1047-
{
1048-
// $user is null when not logged-in or anon.
1049-
}
1035+
``null`` for convenience.
10501036

10511037
The point is this: always check to see if the user is logged in before using
10521038
the User object, and use the ``isGranted()`` method (or
@@ -1062,6 +1048,25 @@ the User object, and use the ``isGranted()`` method (or
10621048

10631049
}
10641050

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

service_container/service_decoration.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ replaces the ``app.mailer`` service. The old ``app.mailer`` service is renamed t
170170
Decoration Priority
171171
-------------------
172172

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

177177
.. configuration-block::
178178

0 commit comments

Comments
 (0)
0