10000 Merge branch '4.0' · symfony/symfony-docs@8a83d17 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8a83d17

Browse files
committed
Merge branch '4.0'
* 4.0: (21 commits) 9677 price is an integer Update serializer.rst Tweak wording in Upgrading a Patch Version Reword the explanation about HTTP exceptions Fix controller references in ESI docs added documentation for author tag management be more clear about child form to be themed FIX : accessing global variable tokenStorage Wrong attribute serializer xml fix FormError access in Twig template Update the dynamic form article to use modern Symfony practices class attribute still needed in some cases Be consistent how we write "core team" add missing redirection map entry Added a note about using the security checker independently Use the default article title Use "children" property instead of "child" Update web_server_configuration.rst Encore.configureUrlLoader() documentation ...
2 parents ece5ef6 + 1bfa4cf commit 8a83d17

19 files changed

+121
-63
lines changed

_build/redirection_map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@
379379
/reference/configuration/assetic /frontend/assetic
380380
/security/target_path /security
381381
/security/csrf_in_login_form /security/csrf
382+
/service_container/service_locators /service_container/service_subscribers_locators
382383
/service_container/third_party /service_container
383384
/templating/templating_service /templates
384385
/testing/simulating_authentication /testing/http_authentication

components/serializer.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -872,9 +872,8 @@ Here, we set it to 2 for the ``$child`` property:
872872
http://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd"
873873
>
874874
<class name="Acme\MyObj">
875-
<attribute name="foo">
876-
<max-depth>2</max-depth>
877-
</attribute>
875+
<attribute name="foo" max-depth="2" />
876+
</class>
878877
</serializer>
879878
880879
The metadata loader corresponding to the chosen format must be configured in

contributing/code/core_team.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ All the Symfony Core members are long-time contributors with solid technical
99
expertise and they have demonstrated a strong commitment to drive the project
1010
forward.
1111

12-
This document states the rules that govern the Symfony Core team. These rules
12+
This document states the rules that govern the Symfony core team. These rules
1313
are effective upon publication of this document and all Symfony Core members
1414
must adhere to said rules and protocol.
1515

@@ -121,7 +121,7 @@ Active Core Members
121121
Former Core Members
122122
~~~~~~~~~~~~~~~~~~~
123123

124-
They are no longer part of the Core Team, but we are very grateful for all their
124+
They are no longer part of the core team, but we are very grateful for all their
125125
Symfony contributions:
126126

127127
* **Bernhard Schussek** (`webmozart`_);

contributing/code/security.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ Reporting a Security Issue
1111
If you think that you have found a security issue in Symfony, don't use the
1212
bug tracker and don't publish it publicly. Instead, all security issues must
1313
be sent to **security [at] symfony.com**. Emails sent to this address are
14-
forwarded to the Symfony core-team private mailing-list.
14+
forwarded to the Symfony core team private mailing-list.
1515

1616
Resolving Process
1717
-----------------
1818

1919
For each report, we first try to confirm the vulnerability. When it is
20-
confirmed, the core-team works on a solution following these steps:
20+
confirmed, the core team works on a solution following these steps:
2121

2222
#. Send an acknowledgement to the reporter;
2323
#. Work on a patch;

contributing/code/standards.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,12 @@ Documentation
260260
* The ``@package`` and ``@subpackage`` annotations are not used;
261261

262262
* Don't inline PHPDoc blocks, even when they contain just one tag (e.g. don't
263-
put ``/** {@inheritdoc} */`` in a single line).
263+
put ``/** {@inheritdoc} */`` in a single line);
264+
265+
* When adding a new class or when making significant changes to an existing class,
266+
an ``@author`` tag with personal contact information may be added, or expanded.
267+
Please note it is possible to have the personal contact information updated or
268+
removed per request to the doc:`core team </contributing/code/core_team>`.
264269

265270
License
266271
~~~~~~~

controller.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,12 @@ method is just a shortcut to create a special
343343
:class:`Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException`
344344
object, which ultimately triggers a 404 HTTP response inside Symfony.
345345

346-
Of course, you can throw any ``Exception`` class in your controller: Symfony will
347-
automatically return a 500 HTTP response code::
346+
If you throw an exception that extends or is an instance of
347+
:class:`Symfony\\Component\\HttpKernel\\Exception\\HttpException`, Symfony will
348+
use the appropriate HTTP status code. Otherwise, the response will have a 500
349+
HTTP status code::
348350

351+
// this exception ultimately generates a 500 status error
349352
throw new \Exception('Something went wrong!');
350353

351354
In every case, an error page is shown to the end user and a full debug

doctrine.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ and save it!
335335
336336
$product = new Product();
337337
$product->setName('Keyboard');
338-
$product->setPrice(19.99);
338+
$product->setPrice(1999);
339339
$product->setDescription('Ergonomic and stylish!');
340340
341341
// tell Doctrine you want to (eventually) save the Product (no queries yet)
@@ -441,7 +441,7 @@ Once you have a repository object, you have many helper methods::
441441
// or find by name and price
442442
$product = $repository->findOneBy([
443443
'name' => 'Keyboard',
444-
'price' => 19.99,
444+
'price' => 1999,
445445
]);
446446

447447
// look for multiple Product objects matching the name, ordered by price
@@ -624,7 +624,7 @@ This uses Doctrine's `Query Builder`_: a very powerful and user-friendly way to
624624
write custom queries. Now, you can call this method on the repository::
625625

626626
// from inside a controller
627-
$minPrice = 10;
627+
$minPrice = 1000;
628628

629629
$products = $this->getDoctrine()
630630
->getRepository(Product::class)
@@ -654,7 +654,7 @@ In addition to the query builder, you can also query with `Doctrine Query Langua
654654
FROM App\Entity\Product p
655655
WHERE p.price > :price
656656
ORDER BY p.price ASC'
657-
)->setParameter('price', 10);
657+
)->setParameter('price', 1000);
658658

659659
// returns an array of Product objects
660660
return $query->execute();
@@ -675,7 +675,7 @@ Or directly with SQL if you need to::
675675
ORDER BY p.price ASC
676676
';
677677
$stmt = $conn->prepare($sql);
678-
$stmt->execute(['price' => 10]);
678+
$stmt->execute(['price' => 1000]);
679679

680680
// returns an array of arrays (i.e. a raw data set)
681681
return $stmt->fetchAll();

form/dynamic_form_modification.rst

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ Using an event listener, your form might look like this::
212212
use Symfony\Component\Form\FormBuilderInterface;
213213
use Symfony\Component\Form\FormEvents;
214214
use Symfony\Component\Form\FormEvent;
215-
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
216215
use Symfony\Component\Form\Extension\Core\Type\TextType;
217216
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
218217

@@ -231,33 +230,31 @@ Using an event listener, your form might look like this::
231230
}
232231

233232
The problem is now to get the current user and create a choice field that
234-
contains only this user's friends.
233+
contains only this user's friends. This can be done injecting the ``Security``
234+
service into the form type so you can get the current user object::
235235

236-
Luckily it is pretty easy to inject a service inside of the form. This can be
237-
done in the constructor::
236+
use Symfony\Component\Security\Core\Security;
238237

239-
private $tokenStorage;
238+
private $security;
240239

241-
public function __construct(TokenStorageInterface $tokenStorage)
240+
public function __construct(Security $security)
242241
{
243-
$this->tokenStorage = $tokenStorage;
242+
$this->security = $security;
244243
}
245244

246245
.. note::
247246

248-
You might wonder, now that you have access to the User (through the token
249-
storage), why not just use it directly in ``buildForm()`` and omit the
250-
event listener? This is because doing so in the ``buildForm()`` method
251-
would result in the whole form type being modified and not just this
252-
one form instance. This may not usually be a problem, but technically
253-
a single form type could be used on a single request to create many forms
254-
or fields.
247+
You might wonder, now that you have access to the ``User`` object, why not
248+
just use it directly in ``buildForm()`` and omit the event listener? This is
249+
because doing so in the ``buildForm()`` method would result in the whole
250+
form type being modified and not just this one form instance. This may not
251+
usually be a problem, but technically a single form type could be used on a
252+
single request to create many forms or fields.
255253

256254
Customizing the Form Type
257255
~~~~~~~~~~~~~~~~~~~~~~~~~
258256

259-
Now that you have all the basics in place you can take advantage of the ``TokenStorageInterface``
260-
and fill in the listener logic::
257+
Now that you have all the basics in place you can complete the listener logic::
261258

262259
// src/Form/Type/FriendMessageFormType.php
263260

@@ -266,16 +263,16 @@ and fill in the listener logic::
266263
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
267264
use Symfony\Component\Form\Extension\Core\Type\TextType;
268265
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
269-
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
266+
use Symfony\Component\Security\Core\Security;
270267
// ...
271268

272269
class FriendMessageFormType extends AbstractType
273270
{
274-
private $tokenStorage;
271+
private $security;
275272

276-
public function __construct(TokenStorageInterface $tokenStorage)
273+
public function __construct(Security $security)
277274
{
278-
$this->tokenStorage = $tokenStorage;
275+
$this->security = $security;
279276
}
280277

281278
public function buildForm(FormBuilderInterface $builder, array $options)
@@ -286,7 +283,7 @@ and fill in the listener logic::
286283
;
287284

288285
// grab the user, do a quick sanity check that one exists
289-
$user = $this->tokenStorage->getToken()->getUser();
286+
$user = $this->security->getUser();
290287
if (!$user) {
291288
throw new \LogicException(
292289
'The FriendMessageFormType cannot be used without an authenticated user!'
@@ -301,13 +298,12 @@ and fill in the listener logic::
301298
$formOptions = array(
302299
'class' => User::class,
303300
'choice_label' => 'fullName',
304-
'query_builder' => function (EntityRepository $er) use ($user) {
301+
'query_builder' => function (EntityRepository $userRepository) use ($user) {
305302
// build a custom query
306-
// return $er->createQueryBuilder('u')->addOrderBy('fullName', 'DESC');
303+
// return $userRepository->createQueryBuilder('u')->addOrderBy('fullName', 'DESC');
307304

308305
// or call a method on your repository that returns the query builder
309-
// the $er is an instance of your UserRepository
310-
// return $er->createOrderByFullNameQueryBuilder();
306+
// return $userRepository->createOrderByFullNameQueryBuilder();
311307
},
312308
);
313309

@@ -331,11 +327,8 @@ Using the Form
331327

332328
If you're using :ref:`autowire <services-autowire>` and
333329
:ref:`autoconfigure <services-autoconfigure>`, your form is ready to be used!
334-
335-
.. tip::
336-
337-
If you're not using autowire and autoconfigure, see :doc:`/form/form_dependencies`
338-
for how to register your form type as a service.
330+
Otherwise, see :doc:`/form/form_dependencies` to learn how to register your form
331+
type as a service.
339332

340333
In a controller, create the form like normal::
341334

form/form_customization.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ You can also apply a form theme to a specific child of your form:
382382

383383
.. code-block:: html+twig
384384

385-
{% form_theme form.child 'form/fields.html.twig' %}
385+
{% form_theme form.a_child_form 'form/fields.html.twig' %}
386386

387387
This is useful when you want to have a custom theme for a nested form that's
388388
different than the one of your main form. Just specify both your themes:
@@ -391,7 +391,7 @@ different than the one of your main form. Just specify both your themes:
391391

392392
{% form_theme form 'form/fields.html.twig' %}
393393

394-
{% form_theme form.child 'form/fields_child.html.twig' %}
394+
{% form_theme form.a_child_form 'form/fields_child.html.twig' %}
395395

396396
Form Theming in PHP
397397
-------------------

frontend.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Optimizing
5353
* :doc:`Versioning (and the manifest.json file) </frontend/encore/versioning>`
5454
* :doc:`Using A CDN </frontend/encore/cdn>`
5555
* :doc:`Creating a "Shared" entry for re-used modules </frontend/encore/shared-entry>`
56+
* :doc:`/frontend/encore/url-loader`
5657

5758
Guides
5859
......

frontend/encore/url-loader.rst

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
Inlining files in CSS with Webpack URL Loader
2+
=============================================
3+
4+
A simple technique to improve the performance of web applications is to reduce
5+
the number of HTTP requests inlining small files as base64 encoded URLs in the
6+
generated CSS files.
7+
8+
Webpack Encore provides this feature via Webpack's `URL Loader`_ plugin, but
9+
it's disabled by default. First, add the URL loader to your project:
10+
11+
.. code-block:: terminal
12+
13+
$ yarn add --dev url-loader
14+
15+
Then enable it in your ``webpack.config.js``:
16+
17+
.. code-block:: javascript
18+
19+
// webpack.config.js
20+
// ...
21+
22+
Encore
23+
// ...
24+
.configureUrlLoader({
25+
fonts: { limit: 4096 },
26+
images: { limit: 4096 }
27+
})
28+
;
29+
30+
The ``limit`` option defines the maximum size in bytes of the inlined files. In
31+
the previous example, font and image files having a size below or equal to 4 KB
32+
will be inlined and the rest of files will be processed as usual.
33+
34+
You can also use all the other options supported by the `URL Loader`_. If you
35+
want to disable this loader for either images or fonts, remove the corresponding
36+
key from the object that is passed to the ``configureUrlLoader()`` method:
37+
38+
.. code-block:: javascript
39+
40+
// webpack.config.js
41+
// ...
42+
43+
Encore
44+
// ...
45+
.configureUrlLoader({
46+
// 'fonts' is not defined, so only images will be inlined
47+
images: { limit: 4096 }
48+
})
49+
;
50+
51+
.. _`URL loader`: https://github.com/webpack-contrib/url-loader

http_cache/esi.rst

-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ matter), Symfony uses the standard ``render`` helper to configure ESI tags:
127127
{# templates/static/about.html.twig #}
128128
129129
{# you can use a controller reference #}
130-
{{ render_esi(controller('App\Controller\NewsController::latest', { 'maxPerPage': 5 })) }}
130+
{{ render_esi(controller('App\\Controller\\NewsController::latest', { 'maxPerPage': 5 })) }}
131131
132132
{# ... or a URL #}
133133
{{ render_esi(url('latest_news', { 'maxPerPage': 5 })) }}
@@ -139,7 +139,7 @@ matter), Symfony uses the standard ``render`` helper to configure ESI tags:
139139
<!-- you can use a controller reference -->
140140
<?php echo $view['actions']->render(
141141
new Symfony\Component\HttpKernel\Controller\ControllerReference(
142-
'App\Controller\NewsController::latest',
142+
'App\\Controller\\NewsController::latest',
143143
array('maxPerPage' => 5)
144144
),
145145
array('strategy' => 'esi')

quick_tour/flex_recipes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ rich API for a ``product`` table? Create a ``Product`` entity and give it the
213213
private $name;
214214

215215
/**
216-
* @ORM\Column(type="string")
216+
* @ORM\Column(type="int")
217217
*/
218218
private $price;
219219

reference/dic_tags.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ also have to be added as regular services:
10981098
.. code-block:: yaml
10991099
11001100
services:
1101-
Twig_Extensions_Extension_Intl:
1101+
Twig\Extensions\IntlExtension:
11021102
tags: [twig.extension]
11031103
11041104
.. code-block:: xml
@@ -1110,7 +1110,7 @@ also have to be added as regular services:
11101110
http://symfony.com/schema/dic/services/services-1.0.xsd">
11111111
11121112
<services>
1113-
<service id="Twig_Extensions_Extension_Intl">
1113+
<service id="Twig\Extensions\IntlExtension">
11141114
<tag name="twig.extension" />
11151115
</service>
11161116
</services>
@@ -1119,7 +1119,7 @@ also have to be added as regular services:
11191119
.. code-block:: php
11201120
11211121
$container
1122-
->register('Twig_Extensions_Extension_Intl')
1122+
->register('Twig\Extensions\IntlExtension')
11231123
->addTag('twig.extension')
11241124
;
11251125

security/security_checker.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,11 @@ FriendsOfPHP organization.
3232
any of your dependencies is affected by a known security vulnerability.
3333
Therefore, you can easily integrate it in your build process.
3434

35+
.. tip::
36+
37+
The security checker is also available as an independent console application
38+
and distributed as a PHAR file so you can use it in any PHP application.
39+
Check out the `Security Checker repository`_ for more details.
40+
3541
.. _`security advisories database`: https://github.com/FriendsOfPHP/security-advisories
42+
.. _`Security Checker repository`: https://github.com/sensiolabs/security-checker

session/proxy_examples.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ can intercept the session before it is written::
134134

135135
private function getUser()
136136
{
137-
if (!$token = $tokenStorage->getToken()) {
137+
if (!$token = $this->tokenStorage->getToken()) {
138138
return;
139139
}
140140

0 commit comments

Comments
 (0)
0