Skip to content

Commit 82be2e4

Browse files
committed
Merge branch '4.0'
* 4.0: (33 commits) Fixed merge errors Client's history clear alternative Don't mention the abandoned JMSTranslationBundle Reworded the console verbosity article to explain SHELL_VERBOSITY too Simplify the setup article Added a tip about tests and BCrypt Document that Doctrine associations don't work across different entity managers Update entity_provider.rst Removed the section that explains how to install all components Improved the link to the CSRF config referece Reword Make require as a dev dependency Fixed invalid form validation reference fix a typo use a class based service ID Update entity_provider.rst Update doctrine.rst Merged new example in older example, removing some text Fix typo Document typed arrays in optionsresolver ...
2 parents e49526e + 9bf91ce commit 82be2e4

24 files changed

+200
-124
lines changed

best_practices/i18n.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ XLIFF notes allow you to define that context.
3636

3737
.. tip::
3838

39-
The Apache-licensed `JMSTranslationBundle`_ offers you a web interface for
40-
viewing and editing these translation files. It also has advanced extractors
41-
that can read your project and automatically update the XLIFF files.
39+
The `PHP Translation Bundle`_ includes advanced extractors that can read
40+
your project and automatically update the XLIFF files.
4241

4342
Translation Keys
4443
----------------
@@ -80,4 +79,4 @@ English in the application would be:
8079

8180
Next: :doc:`/best_practices/security`
8281

83-
.. _`JMSTranslationBundle`: https://github.com/schmittjoh/JMSTranslationBundle
82+
.. _`PHP Translation Bundle`: https://github.com/php-translation/symfony-bundle

components/browser_kit.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ also delete all the cookies::
226226
$client = new Client();
227227
$client->request('GET', '/');
228228

229-
// delete history
229+
// reset the client (history and cookies are cleared too)
230230
$client->restart();
231231

232232
Learn more

components/ldap.rst

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,52 @@ LDAP server), you may query the LDAP server using the
7373

7474
// ...
7575

76-
$ldap->query('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))');
76+
$query = $ldap->query('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))');
77+
$results = $query->execute();
78+
79+
foreach ($results as $entry) {
80+
// Do something with the results
81+
}
82+
83+
By default, LDAP entries are lazy-loaded. If you wish to fetch
84+
all entries in a single call and do something with the results'
85+
array, you may use the
86+
:method:`Symfony\\Component\\Ldap\\Adapter\\ExtLdap\\Collection::toArray` method::
87+
88+
// ...
89+
90+
$query = $ldap->query('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))');
91+
$results = $query->execute()->toArray();
92+
93+
// Do something with the results array
94+
95+
Creating or updating entries
96+
----------------------------
97+
98+
Since version 3.1, The Ldap component provides means to create
99+
new LDAP entries, update or even delete existing ones::
100+
101+
use Symfony\Component\Ldap\Entry;
102+
// ...
103+
104+
$entry = new Entry('cn=Fabien Potencier,dc=symfony,dc=com', array(
105+
'sn' => array('fabpot'),
106+
'objectClass' => array('inetOrgPerson'),
107+
));
108+
109+
$em = $ldap->getEntryManager();
110+
111+
// Creating a new entry
112+
$em->add($entry);
113+
114+
// Finding and updating an existing entry
115+
$query = $ldap->query('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))');
116+
$result = $query->execute();
117+
$entry = $result[0];
118+
$entry->addAttribute('email', array('fabpot@symfony.com'));
119+
$em->update($entry);
120+
121+
// Removing an existing entry
122+
$em->remove(new Entry('cn=Test User,dc=symfony,dc=com'));
77123

78124
.. _Packagist: https://packagist.org/packages/symfony/ldap

components/options_resolver.rst

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,27 @@ correctly. To validate the types of the options, call
317317
public function configureOptions(OptionsResolver $resolver)
318318
{
319319
// ...
320+
321+
// specify one allowed type
320322
$resolver->setAllowedTypes('host', 'string');
323+
324+
// specify multiple allowed types
321325
$resolver->setAllowedTypes('port', array('null', 'int'));
326+
327+
// check all items in an array recursively for a type
328+
$resolver->setAllowedTypes('dates', 'DateTime[]');
329+
$resolver->setAllowedtypes('ports', 'int[]');
322330
}
323331
}
324332

325-
For each option, you can define either just one type or an array of acceptable
326-
types. You can pass any type for which an ``is_<type>()`` function is defined
327-
in PHP. Additionally, you may pass fully qualified class or interface names.
333+
You can pass any type for which an ``is_<type>()`` function is defined in PHP.
334+
You may also pass fully qualified class or interface names (which is checked
335+
using ``instanceof``). Additionally, you can validate all items in an array
336+
recursively by suffixing the type with ``[]``.
337+
338+
.. versionadded:: 3.4
339+
Validating types of array items recursively was introduced in Symfony 3.4.
340+
Prior to Symfony 3.4, only scalar values could be validated.
328341

329342
If you pass an invalid option now, an
330343
:class:`Symfony\\Component\\OptionsResolver\\Exception\\InvalidOptionsException`

components/phpunit_bridge.rst

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,25 @@ in the **Unsilenced** section of the deprecation report.
113113
Mark Tests as Legacy
114114
--------------------
115115

116-
Add the ``@group legacy`` annotation to a test class or method to mark it
117-
as legacy.
116+
There are three ways to mark a test as legacy:
117+
118+
* (**Recommended**) Add the ``@group legacy`` annotation to its class or method;
119+
120+
* Make its class name start with the ``Legacy`` prefix;
121+
122+
* Make its method name start with ``testLegacy*()`` instead of ``test*()``.
123+
124+
.. note::
125+
126+
If your data provider calls code that would usually trigger a deprecation,
127+
you can prefix its name with ``provideLegacy`` or ``getLegacy`` to silent
128+
these deprecations. If your data provider does not execute deprecated
129+
code, it is not required to choose a special naming just because the
130+
test being fed by the data provider is marked as legacy.
131+
132+
Also be aware that choosing one of the two legacy prefixes will not mark
133+
tests as legacy that make use of this data provider. You still have to
134+
mark them as legacy tests explicitly.
118135

119136
Configuration
120137
-------------

components/process.rst

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ You can install the component in 2 different ways:
2020
Usage
2121
-----
2222

23-
The :class:`Symfony\\Component\\Process\\Process` class allows you to execute
24-
a command in a sub-process::
23+
The :class:`Symfony\\Component\\Process\\Process` class executes a command in a
24+
sub-process, taking care of the differences between operating system and
25+
escaping arguments to prevent security issues. It replaces PHP functions like
26+
:phpfunction:`exec`, :phpfunction:`passthru`, :phpfunction:`shell_exec` and
27+
:phpfunction:`system`::
2528

2629
use Symfony\Component\Process\Process;
2730
use Symfony\Component\Process\Exception\ProcessFailedException;
@@ -36,8 +39,18 @@ a command in a sub-process::
3639

3740
echo $process->getOutput();
3841

39-
The component takes care of the subtle differences between the different platforms
40-
when executing the command.
42+
.. tip::
43+
44+
In addition to passing the command binary and its arguments as a string, you
45+
can also pass them as an array, which is useful when building a complex
46+
command programmatically::
47+
48+
// traditional string based commands
49+
$builder = new Process('ls -lsa');
50+
// same example but using an array
51+
$builder = new Process(array('ls', '-lsa'));
52+
// the array can contain any number of arguments and options
53+
$builder = new Process(array('ls', '-l', '-s', '-a'));
4154

4255
The ``getOutput()`` method always returns the whole content of the standard
4356
output of the command and ``getErrorOutput()`` the content of the error

components/using_components.rst

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,6 @@ immediately::
5656

5757
// ...
5858

59-
Using all of the Components
60-
---------------------------
61-
62-
If you want to use all of the Symfony Components, then instead of adding
63-
them one by one, you can include the ``symfony/symfony`` package:
64-
65-
.. code-block:: terminal
66-
67-
$ composer require symfony/symfony
68-
69-
This will also include the Bundle and Bridge libraries, which you may or
70-
may not actually need.
71-
7259
Now what?
7360
---------
7461

components/var_dumper.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ For example::
5050

5151
dump($someVar);
5252

53+
// dump() returns the passed value, so you can dump an object and keep using it
54+
dump($someObject)->someMethod();
55+
5356
By default, the output format and destination are selected based on your
5457
current PHP SAPI:
5558

console/verbosity.rst

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,41 @@
11
Verbosity Levels
22
================
33

4-
The console has five verbosity levels. These are defined in the
5-
:class:`Symfony\\Component\\Console\\Output\\OutputInterface`:
6-
7-
=========================================== ================================== =====================
8-
Value Meaning Console option
9-
=========================================== ================================== =====================
10-
``OutputInterface::VERBOSITY_QUIET`` Do not output any messages ``-q`` or ``--quiet``
11-
``OutputInterface::VERBOSITY_NORMAL`` The default verbosity level (none)
12-
``OutputInterface::VERBOSITY_VERBOSE`` Increased verbosity of messages ``-v``
13-
``OutputInterface::VERBOSITY_VERY_VERBOSE`` Informative non essential messages ``-vv``
14-
``OutputInterface::VERBOSITY_DEBUG`` Debug messages ``-vvv``
15-
=========================================== ================================== =====================
4+
Console commands have different verbosity levels, which determine the messages
5+
displayed in their output. By default, commands display only the most useful
6+
messages, but you can control their verbosity with the ``-q`` and ``-v`` options:
7+
8+
.. code-block:: terminal
9+
10+
# do not output any message (not even the command result messages)
11+
$ php bin/console some-command -q
12+
$ php bin/console some-command --quiet
13+
14+
# normal behavior, no option required (display only the useful messages)
15+
$ php bin/console some-command
16+
17+
# increase verbosity of messages
18+
$ php bin/console some-command -v
19+
20+
# display also the informative non essential messages
21+
$ php bin/console some-command -vv
22+
23+
# display all messages (useful to debug errors)
24+
$ php bin/console some-command -vvv
25+
26+
The verbosity level can also be controlled globally for all commands with the
27+
``SHELL_VERBOSITY`` environment variable (the ``-q`` and ``-v`` options still
28+
have more precedence over the value of ``SHELL_VERBOSITY``):
29+
30+
===================== ========================= ===========================================
31+
Console option ``SHELL_VERBOSITY`` value Equivalent PHP constant
32+
===================== ========================= ===========================================
33+
``-q`` or ``--quiet`` ``-1`` ``OutputInterface::VERBOSITY_QUIET``
34+
(none) ``0`` ``OutputInterface::VERBOSITY_NORMAL``
35+
``-v`` ``1`` ``OutputInterface::VERBOSITY_VERBOSE``
36+
``-vv`` ``2`` ``OutputInterface::VERBOSITY_VERY_VERBOSE``
37+
``-vvv`` ``3`` ``OutputInterface::VERBOSITY_DEBUG``
38+
===================== ========================= ===========================================
1639

1740
It is possible to print a message in a command for only a specific verbosity
1841
level. For example::
@@ -31,38 +54,19 @@ level. For example::
3154
'Password: '.$input->getArgument('password'),
3255
));
3356

34-
// the user class is only printed when the verbose verbosity level is used
35-
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
57+
// available methods: ->isQuiet(), ->isVerbose(), ->isVeryVerbose(), ->isDebug()
58+
if ($output->isVerbose()) {
3659
$output->writeln('User class: '.get_class($user));
3760
}
3861

39-
// alternatively you can pass the verbosity level to writeln()
62+
// alternatively you can pass the verbosity level PHP constant to writeln()
4063
$output->writeln(
4164
'Will only be printed in verbose mode or higher',
4265
OutputInterface::VERBOSITY_VERBOSE
4366
);
4467
}
4568
}
4669

47-
There are also more semantic methods you can use to test for each of the
48-
verbosity levels::
49-
50-
if ($output->isQuiet()) {
51-
// ...
52-
}
53-
54-
if ($output->isVerbose()) {
55-
// ...
56-
}
57-
58-
if ($output->isVeryVerbose()) {
59-
// ...
60-
}
61-
62-
if ($output->isDebug()) {
63-
// ...
64-
}
65-
6670
When the quiet level is used, all output is suppressed as the default
6771
:method:`Symfony\\Component\\Console\\Output\\Output::write` method returns
6872
without actually printing.

deployment.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,9 @@ as you normally do:
156156
.. caution::
157157

158158
If you get a "class not found" error during this step, you may need to
159-
run ``export SYMFONY_ENV=prod`` before running this command so that
160-
the ``post-install-cmd`` scripts run in the ``prod`` environment.
159+
  run ``export SYMFONY_ENV=prod`` (or ``export APP_ENV=prod`` if you're
160+
  using :doc:`Symfony Flex </setup/flex>`) before running this command so
161+
that the ``post-install-cmd`` scripts run in the ``prod`` environment.
161162

162163
D) Clear your Symfony Cache
163164
~~~~~~~~~~~~~~~~~~~~~~~~~~~

doctrine.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ a new method for this to your repository::
612612
*/
613613
public function findAllGreaterThanPrice($price): array
614614
{
615-
// automatically knows to selects Products
615+
// automatically knows to select Products
616616
// the "p" is an alias you'll use in the rest of the query
617617
$qb = $this->createQueryBuilder('p')
618618
->andWhere('p.price > :price')
@@ -623,7 +623,7 @@ a new method for this to your repository::
623623
return $qb->execute();
624624

625625
// to get just one result:
626-
// $product = $query->setMaxResults(1)->getOneOrNullResult();
626+
// $product = $qb->setMaxResults(1)->getOneOrNullResult();
627627
}
628628
}
629629

@@ -654,6 +654,8 @@ In addition to the query builder, you can also query with `Doctrine Query Langua
654654

655655
public function findAllGreaterThanPrice($price): array
656656
{
657+
$em = $this->getEntityManager();
658+
657659
$query = $em->createQuery(
658660
'SELECT p
659661
FROM App\Entity\Product p

doctrine/multiple_entity_managers.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ entity manager that connects to another database might handle the rest.
1616
usually required. Be sure you actually need multiple entity managers before
1717
adding in this layer of complexity.
1818

19+
.. caution::
20+
21+
Entities cannot define associations across different entity managers. If you
22+
need that, there are `several alternatives <https://stackoverflow.com/a/11494543/2804294>`_
23+
that require some custom setup.
24+
1925
The following configuration code shows how you can configure two entity managers:
2026

2127
.. configuration-block::

form/disabling_validation.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,10 @@ these cases you can set the ``validation_groups`` option to ``false``::
1818

1919
Note that when you do that, the form will still run basic integrity checks,
2020
for example whether an uploaded file was too large or whether non-existing
21-
fields were submitted. If you want to suppress validation, you can use the
22-
:ref:`POST_SUBMIT event <form-dynamic-form-modification-suppressing-form-validation>`.
21+
fields were submitted.
22+
23+
The submission of extra form fields can be controlled with the
24+
`allow_extra_fields config option`_ and the maximum upload file size should be
25+
handled via your PHP and web server configuration.
26+
27+
.. _`allow_extra_fields config option`: https://symfony.com/doc/current/reference/forms/types/form.html#allow-extra-fields

form/dynamic_form_modification.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -613,11 +613,3 @@ field according to the current selection in the ``sport`` field:
613613
The major benefit of submitting the whole form to just extract the updated
614614
``position`` field is that no additional server-side code is needed; all the
615615
code from above to generate the submitted form can be reused.
616-
617-
.. _form-dynamic-form-modification-suppressing-form-validation:
618-
619-
Suppressing Form Validation
620-
---------------------------
621-
622-
To suppress form validation, set ``validation_groups`` to ``false`` or an empty
623-
array.

0 commit comments

Comments
 (0)