Skip to content

Commit dfe4ff0

Browse files
committed
Merge branch '4.1'
* 4.1: (28 commits) Removed an outdated section Reorganized the contents of the new output sections Add documentation about manipulating console output Update deployment.rst Update the security reference because user providers are no longer mandatory Update typescript.rst Corrected titles of test tools and use safe url for phpspec Add 2 solutions for the 'option with optional argument' problem Simplify the explanation leaving just one solution Add 2 solutions for the 'option with optional argument' problem ocramius/proxy-manager isn't needed anymore Fix a typo in the HTML5 date form property Add URL-encoding notice ...
2 parents c98569d + a0c278a commit dfe4ff0

File tree

17 files changed

+315
-60
lines changed

17 files changed

+315
-60
lines changed

best_practices/tests.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Unit Tests
1313
Unit tests are used to test your "business logic", which should live in classes
1414
that are independent of Symfony. For that reason, Symfony doesn't really
1515
have an opinion on what tools you use for unit testing. However, the most
16-
popular tools are `PhpUnit`_ and `PhpSpec`_.
16+
popular tools are `PHPUnit`_ and `PHPSpec`_.
1717

1818
Functional Tests
1919
----------------
@@ -114,8 +114,8 @@ Learn More about Functional Tests
114114
Consider using the `HautelookAliceBundle`_ to generate real-looking data for
115115
your test fixtures using `Faker`_ and `Alice`_.
116116

117-
.. _`PhpUnit`: https://phpunit.de/
118-
.. _`PhpSpec`: http://www.phpspec.net/
117+
.. _`PHPUnit`: https://phpunit.de/
118+
.. _`PHPSpec`: https://www.phpspec.net/
119119
.. _`smoke testing`: https://en.wikipedia.org/wiki/Smoke_testing_(software)
120120
.. _`Mink`: http://mink.behat.org
121121
.. _`HautelookAliceBundle`: https://github.com/hautelook/AliceBundle

components/console/helpers/progressbar.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,3 +342,43 @@ of the custom placeholders::
342342
$progressBar->advance();
343343
// 2/100 -- Importing invoices... (client-001/invoices.xml)
344344
}
345+
346+
.. _console-multiple-progress-bars:
347+
348+
Displaying Multiple Progress Bars
349+
---------------------------------
350+
351+
.. versionadded:: 4.1
352+
The feature to display multiple progress bars using output sections was
353+
introduced in Symfony 4.1.
354+
355+
When using :ref:`Console output sections <console-output-sections>` it's
356+
possible to display multiple progress bars at the same time and change their
357+
progress independently::
358+
359+
$section1 = $output->section();
360+
$section2 = $output->section();
361+
362+
$progress1 = new ProgressBar($section1);
363+
$progress2 = new ProgressBar($section2);
364+
365+
$progress1->start(100);
366+
$progress2->start(100);
367+
368+
$i = 0;
369+
while (++$i < 100) {
370+
$progress1->advance();
371+
372+
if ($i % 2 === 0) {
373+
$progress2->advance(4);
374+
}
375+
376+
usleep(50000);
377+
}
378+
379+
After a couple of iterations, the output in the terminal will look like this:
380+
381+
.. code-block:: text
382+
383+
34/100 [=========>------------------] 34%
384+
68/100 [===================>--------] 68%

components/console/helpers/table.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,47 @@ This outputs:
324324
325325
You can use the ``colspan`` and ``rowspan`` options at the same time which allows
326326
you to create any table layout you may wish.
327+
328+
.. _console-modify-rendered-tables:
329+
330+
Modifying Rendered Tables
331+
-------------------------
332+
333+
.. versionadded:: 4.1
334+
The feature to modify rendered tables was introduced in Symfony 4.1.
335+
336+
The ``render()`` method requires passing the entire table contents. However,
337+
sometimes that information is not available beforehand because it's generated
338+
dynamically. In those cases, use the
339+
:method:`Symfony\\Component\\Console\\Helper\\Table::appendRow` method, which
340+
takes the same arguments as the ``addRow()`` method, to add rows at the bottom
341+
of an already rendered table.
342+
343+
The only requirement to append rows is that the table must be rendered inside a
344+
:ref:`Console output section <console-output-sections>`::
345+
346+
use Symfony\Component\Console\Helper\Table;
347+
// ...
348+
349+
class SomeCommand extends Command
350+
{
351+
public function execute(InputInterface $input, OutputInterface $output)
352+
{
353+
$section = $output->section();
354+
$table = new Table($section);
355+
356+
$table->addRow(['Row 1']);
357+
$table->render();
358+
359+
$table->addRow(['Row 2']);
360+
}
361+
}
362+
363+
This will display the following table in the terminal:
364+
365+
.. code-block:: terminal
366+
367+
+-------+
368+
| Row 1 |
369+
| Row 2 |
370+
+-------+

console.rst

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,13 @@ After configuring and registering the command, you can execute it in the termina
8787
$ php bin/console app:create-user
8888
8989
As you might expect, this command will do nothing as you didn't write any logic
90-
yet. Add your own logic inside the ``execute()`` method, which has access to the
91-
input stream (e.g. options and arguments) and the output stream (to write
92-
messages to the console)::
90+
yet. Add your own logic inside the ``execute()`` method.
91+
92+
Console Output
93+
--------------
94+
95+
The ``execute()`` method has access to the output stream to write messages to
96+
the console::
9397

9498
// ...
9599
protected function execute(InputInterface $input, OutputInterface $output)
@@ -128,6 +132,57 @@ Now, try executing the command:
128132
Whoa!
129133
You are about to create a user.
130134
135+
.. _console-output-sections:
136+
137+
Output Sections
138+
~~~~~~~~~~~~~~~
139+
140+
.. versionadded:: 4.1
141+
Output sections were introduced in Symfony 4.1.
142+
143+
The regular console output can be divided into multiple independent regions
144+
called "output sections". Create one or more of these sections when you need to
145+
clear and overwrite the output information.
146+
147+
Sections are created with the
148+
:method:`Symfony\\Component\\Console\\Output\\ConsoleOutput::section` method,
149+
which returns an instance of
150+
:class:`Symfony\\Component\\Console\\Output\\ConsoleSectionOutput`::
151+
152+
class MyCommand extends Command
153+
{
154+
protected function execute(InputInterface $input, OutputInterface $output)
155+
{
156+
$section1 = $output->section();
157+
$section2 = $output->section();
158+
$section1->writeln('Hello');
159+
$section2->writeln('World!');
160+
// Output displays "Hello\nWorld!\n"
161+
162+
// overwrite() replaces all the existing section contents with the given content
163+
$section1->overwrite('Goodbye');
164+
// Output now displays "Goodbye\nWorld!\n"
165+
166+
// clear() deletes all the section contents...
167+
$section2->clear();
168+
// Output now displays "Goodbye\n"
169+
170+
// ...but you can also delete a given number of lines
171+
// (this example deletes the last two lines of the section)
172+
$section1->clear(2);
173+
// Output is now completely empty!
174+
}
175+
}
176+
177+
.. note::
178+
179+
A new line is appended automatically when displaying information in a section.
180+
181+
Output sections let you manipulate the Console output in advanced ways, such as
182+
:ref:`displaying multiple progress bars <console-multiple-progress-bars>` which
183+
are updated independently and :ref:`appending rows to tables <console-modify-rendered-tables>`
184+
that have already been rendered.
185+
131186
Console Input
132187
-------------
133188

console/input.rst

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ values after a white space or an ``=`` sign (e.g. ``--iterations 5`` or
179179
``--iterations=5``), but short options can only use white spaces or no
180180
separation at all (e.g. ``-i 5`` or ``-i5``).
181181

182+
.. caution::
183+
184+
While it is possible to separate an option from its value with a white space,
185+
using this form leads to an ambiguity should the option appear before the
186+
command name. For example, ``php app/console --iterations 5 app:greet Fabien``
187+
is ambiguous; Symfony would interpret ``5`` as the command name. To avoid
188+
this situation, always place options after the command name, or avoid using
189+
a space to separate the option name from its value.
190+
182191
There are four option variants you can use:
183192

184193
``InputOption::VALUE_IS_ARRAY``
@@ -209,21 +218,53 @@ You can combine ``VALUE_IS_ARRAY`` with ``VALUE_REQUIRED`` or
209218
array('blue', 'red')
210219
);
211220

212-
.. tip::
221+
Options with optional arguments
222+
-------------------------------
223+
224+
There is nothing forbidding you to create a command with an option that
225+
optionally accepts a value, but it's a bit tricky. Consider this example::
226+
227+
// ...
228+
use Symfony\Component\Console\Input\InputOption;
229+
230+
$this
231+
// ...
232+
->addOption(
233+
'yell',
234+
null,
235+
InputOption::VALUE_OPTIONAL,
236+
'Should I yell while greeting?'
237+
);
238+
239+
This option can be used in 3 ways: ``--yell``, ``yell=louder``, and not passing
240+
the option at all. However, it's hard to distinguish between passing the option
241+
without a value (``greet --yell``) and not passing the option (``greet``).
242+
243+
To solve this issue, you have to set the option's default value to ``false``::
244+
245+
// ...
246+
use Symfony\Component\Console\Input\InputOption;
247+
248+
$this
249+
// ...
250+
->addOption(
251+
'yell',
252+
null,
253+
InputOption::VALUE_OPTIONAL,
254+
'Should I yell while greeting?',
255+
false // this is the new default value, instead of null
256+
);
213257

214-
There is nothing forbidding you to create a command with an option that
215-
optionally accepts a value. However, there is no way you can distinguish
216-
when the option was used without a value (``command --language``) or when
217-
it wasn't used at all (``command``). In both cases, the value retrieved for
218-
the option will be ``null``.
258+
Now check the value of the option and keep in mind that ``false !== null``::
259+
260+
$optionValue = $input->getOptions('yell');
261+
$yell = ($optionValue !== false);
262+
$yellLouder = ($optionValue === 'louder');
219263

220264
.. caution::
221265

222-
While it is possible to separate an option from its value with a white space,
223-
using this form leads to an ambiguity should the option appear before the
224-
command name. For example, ``php bin/console --iterations 5 app:greet Fabien``
225-
is ambiguous; Symfony would interpret ``5`` as the command name. To avoid
226-
this situation, always place options after the command name, or avoid using
227-
a space to separate the option name from its value.
266+
Due to a PHP limitation, passing an empty string is indistinguishable from
267+
not passing any value at all. In ``command --prefix`` and ``command --prefix=''``
268+
cases, the value of the ``prefix`` option will be ``null``.
228269

229270
.. _`docopt standard`: http://docopt.org/

contributing/community/releases.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ Version Feature Freeze Release End of Maintenance End of Life
122122
`2.6`_ 09/2014 11/2014 07/2015 (8 months) 01/2016
123123
`2.7`_ (LTS) 03/2015 05/2015 05/2018 (36 months) 05/2019
124124
`2.8`_ (LTS) 09/2015 11/2015 11/2018 (36 months [2]_) 11/2019
125-
`3.0`_ 09/2015 11/2015 07/2016 (8 months) [3]_) 01/2017
125+
`3.0`_ 09/2015 11/2015 07/2016 (8 months [3]_) 01/2017
126126
`3.1`_ 03/2016 05/2016 01/2017 (8 months) 07/2017
127127
`3.2`_ 09/2016 11/2016 07/2017 (8 months) 01/2018
128128
`3.3`_ 03/2017 05/2017 01/2018 (8 months) 07/2018
@@ -194,7 +194,7 @@ version is published every two years and there is a year to upgrade.
194194

195195
.. _Semantic Versioning: https://semver.org/
196196
.. _Git repository: https://github.com/symfony/symfony
197-
.. _SensioLabs: http://sensiolabs.com/
197+
.. _SensioLabs: https://sensiolabs.com/
198198
.. _roadmap notification: https://symfony.com/roadmap
199199
.. _extended to September 2014: https://symfony.com/blog/extended-maintenance-for-symfony-2-4
200200
.. _timeline calculator: https://symfony.com/roadmap#checker

deployment.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,8 @@ you'll need to do:
116116
A) Check Requirements
117117
~~~~~~~~~~~~~~~~~~~~~
118118

119-
Check if your server meets the requirements by running:
120-
121-
.. code-block:: terminal
122-
123-
$ php bin/symfony_requirements
119+
Use the :doc:`Symfony Requirements Checker </reference/requirements>` to check
120+
if your server meets the technical requirements to run Symfony applications.
124121

125122
.. _b-configure-your-app-config-parameters-yml-file:
126123

email.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ environment variable in the ``.env`` file:
3737
# use this to disable email delivery
3838
MAILER_URL=null://localhost
3939
40-
# use this to configure a traditional SMTP server
40+
# use this to configure a traditional SMTP server (make sure to URL-encode the
41+
# values of the username and password if they contain non-alphanumeric characters
42+
# such as '+', '@', ':' and '*', which are reserved in URLs)
4143
MAILER_URL=smtp://localhost:25?encryption=ssl&auth_mode=login&username=&password=
4244
4345
Refer to the :doc:`SwiftMailer configuration reference </reference/configuration/swiftmailer>`

frontend/encore/typescript.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ also configure the `ts-loader options`_ via a callback:
2828
2929
.enableTypeScriptLoader(function (typeScriptConfigOptions) {
3030
typeScriptConfigOptions.transpileOnly = true;
31-
typeScriptConfigOptions.configFileName = '/path/to/tsconfig.json';
31+
typeScriptConfigOptions.configFile = '/path/to/tsconfig.json';
3232
});
3333
3434
If React assets are enabled (``.enableReactPreset()``), any ``.tsx`` file will be

messenger.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ factories. Using them requires a two-step configuration based on Symfony's
623623
arguments: ['@doctrine']
624624
625625
# Step 2: an abstract definition that will call the factory with default
626-
# arguments or the one provided in the middleware config
626+
# arguments or the ones provided in the middleware config
627627
messenger.middleware.doctrine_transaction_middleware:
628628
class: Symfony\Bridge\Doctrine\Messenger\DoctrineTransactionMiddleware
629629
factory: ['@doctrine.orm.messenger.middleware_factory.transaction', 'createMiddleware']
@@ -650,9 +650,9 @@ Then you can reference and configure the
650650
buses:
651651
command_bus:
652652
middleware:
653-
# Using defaults:
653+
# Using defaults
654654
- doctrine_transaction_middleware
655-
# Using another entity manager:
655+
# Using another entity manager
656656
- doctrine_transaction_middleware: ['custom']
657657
658658
.. code-block:: xml
@@ -669,7 +669,7 @@ Then you can reference and configure the
669669
<framework:config>
670670
<framework:messenger>
671671
<framework:bus name="command_bus">
672-
<!-- Using defaults: -->
672+
<!-- Using defaults -->
673673
<framework:middleware id="doctrine_transaction_middleware" />
674674
<!-- Using another entity manager -->
675675
<framework:middleware id="doctrine_transaction_middleware">
@@ -688,7 +688,7 @@ Then you can reference and configure the
688688
'buses' => array(
689689
'command_bus' => array(
690690
'middleware' => array(
691-
// Using defaults:
691+
// Using defaults
692692
'doctrine_transaction_middleware',
693693
// Using another entity manager
694694
array('id' => 'doctrine_transaction_middleware', 'arguments' => array('custom')),

reference/configuration/security.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Each part will be explained in the next section.
7272
time_cost: 2 # Number of iterations
7373
threads: 2 # Number of parallel threads
7474
75-
providers: # Required
75+
providers:
7676
# Examples:
7777
my_in_memory_provider:
7878
memory:
@@ -301,6 +301,9 @@ Each part will be explained in the next section.
301301
ROLE_ADMIN: [ROLE_ORGANIZER, ROLE_USER]
302302
ROLE_SUPERADMIN: [ROLE_ADMIN]
303303
304+
.. versionadded:: 4.1
305+
The ``providers`` option is optional starting from Symfony 4.1.
306+
304307
.. _reference-security-firewall-form-login:
305308

306309
Form Login Configuration

reference/forms/types/options/html5.rst.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ html5
66
If this is set to ``true`` (the default), it'll use the HTML5 type (date, time
77
or datetime) to render the field. When set to ``false``, it'll use the text type.
88

9-
This is useful when you want to use a custom JavaScript datapicker, which
9+
This is useful when you want to use a custom JavaScript datepicker, which
1010
often requires a text type instead of an HTML5 type.

0 commit comments

Comments
 (0)