Skip to content

Commit 334ee99

Browse files
committed
Readded all 4.3 features
1 parent f2e6386 commit 334ee99

File tree

9 files changed

+230
-2
lines changed

9 files changed

+230
-2
lines changed

components/console/helpers/progressbar.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,33 @@ that the progress bar display is refreshed with a 100% completion.
9595
:method:`Symfony\\Component\\Console\\Helper\\ProgressBar::display`
9696
to show the progress bar again.
9797

98+
If the progress information is stored in an iterable variable (such as an array
99+
or a PHP generator) you can use the
100+
:method:`Symfony\\Component\\Console\\Helper\\ProgressBar::iterate` method,
101+
which starts, advances and finishes the progress bar automatically::
102+
103+
use Symfony\Component\Console\Helper\ProgressBar;
104+
105+
$progressBar = new ProgressBar($output);
106+
107+
// $iterable can be for example an array ([1, 2, 3, ...]) or a generator
108+
// $iterable = function () { yield 1; yield 2; ... };
109+
foreach ($progressBar->iterate($iterable) as $value) {
110+
// ... do some work
111+
}
112+
113+
If ``$iterable = [1, 2]``, the previous code will output the following:
114+
115+
.. code-block:: terminal
116+
117+
0/2 [>---------------------------] 0%
118+
1/2 [==============>-------------] 50%
119+
2/2 [============================] 100%
120+
121+
.. versionadded:: 4.3
122+
123+
The ``iterate()`` method was introduced in Symfony 4.3.
124+
98125
Customizing the Progress Bar
99126
----------------------------
100127

components/dom_crawler.rst

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,13 @@ Access the value of the first node of the current selection::
204204
// if the node does not exist, calling to text() will result in an exception
205205
$message = $crawler->filterXPath('//body/p')->text();
206206

207+
// avoid the exception passing an argument that text() returns when node does not exist
208+
$message = $crawler->filterXPath('//body/p')->text('Default text content');
209+
210+
.. versionadded:: 4.3
211+
212+
The default argument of ``text()`` was introduced in Symfony 4.3.
213+
207214
Access the attribute value of the first node of the current selection::
208215

209216
$class = $crawler->filterXPath('//body/p')->attr('class');
@@ -212,12 +219,17 @@ Extract attribute and/or node values from the list of nodes::
212219

213220
$attributes = $crawler
214221
->filterXpath('//body/p')
215-
->extract(['_text', 'class'])
222+
->extract(['_name', '_text', 'class'])
216223
;
217224

218225
.. note::
219226

220-
Special attribute ``_text`` represents a node value.
227+
Special attribute ``_text`` represents a node value, while ``_name``
228+
represents the element name (the HTML tag name).
229+
230+
.. versionadded:: 4.3
231+
232+
The special attribute ``_name`` was introduced in Symfony 4.3.
221233

222234
Call an anonymous function on each node of the list::
223235

@@ -297,6 +309,13 @@ and :phpclass:`DOMNode` objects::
297309
// if the node does not exist, calling to html() will result in an exception
298310
$html = $crawler->html();
299311

312+
// avoid the exception passing an argument that html() returns when node does not exist
313+
$html = $crawler->html('Default <strong>HTML</strong> content');
314+
315+
.. versionadded:: 4.3
316+
317+
The default argument of ``html()`` was introduced in Symfony 4.3.
318+
300319
Expression Evaluation
301320
~~~~~~~~~~~~~~~~~~~~~
302321

configuration/external_parameters.rst

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,15 @@ Symfony provides the following env var processors:
446446
'auth' => '%env(file:AUTH_FILE)%',
447447
]);
448448
449+
``env(trim:FOO)``
450+
Trims the content of ``FOO`` env var, removing whitespaces from the beginning
451+
and end of the string. This is especially useful in combination with the
452+
``file`` processor, as it'll remove newlines at the end of a file.
453+
454+
.. versionadded:: 4.3
455+
456+
The ``trim`` processor was introduced in Symfony 4.3.
457+
449458
``env(key:FOO:BAR)``
450459
Retrieves the value associated with the key ``FOO`` from the array whose
451460
contents are stored in the ``BAR`` env var:
@@ -484,6 +493,50 @@ Symfony provides the following env var processors:
484493
$container->setParameter('env(SECRETS_FILE)', '/opt/application/.secrets.json');
485494
$container->setParameter('database_password', '%env(key:database_password:json:file:SECRETS_FILE)%');
486495
496+
``env(default:fallback_param:BAR)``
497+
Retrieves the value of the parameter ``fallback_param`` when the ``BAR`` env
498+
var is not available:
499+
500+
.. configuration-block::
501+
502+
.. code-block:: yaml
503+
504+
# config/services.yaml
505+
parameters:
506+
# if PRIVATE_KEY is not a valid file path, the content of raw_key is returned
507+
private_key: '%env(default:raw_key:file:PRIVATE_KEY)%'
508+
raw_key: '%env(PRIVATE_KEY)%'
509+
510+
.. code-block:: xml
511+
512+
<!-- config/services.xml -->
513+
<?xml version="1.0" encoding="UTF-8" ?>
514+
<container xmlns="http://symfony.com/schema/dic/services"
515+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
516+
xmlns:framework="http://symfony.com/schema/dic/symfony"
517+
xsi:schemaLocation="http://symfony.com/schema/dic/services
518+
http://symfony.com/schema/dic/services/services-1.0.xsd
519+
http://symfony.com/schema/dic/symfony
520+
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
521+
<parameters>
522+
<!-- if PRIVATE_KEY is not a valid file path, the content of raw_key is returned -->
523+
<parameter key="private_key">%env(default:raw_key:file:PRIVATE_KEY)%</parameter>
524+
<parameter key="raw_key">%env(PRIVATE_KEY)%</parameter>
525+
</parameters>
526+
</container>
527+
528+
.. code-block:: php
529+
530+
// config/services.php
531+
532+
// if PRIVATE_KEY is not a valid file path, the content of raw_key is returned
533+
$container->setParameter('private_key', '%env(default:raw_key:file:PRIVATE_KEY)%');
534+
$container->setParameter('raw_key', '%env(PRIVATE_KEY)%');
535+
536+
.. versionadded:: 4.3
537+
538+
The ``default`` processor was introduced in Symfony 4.3.
539+
487540
It is also possible to combine any number of processors:
488541

489542
.. code-block:: yaml

console/coloring.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,25 @@ You can also set these colors and options directly inside the tag name::
7474
or use the :method:`Symfony\\Component\\Console\\Formatter\\OutputFormatter::escape`
7575
method to escape all the tags included in the given string.
7676

77+
Displaying Clickable Links
78+
~~~~~~~~~~~~~~~~~~~~~~~~~~
79+
80+
.. versionadded:: 4.3
81+
The feature to display clickable links was introduced in Symfony 4.3.
82+
83+
Commands can use the special ``<href>`` tag to display links similar to the
84+
``<a>`` elements of web pages::
85+
86+
$output->writeln('<href=https://symfony.com>Symfony Homepage</>');
87+
88+
If your terminal belongs to the `list of terminal emulators that support links`_
89+
you can click on the *"Symfony Homepage"* text to open its URL in your default
90+
browser. Otherwise, you'll see *"Symfony Homepage"* as regular text and the URL
91+
will be lost.
92+
7793
.. _Cmder: http://cmder.net/
7894
.. _ConEmu: https://conemu.github.io/
7995
.. _ANSICON: https://github.com/adoxa/ansicon/releases
8096
.. _Mintty: https://mintty.github.io/
8197
.. _Hyper: https://hyper.is/
98+
.. _`list of terminal emulators that support links`: https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda

form/create_custom_field_type.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ The goal of this field was to extend the choice type to enable selection of the
9999
shipping type. This is achieved by fixing the ``choices`` to a list of available
100100
shipping options.
101101

102+
.. tip::
103+
104+
If the purpose of this new form type was to customize the rendering of some
105+
fields only, skip this step and use ``block_name`` or ``block_prefix`` options
106+
instead to :ref:`define a custom form fragment name <form-fragment-custom-naming>`.
107+
102108
.. tip::
103109

104110
Run the following command to verify that the form type was successfully

form/form_themes.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,32 @@ form. You can also define this value explicitly with the ``block_name`` option::
275275
In this example, the fragment name will be ``_product_custom_name_widget``
276276
instead of the default ``_product_name_widget``.
277277

278+
.. _form-fragment-custom-naming:
279+
280+
Custom Fragment Naming for Individual Fields
281+
............................................
282+
283+
The ``block_prefix`` option allows form fields to define their own custom
284+
fragment name. This is mostly useful to customize some instances of the same
285+
field without having to :doc:`create a custom form type </form/create_custom_field_type>`::
286+
287+
use Symfony\Component\Form\Extension\Core\Type\TextType;
288+
use Symfony\Component\Form\FormBuilderInterface;
289+
290+
public function buildForm(FormBuilderInterface $builder, array $options)
291+
{
292+
$builder->add('name', TextType::class, array(
293+
'block_prefix' => 'wrapped_text',
294+
));
295+
}
296+
297+
.. versionadded:: 4.3
298+
299+
The ``block_prefix`` option was introduced in Symfony 4.3.
300+
301+
Now you can use ``wrapped_text_row``, ``wrapped_text_widget``, etc. as the block
302+
names.
303+
278304
.. _form-custom-prototype:
279305

280306
Fragment Naming for Collections

routing.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,14 @@ So how can you make ``blog_list`` once again match when the user visits
511511
Now, when the user visits ``/blog``, the ``blog_list`` route will match and
512512
``$page`` will default to a value of ``1``.
513513

514+
If you want to always include some default value in the generated URL (for
515+
example to force the generation of ``/blog/1`` instead of ``/blog`` in the
516+
previous example) add the ``!`` character before the placeholder name: ``/blog/{!page}``
517+
518+
.. versionadded:: 4.3
519+
The feature to force the inclusion of default values in generated URLs was
520+
introduced in Symfony 4.3.
521+
514522
As it happens with requirements, default values can also be inlined in each
515523
placeholder using the syntax ``{placeholder_name?default_value}``. This feature
516524
is compatible with inlined requirements, so you can inline both in a single

security/csrf.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ this can be customized on a form-by-form basis::
108108
// ...
109109
}
110110

111+
You can also customize the rendering of the CSRF form field creating a custom
112+
:doc:`form theme </form/form_themes>` and using ``csrf_token`` as the prefix of
113+
the field (e.g. define ``{% block csrf_token_widget %} ... {% endblock %}`` to
114+
customize the entire form field contents).
115+
116+
.. versionadded:: 4.3
117+
118+
The ``csrf_token`` form field prefix was introduced in Symfony 4.3.
119+
111120
CSRF Protection in Login Forms
112121
------------------------------
113122

service_container/alias_private.rst

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,69 @@ This means that when using the container directly, you can access the
146146
# ...
147147
app.mailer: '@App\Mail\PhpMailer'
148148
149+
Deprecating Service Aliases
150+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
151+
152+
If you decide to deprecate the use of a service alias (because it is outdated
153+
or you decided not to maintain it anymore), you can deprecate its definition:
154+
155+
.. configuration-block::
156+
157+
.. code-block:: yaml
158+
159+
app.mailer:
160+
alias: '@AppBundle\Mail\PhpMailer'
161+
162+
# this will display a generic deprecation message...
163+
deprecated: true
164+
165+
# ...but you can also define a custom deprecation message
166+
deprecated: 'The "%alias_id%" alias is deprecated. Don\'t use it anymore.'
167+
168+
.. code-block:: xml
169+
170+
<?xml version="1.0" encoding="UTF-8" ?>
171+
<container xmlns="http://symfony.com/schema/dic/services"
172+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-Instance"
173+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
174+
175+
<services>
176+
<service id="app.mailer" alias="App\Mail\PhpMailer">
177+
<!-- this will display a generic deprecation message... -->
178+
<deprecated />
179+
180+
<!-- ...but you can also define a custom deprecation message -->
181+
<deprecated>The "%alias_id%" service alias is deprecated. Don't use it anymore.</deprecated>
182+
</service>
183+
</services>
184+
</container>
185+
186+
.. code-block:: php
187+
188+
$container
189+
->setAlias('app.mailer', 'App\Mail\PhpMailer')
190+
191+
// this will display a generic deprecation message...
192+
->setDeprecated(true)
193+
194+
// ...but you can also define a custom deprecation message
195+
->setDeprecated(
196+
true,
197+
'The "%alias_id%" service alias is deprecated. Don\'t use it anymore.'
198+
)
199+
;
200+
201+
Now, every time this service alias is used, a deprecation warning is triggered,
202+
advising you to stop or to change your uses of that alias.
203+
204+
The message is actually a message template, which replaces occurrences of the
205+
``%alias_id%`` placeholder by the service alias id. You **must** have at least
206+
one occurrence of the ``%alias_id%`` placeholder in your template.
207+
208+
.. versionadded:: 4.3
209+
210+
The ``deprecated`` option for service aliases was introduced in Symfony 4.3.
211+
149212
Anonymous Services
150213
------------------
151214

0 commit comments

Comments
 (0)