Skip to content

Commit 9f39fd7

Browse files
committed
Merge branch '4.1'
* 4.1: Minor typo fix on messenger xml config tweaked documentation about the profiler Change link to actual demo repo Remove unnecessary semicolons Change to short php echo tags [Encore] Make title in FAQ more clear [Forms] Update Bootstrap 4's documentation links to 4.1 Mentioned how to redirect and maintain the query string Remove obsolete reference Minimalist default PSR-3 logger Fix #10250 - remove manual class discriminator configuration Use cross references for internal links Added a note on forms validation Mentioned the <optgroup> html tag explicitly Update redis_adapter.rst
2 parents bc0c51a + e7946d9 commit 9f39fd7

29 files changed

+168
-161
lines changed

best_practices/forms.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,35 @@ view layer:
137137
<input type="submit" class="btn" value="Create" />
138138
{{ form_end(form) }}
139139

140+
Validation
141+
----------
142+
143+
The :ref:`constraints <reference-form-option-constraints>` option allows you to
144+
attach :doc:`validation constraints </reference/constraints>` to any form field.
145+
However, doing that prevents the validation from being reused in other forms or
146+
other places where the mapped object is used.
147+
148+
.. best-practice::
149+
150+
Do not define your validation constraints in the form but on the object the
151+
form is mapped to.
152+
153+
For example, to validate that the title of the post edited with a form is not
154+
blank, add the following in the ``Post`` object::
155+
156+
// src/Entity/Post.php
157+
158+
// ...
159+
use Symfony\Component\Validator\Constraints as Assert;
160+
161+
class Post
162+
{
163+
/**
164+
* @Assert\NotBlank()
165+
*/
166+
public $title;
167+
}
168+
140169
Rendering the Form
141170
------------------
142171

components/cache/adapters/redis_adapter.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ array of ``key => value`` pairs representing option names and their respective v
9292
$client = RedisAdapter::createConnection(
9393

9494
// provide a string dsn
95-
'redis://localhost:6739',
95+
'redis://localhost:6379',
9696

9797
// associative array of configuration options
9898
array(

components/process.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ instead::
322322
use Symfony\Component\Process\PhpProcess;
323323

324324
$process = new PhpProcess(<<<EOF
325-
<?php echo 'Hello World'; ?>
325+
<?= 'Hello World' ?>
326326
EOF
327327
);
328328
$process->run();

components/serializer.rst

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ Converting Property Names when Serializing and Deserializing
424424
Sometimes serialized attributes must be named differently than properties
425425
or getter/setter methods of PHP classes.
426426

427-
The Serializer Component provides a handy way to translate or map PHP field
427+
The Serializer component provides a handy way to translate or map PHP field
428428
names to serialized names: The Name Converter System.
429429

430430
Given you have the following object::
@@ -594,7 +594,7 @@ There are several types of normalizers available:
594594
``firstName``).
595595

596596
The ``ObjectNormalizer`` is the most powerful normalizer. It is configured by
597-
default when using the Symfony Standard Edition with the serializer enabled.
597+
default in Symfony applications with the Serializer component enabled.
598598

599599
:class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer`
600600
This normalizer reads the content of the class by calling the "getters"
@@ -684,8 +684,8 @@ The Serializer component provides several built-in encoders:
684684
:class:`Symfony\\Component\\Serializer\\Encoder\\CsvEncoder`
685685
This encoder encodes and decodes data in CSV_.
686686

687-
All these encoders are enabled by default when using the Symfony Standard Edition
688-
with the serializer enabled.
687+
All these encoders are enabled by default when using the Serializer component
688+
in a Symfony application.
689689

690690
The ``JsonEncoder``
691691
~~~~~~~~~~~~~~~~~~~
@@ -925,8 +925,8 @@ Here, we set it to 2 for the ``$child`` property:
925925
</serializer>
926926
927927
The metadata loader corresponding to the chosen format must be configured in
928-
order to use this feature. It is done automatically when using the Symfony
929-
Standard Edition. When using the standalone component, refer to
928+
order to use this feature. It is done automatically when using the Serializer component
929+
in a Symfony application. When using the standalone component, refer to
930930
:ref:`the groups documentation <component-serializer-attributes-groups>` to
931931
learn how to do that.
932932

@@ -1160,11 +1160,11 @@ context option::
11601160
Recursive Denormalization and Type Safety
11611161
-----------------------------------------
11621162

1163-
The Serializer Component can use the :doc:`PropertyInfo Component </components/property_info>` to denormalize
1163+
The Serializer component can use the :doc:`PropertyInfo Component </components/property_info>` to denormalize
11641164
complex types (objects). The type of the class' property will be guessed using the provided
11651165
extractor and used to recursively denormalize the inner data.
11661166

1167-
When using the Symfony Standard Edition, all normalizers are automatically configured to use the registered extractors.
1167+
When using this component in a Symfony application, all normalizers are automatically configured to use the registered extractors.
11681168
When using the component standalone, an implementation of :class:`Symfony\\Component\\PropertyInfo\\PropertyTypeExtractorInterface`,
11691169
(usually an instance of :class:`Symfony\\Component\\PropertyInfo\\PropertyInfoExtractor`) must be passed as the 4th
11701170
parameter of the ``ObjectNormalizer``::
@@ -1239,9 +1239,14 @@ between the possible objects. In practice, when using the Serializer component,
12391239
pass a :class:`Symfony\\Component\\Serializer\\Mapping\\ClassDiscriminatorResolverInterface`
12401240
implementation to the :class:`Symfony\\Component\\Serializer\\Normalizer\\ObjectNormalizer`.
12411241

1242-
Consider an application that defines an abstract ``CodeRepository`` class
1243-
extended by ``GitHubCodeRepository`` and ``BitBucketCodeRepository`` classes.
1244-
This example shows how to serialize and deserialize those objects::
1242+
The Serializer component provides an implementation of ``ClassDiscriminatorResolverInterface``
1243+
called :class:`Symfony\\Component\\Serializer\\Mapping\\ClassDiscriminatorFromClassMetadata`
1244+
which uses the class metadata factory and a mapping configuration to serialize
1245+
and deserialize objects of the correct class.
1246+
1247+
When using this component inside a Symfony application and the class metadata factory is enabled
1248+
as explained in the :ref:`Attributes Groups section <component-serializer-attributes-groups>`,
1249+
this is already set up and you only need to provide the configuration. Otherwise::
12451250

12461251
// ...
12471252
use Symfony\Component\Serializer\Encoder\JsonEncoder;
@@ -1253,25 +1258,15 @@ This example shows how to serialize and deserialize those objects::
12531258
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
12541259

12551260
$discriminator = new ClassDiscriminatorFromClassMetadata($classMetadataFactory);
1256-
$discriminator->addClassMapping(CodeRepository::class, new ClassDiscriminatorMapping('type', [
1257-
'github' => GitHubCodeRepository::class,
1258-
'bitbucket' => BitBucketCodeRepository::class,
1259-
]));
12601261

12611262
$serializer = new Serializer(
12621263
array(new ObjectNormalizer($classMetadataFactory, null, null, null, $discriminator)),
12631264
array('json' => new JsonEncoder())
12641265
);
12651266

1266-
$serialized = $serializer->serialize(new GitHubCodeRepository());
1267-
// {"type": "github"}
1268-
1269-
$repository = $serializer->deserialize($serialized, CodeRepository::class, 'json');
1270-
// instanceof GitHubCodeRepository
1271-
1272-
If the class metadata factory is enabled as explained in the
1273-
:ref:`Attributes Groups section <component-serializer-attributes-groups>`, you
1274-
can use this simpler configuration:
1267+
Now configure your discriminator class mapping. Consider an application that
1268+
defines an abstract ``CodeRepository`` class extended by ``GitHubCodeRepository``
1269+
and ``BitBucketCodeRepository`` classes:
12751270

12761271
.. configuration-block::
12771272

@@ -1317,6 +1312,14 @@ can use this simpler configuration:
13171312
</class>
13181313
</serializer>
13191314
1315+
Once configured, the serializer uses the mapping to pick the correct class::
1316+
1317+
$serialized = $serializer->serialize(new GitHubCodeRepository());
1318+
// {"type": "github"}
1319+
1320+
$repository = $serializer->deserialize($serialized, CodeRepository::class, 'json');
1321+
// instanceof GitHubCodeRepository
1322+
13201323
Performance
13211324
-----------
13221325

@@ -1339,7 +1342,7 @@ and return ``true`` when
13391342
is called.
13401343

13411344
.. note::
1342-
1345+
13431346
All built-in :ref:`normalizers and denormalizers <component-serializer-normalizers>`
13441347
as well the ones included in `API Platform`_ natively implement this interface.
13451348

@@ -1359,7 +1362,7 @@ Learn more
13591362

13601363
.. seealso::
13611364

1362-
A popular alternative to the Symfony Serializer Component is the third-party
1365+
A popular alternative to the Symfony Serializer component is the third-party
13631366
library, `JMS serializer`_ (versions before ``v1.12.0`` were released under
13641367
the Apache license, so incompatible with GPLv2 projects).
13651368

components/templating.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ which uses the template reference to actually find and load the template::
5454
.. code-block:: html+php
5555

5656
<!-- views/hello.php -->
57-
Hello, <?php echo $firstname ?>!
57+
Hello, <?= $firstname ?>!
5858

5959
The :method:`Symfony\\Component\\Templating\\PhpEngine::render` method parses
6060
the ``views/hello.php`` file and returns the output text. The second argument
@@ -85,7 +85,7 @@ to render the template originally) inside the template to render another templat
8585

8686
<?php $names = array('Fabien', ...) ?>
8787
<?php foreach ($names as $name) : ?>
88-
<?php echo $view->render('hello.php', array('firstname' => $name)) ?>
88+
<?= $view->render('hello.php', array('firstname' => $name)) ?>
8989
<?php endforeach ?>
9090

9191
Global Variables
@@ -103,7 +103,7 @@ In a template:
103103

104104
.. code-block:: html+php
105105

106-
<p>The google tracking code is: <?php echo $ga_tracking ?></p>
106+
<p>The google tracking code is: <?= $ga_tracking ?></p>
107107

108108
.. caution::
109109

@@ -123,13 +123,13 @@ JavaScript code isn't written out to your page. This will prevent things like
123123
XSS attacks. To do this, use the
124124
:method:`Symfony\\Component\\Templating\\PhpEngine::escape` method::
125125

126-
<?php echo $view->escape($firstname) ?>
126+
<?= $view->escape($firstname) ?>
127127

128128
By default, the ``escape()`` method assumes that the variable is outputted
129129
within an HTML context. The second argument lets you change the context. For
130130
example, to output something inside JavaScript, use the ``js`` context::
131131

132-
<?php echo $view->escape($var, 'js') ?>
132+
<?= $view->escape($var, 'js') ?>
133133

134134
The component comes with an HTML and JS escaper. You can register your own
135135
escaper using the

components/templating/slotshelper.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ set in a slot is in the ``_content`` slot.
6767
<?php $view['slots']->set('title', $page->title) ?>
6868

6969
<h1>
70-
<?php echo $page->title ?>
70+
<?= $page->title ?>
7171
</h1>
7272
<p>
73-
<?php echo $page->body ?>
73+
<?= $page->body ?>
7474
</p>
7575

7676
.. note::

controller.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ and ``redirect()`` methods::
148148
// redirect to a route with parameters
149149
return $this->redirectToRoute('app_lucky_number', array('max' => 10));
150150

151+
// redirects to a route and mantains the original query string parameters
152+
return $this->redirectToRoute('blog_show', $request->query->all());
153+
151154
// redirects externally
152155
return $this->redirect('http://symfony.com/doc');
153156
}

create_framework/front_controller.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ And the ``hello.php`` script can now be converted to a template::
190190
<!-- example.com/src/pages/hello.php -->
191191
<?php $name = $request->get('name', 'World') ?>
192192

193-
Hello <?php echo htmlspecialchars($name, ENT_QUOTES, 'UTF-8') ?>
193+
Hello <?= htmlspecialchars($name, ENT_QUOTES, 'UTF-8') ?>
194194

195195
We have the first version of our framework::
196196

create_framework/routing.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ As we now extract the request query parameters, simplify the ``hello.php``
3333
template as follows::
3434

3535
<!-- example.com/src/pages/hello.php -->
36-
Hello <?php echo htmlspecialchars(isset($name) ? $name : 'World', ENT_QUOTES, 'UTF-8') ?>
36+
Hello <?= htmlspecialchars(isset($name) ? $name : 'World', ENT_QUOTES, 'UTF-8') ?>
3737

3838
Now, we are in good shape to add new features.
3939

@@ -166,7 +166,7 @@ There are a few new things in the code:
166166
* Request attributes are extracted to keep our templates simple::
167167

168168
<!-- example.com/src/pages/hello.php -->
169-
Hello <?php echo htmlspecialchars($name, ENT_QUOTES, 'UTF-8') ?>
169+
Hello <?= htmlspecialchars($name, ENT_QUOTES, 'UTF-8') ?>
170170

171171
* Route configuration has been moved to its own file::
172172

form/bootstrap4.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ template which other templates extend from):
1212

1313
{# beware that the blocks in your template may be named different #}
1414
{% block head_css %}
15-
<!-- Copy CSS from https://getbootstrap.com/docs/4.0/getting-started/introduction/#css -->
15+
<!-- Copy CSS from https://getbootstrap.com/docs/4.1/getting-started/introduction/#css -->
1616
{% endblock %}
1717
{% block head_js %}
18-
<!-- Copy JavaScript from https://getbootstrap.com/docs/4.0/getting-started/introduction/#js -->
18+
<!-- Copy JavaScript from https://getbootstrap.com/docs/4.1/getting-started/introduction/#js -->
1919
{% endblock %}
2020

2121
If your application uses modern front-end practices, it's better to use
@@ -111,6 +111,6 @@ Form errors are rendered **inside** the ``<label>`` element to make sure there
111111
is a strong connection between the error and its ``<input>``, as required by the
112112
`WCAG 2.0 standard`_.
113113

114-
.. _`their documentation`: https://getbootstrap.com/docs/4.0/
114+
.. _`their documentation`: https://getbootstrap.com/docs/4.1/
115115
.. _`WCAG 2.0 standard`: https://www.w3.org/TR/WCAG20/
116-
.. _`custom forms`: https://getbootstrap.com/docs/4.0/components/forms/#custom-forms
116+
.. _`custom forms`: https://getbootstrap.com/docs/4.1/components/forms/#custom-forms

form/form_customization.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,6 @@ more details about this concept in Twig, see :ref:`twig-reference-form-variables
857857
.. _`bootstrap_4_layout.html.twig`: https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_layout.html.twig
858858
.. _`bootstrap_4_horizontal_layout.html.twig`: https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_4_horizontal_layout.html.twig
859859
.. _`Bootstrap 3 CSS framework`: https://getbootstrap.com/docs/3.3/
860-
.. _`Bootstrap 4 CSS framework`: https://getbootstrap.com/docs/4.0/
860+
.. _`Bootstrap 4 CSS framework`: https://getbootstrap.com/docs/4.1/
861861
.. _`foundation_5_layout.html.twig`: https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/foundation_5_layout.html.twig
862862
.. _`Foundation CSS framework`: http://foundation.zurb.com/

frontend/encore/faq.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ How do I deploy my Encore Assets?
88

99
There are two important things to remember when deploying your assets.
1010

11-
**1) Run ``encore production``**
11+
**1) Compile assets for production**
1212

1313
Optimize your assets for production by running:
1414

0 commit comments

Comments
 (0)