Skip to content

Commit 502e333

Browse files
committed
Merge branch '3.4'
* 3.4: (40 commits) Adding an article to explain the 3.3 changes, and how to upgrade updating instance Avoid backticks in shell scripts Update optional_dependencies.rst Fix xml blocks pass only strings to loadUserByUsername() Fix Authenticator Class (getCredentials) example Documented addAnnotatedClassesToCompile() and the use of class patterns Added the picture that shows how GuardAuthenticationListener calls Authentication Guard methods. [#7205] minor tweak Simplified the use of transChoice() [#7875] minor tweaks Minor fix Minor changes Properly show all events and describe guard events [#7891] remove not needed sentence [#7773] fix line length Add helpful remarks on custom DataCollector Remove use of deprecated security.exception_listener.class parameter Update resources.rst ...
2 parents 80138ca + 52e4032 commit 502e333

File tree

105 files changed

+2008
-545
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+2008
-545
lines changed
Loading

bundles/best_practices.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,17 @@ The end user can provide values in any configuration file:
348348
.. code-block:: xml
349349
350350
<!-- app/config/config.xml -->
351-
<parameters>
352-
<parameter key="acme_blog.author.email">fabien@example.com</parameter>
353-
</parameters>
351+
<?xml version="1.0" encoding="UTF-8" ?>
352+
<container xmlns="http://symfony.com/schema/dic/services"
353+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
354+
xsi:schemaLocation="http://symfony.com/schema/dic/services
355+
http://symfony.com/schema/dic/services/services-1.0.xsd">
356+
357+
<parameters>
358+
<parameter key="acme_blog.author.email">fabien@example.com</parameter>
359+
</parameters>
360+
361+
</container>
354362
355363
.. code-block:: php
356364

bundles/configuration.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ thrown)::
225225
$configuration = new Configuration();
226226

227227
$config = $this->processConfiguration($configuration, $configs);
228-
228+
229229
// you now have these 2 config keys
230230
// $config['twitter']['client_id'] and $config['twitter']['client_secret']
231231
}
@@ -424,7 +424,6 @@ Assuming the XSD file is called ``hello-1.0.xsd``, the schema location will be
424424
425425
<!-- app/config/config.xml -->
426426
<?xml version="1.0" ?>
427-
428427
<container xmlns="http://symfony.com/schema/dic/services"
429428
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
430429
xmlns:acme-hello="http://acme_company.com/schema/dic/hello"

bundles/extension.rst

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,14 @@ Symfony creates a big ``classes.php`` file in the cache directory to aggregate
133133
the contents of the PHP classes that are used in every request. This reduces the
134134
I/O operations and increases the application performance.
135135

136+
.. versionadded:: 3.2
137+
The ``addAnnotatedClassesToCompile()`` method was added in Symfony 3.2.
138+
136139
Your bundles can also add their own classes into this file thanks to the
137-
``addClassesToCompile()`` method. Define the classes to compile as an array of
138-
their fully qualified class names::
140+
``addClassesToCompile()`` and ``addAnnotatedClassesToCompile()`` methods (both
141+
work in the same way, but the second one is for classes that contain PHP
142+
annotations). Define the classes to compile as an array of their fully qualified
143+
class names::
139144

140145
use AppBundle\Manager\UserManager;
141146
use AppBundle\Utils\Slugger;
@@ -145,22 +150,52 @@ their fully qualified class names::
145150
{
146151
// ...
147152

153+
// this method can't compile classes that contain PHP annotations
148154
$this->addClassesToCompile(array(
149155
UserManager::class,
150156
Slugger::class,
151157
// ...
152158
));
159+
160+
// add here only classes that contain PHP annotations
161+
$this->addAnnotatedClassesToCompile(array(
162+
'AppBundle\\Controller\\DefaultController',
163+
// ...
164+
));
153165
}
154166

155167
.. note::
156168

157169
If some class extends from other classes, all its parents are automatically
158170
included in the list of classes to compile.
159171

160-
Beware that this technique **can't be used in some cases**:
172+
.. versionadded:: 3.2
173+
The option to add classes to compile using patterns was introduced in Symfony 3.2.
174+
175+
The classes to compile can also be added using file path patterns::
176+
177+
// ...
178+
public function load(array $configs, ContainerBuilder $container)
179+
{
180+
// ...
181+
182+
$this->addClassesToCompile(array(
183+
'**Bundle\\Manager\\',
184+
// ...
185+
));
186+
187+
$this->addAnnotatedClassesToCompile(array(
188+
'**Bundle\\Controller\\',
189+
// ...
190+
));
191+
}
192+
193+
Patterns are transformed into the actual class namespaces using the classmap
194+
generated by Composer. Therefore, before using these patterns, you must generate
195+
the full classmap executing the ``dump-autoload`` command of Composer.
196+
197+
.. caution::
161198

162-
* When classes contain annotations, such as controllers with ``@Route``
163-
annotations and entities with ``@ORM`` or ``@Assert`` annotations, because
164-
the file location retrieved from PHP reflection changes;
165-
* When classes use the ``__DIR__`` and ``__FILE__`` constants, because their
166-
values will change when loading these classes from the ``classes.php`` file.
199+
This technique can't be used when the classes to compile use the ``__DIR__``
200+
or ``__FILE__`` constants, because their values will change when loading
201+
these classes from the ``classes.php`` file.

bundles/prepend_extension.rst

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ users to choose to remove functionality they are not using. Creating multiple
1212
bundles has the drawback that configuration becomes more tedious and settings
1313
often need to be repeated for various bundles.
1414

15-
It is possible to remove the disadvantage of the multiple bundle approach
15+
It is possible to remove the disadvantage of the multiple bundle approach
1616
by enabling a single Extension to prepend the settings for any bundle.
1717
It can use the settings defined in the ``app/config/config.yml``
1818
to prepend settings just as if they had been written explicitly by
@@ -116,11 +116,21 @@ The above would be the equivalent of writing the following into the
116116
.. code-block:: xml
117117
118118
<!-- app/config/config.xml -->
119-
<acme-something:config use-acme-goodbye="false">
120-
<acme-something:entity-manager-name>non_default</acme-something:entity-manager-name>
121-
</acme-something:config>
119+
<?xml version="1.0" encoding="UTF-8" ?>
120+
<container xmlns="http://symfony.com/schema/dic/services"
121+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
122+
xmlns:acme-something="http://example.org/schema/dic/acme_something"
123+
xmlns:acme-other="http://example.org/schema/dic/acme_other"
124+
xsi:schemaLocation="http://symfony.com/schema/dic/services
125+
http://symfony.com/schema/dic/services/services-1.0.xsd">
122126
123-
<acme-other:config use-acme-goodbye="false" />
127+
<acme-something:config use-acme-goodbye="false">
128+
<acme-something:entity-manager-name>non_default</acme-something:entity-manager-name>
129+
</acme-something:config>
130+
131+
<acme-other:config use-acme-goodbye="false" />
132+
133+
</container>
124134
125135
.. code-block:: php
126136

components/expression_language.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ Caching
112112
The component provides some different caching strategies, read more about them
113113
in :doc:`/components/expression_language/caching`.
114114

115+
AST Dumping and Editing
116+
-----------------------
117+
118+
The AST (*Abstract Syntax Tree*) of expressions can be dumped and manipulated
119+
as explained in :doc:`/components/expression_language/ast`.
120+
115121
Learn More
116122
----------
117123

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
.. index::
2+
single: AST; ExpressionLanguage
3+
single: AST; Abstract Syntax Tree
4+
5+
Dumping and Manipulating the AST of Expressions
6+
===============================================
7+
8+
Manipulating or inspecting the expressions created with the ExpressionLanguage
9+
component is difficult because they are plain strings. A better approach is to
10+
turn those expressions into an AST. In computer science, `AST`_ (*Abstract
11+
Syntax Tree*) is *"a tree representation of the structure of source code written
12+
in a programming language"*. In Symfony, a ExpressionLanguage AST is a set of
13+
nodes that contain PHP classes representing the given expression.
14+
15+
Dumping the AST
16+
---------------
17+
18+
Call the :method:`Symfony\\Component\\ExpressionLanguage\\ExpressionLanguage::getNodes`
19+
method after parsing any expression to get its AST::
20+
21+
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
22+
23+
$ast = (new ExpressionLanguage())
24+
->parse('1 + 2')
25+
->getNodes()
26+
;
27+
28+
// dump the AST nodes for inspection
29+
var_dump($ast);
30+
31+
// dump the AST nodes as a string representation
32+
$astAsString = $ast->dump();
33+
34+
Manipulating the AST
35+
--------------------
36+
37+
The nodes of the AST can also be dumped into a PHP array of nodes to allow
38+
manipulating them. Call the :method:`Symfony\\Component\\ExpressionLanguage\\ExpressionLanguage::toArray`
39+
method to turn the AST into an array::
40+
41+
// ...
42+
43+
$astAsArray = (new ExpressionLanguage())
44+
->parse('1 + 2')
45+
->getNodes()
46+
->toArray()
47+
;
48+
49+
.. _`AST`: https://en.wikipedia.org/wiki/Abstract_syntax_tree

components/http_foundation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ handling, switching to chunked encoding instead::
544544

545545
If you *just* created the file during this same request, the file *may* be sent
546546
without any content. This may be due to cached file stats that return zero for
547-
the size of the file. To fix this issue, call ``clearstatcache(false, $file)``
547+
the size of the file. To fix this issue, call ``clearstatcache(true, $file)``
548548
with the path to the binary file.
549549

550550
.. _component-http-foundation-json-response:

components/translation/usage.rst

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,16 +253,39 @@ all the forms as a string separated by a pipe (``|``)::
253253
To translate pluralized messages, use the
254254
:method:`Symfony\\Component\\Translation\\Translator::transChoice` method::
255255

256+
// the %count% placeholder is assigned to the second argument...
256257
$translator->transChoice(
257258
'There is one apple|There are %count% apples',
259+
10
260+
);
261+
262+
// ...but you can define more placeholders if needed
263+
$translator->transChoice(
264+
'Hurry up %name%! There is one apple left.|There are %count% apples left.',
258265
10,
259-
array('%count%' => 10)
266+
// no need to include %count% here; Symfony does that for you
267+
array('%name%' => $user->getName())
260268
);
261269

262270
The second argument (``10`` in this example) is the *number* of objects being
263271
described and is used to determine which translation to use and also to populate
264272
the ``%count%`` placeholder.
265273

274+
.. versionadded:: 3.2
275+
276+
Before Symfony 3.2, the placeholder used to select the plural (``%count%``
277+
in this example) must be included in the third optional argument of the
278+
``transChoice()`` method::
279+
280+
$translator->transChoice(
281+
'There is one apple|There are %count% apples',
282+
10,
283+
array('%count%' => 10)
284+
);
285+
286+
Starting from Symfony 3.2, when the only placeholder is ``%count%``, you
287+
don't have to pass this third argument.
288+
266289
Based on the given number, the translator chooses the right plural form.
267290
In English, most words have a singular form when there is exactly one object
268291
and a plural form for all other numbers (0, 2, 3...). So, if ``count`` is
@@ -366,11 +389,25 @@ use for translation::
366389
$translator->transChoice(
367390
'{0} There are no apples|{1} There is one apple|]1,Inf[ There are %count% apples',
368391
10,
369-
array('%count%' => 10),
392+
array(),
370393
'messages',
371394
'fr_FR'
372395
);
373396

397+
.. note::
398+
399+
Starting from Symfony 3.2, the third argument of ``transChoice()`` is
400+
optional when the only placeholder in use is ``%count%``. In previous
401+
Symfony versions you needed to always define it::
402+
403+
$translator->transChoice(
404+
'{0} There are no apples|{1} There is one apple|]1,Inf[ There are %count% apples',
405+
10,
406+
array('%count%' => 10),
407+
'messages',
408+
'fr_FR'
409+
);
410+
374411
Retrieving the Message Catalogue
375412
--------------------------------
376413

components/validator/resources.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ In this example, the validation metadata is retrieved executing the
4545
public static function loadValidatorMetadata(ClassMetadata $metadata)
4646
{
4747
$metadata->addPropertyConstraint('name', new Assert\NotBlank());
48-
$metadata->addPropertyConstraint('name', new Asert\Length(array(
48+
$metadata->addPropertyConstraint('name', new Assert\Length(array(
4949
'min' => 5,
5050
'max' => 20,
5151
)));

0 commit comments

Comments
 (0)