Skip to content

Commit ab8af2d

Browse files
committed
Merge branch '3.4' into 4.0
* 3.4: Mentioned the ability of PropertyNormalizer to handle parent classes Reverted the cache:clear warm up deprecation Documented how to load and dump translation notes [BrowserKit] Add snippet: how to upload a file uploading example: explaining the need for md5 soap_web_service: code style in examples Updated the main performance article to make it more actionable Improved the docs about multiple Webpack configs Added a note about using slashes and the special _format param Document new VarCloner::setMinDepth function
2 parents 039a298 + 89b4cad commit ab8af2d

File tree

11 files changed

+282
-100
lines changed

11 files changed

+282
-100
lines changed

components/browser_kit.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ method (which makes the needed HTTP POST request to submit the form contents)::
109109
$form['login'] = 'symfonyfan';
110110
$form['password'] = 'anypass';
111111

112+
// To upload a file, the value should be the absolute file path
113+
$form['file'] = __FILE__;
114+
112115
// submit that form
113116
$crawler = $client->submit($form);
114117

components/serializer.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,11 +565,15 @@ There are several types of normalizers available:
565565

566566
:class:`Symfony\\Component\\Serializer\\Normalizer\\PropertyNormalizer`
567567
This normalizer directly reads and writes public properties as well as
568-
**private and protected** properties. It supports calling the constructor
569-
during the denormalization process.
568+
**private and protected** properties (from both the class and all of its
569+
parent classes). It supports calling the constructor during the denormalization process.
570570

571571
Objects are normalized to a map of property names to property values.
572572

573+
.. versionadded:: 3.4
574+
The ability to handle parent classes for ``PropertyNormalizer`` was
575+
introduced in Symfony 3.4.
576+
573577
:class:`Symfony\\Component\\Serializer\\Normalizer\\JsonSerializableNormalizer`
574578
This normalizer works with classes that implement :phpclass:`JsonSerializable`.
575579

components/translation/usage.rst

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,5 +418,62 @@ The ``$messages`` variable will have the following structure::
418418
),
419419
);
420420

421+
Adding Notes to Translation Contents
422+
------------------------------------
423+
424+
.. versionadded: 3.4
425+
The feature to load and dump translation notes was introduced in Symfony 3.4.
426+
427+
Sometimes translators need additional context to better decide how to translate
428+
some content. This context can be provided with notes, which are a collection of
429+
comments used to store end user readable information. The only format that
430+
supports loading and dumping notes is XLIFF version 2.0.
431+
432+
If the XLIFF 2.0 document contains ``<notes>`` nodes, they are automatically
433+
loaded/dumped when using this component inside a Symfony application:
434+
435+
.. code-block:: xml
436+
437+
<?xml version="1.0" encoding="utf-8"?>
438+
<xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0"
439+
srcLang="fr-FR" trgLang="en-US">
440+
<file id="messages.en_US">
441+
<unit id="LCa0a2j">
442+
<notes>
443+
<note category="state">new</note>
444+
<note category="approved">true</note>
445+
<note category="section" priority="1">user login</note>
446+
</notes>
447+
<segment>
448+
<source>original-content</source>
449+
<target>translated-content</target>
450+
</segment>
451+
</unit>
452+
</file>
453+
</xliff>
454+
455+
When using the standalone Translation component, call the ``setMetadata()``
456+
method of the catalogue and pass the notes as arrays. This is for example the
457+
code needed to generate the previous XLIFF file::
458+
459+
use Symfony\Component\Translation\MessageCatalogue;
460+
use Symfony\Component\Translation\Dumper\XliffFileDumper;
461+
462+
$catalogue = new MessageCatalogue('en_US');
463+
$catalogue->add([
464+
'original-content' => 'translated-content',
465+
]);
466+
$catalogue->setMetadata('original-content', ['notes' => [
467+
['category' => 'state', 'content' => 'new'],
468+
['category' => 'approved', 'content' => 'true'],
469+
['category' => 'section', 'content' => 'user login', 'priority' => '1'],
470+
]]);
471+
472+
$dumper = new XliffFileDumper();
473+
$dumper->formatCatalogue($catalogue, 'messages', [
474+
'default_locale' => 'fr_FR',
475+
'xliff_version' => '2.0'
476+
]);
477+
421478
.. _`L10n`: https://en.wikipedia.org/wiki/Internationalization_and_localization
422479
.. _`ISO 31-11`: https://en.wikipedia.org/wiki/Interval_(mathematics)#Notations_for_intervals

components/var_dumper/advanced.rst

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,23 @@ Before calling :method:`Symfony\\Component\\VarDumper\\Cloner\\VarCloner::cloneV
5353
you can configure these limits:
5454

5555
:method:`Symfony\\Component\\VarDumper\\Cloner\\VarCloner::setMaxItems`
56-
configures the maximum number of items that will be cloned
57-
*past the first nesting level*. Items are counted using a breadth-first
56+
Configures the maximum number of items that will be cloned
57+
*past the minimum nesting depth*. Items are counted using a breadth-first
5858
algorithm so that lower level items have higher priority than deeply nested
59-
items;
59+
items. Specifying ``-1`` removes the limit.
6060

61-
:method:`Symfony\\Component\\VarDumper\\Cloner\\VarCloner::setMaxString`
62-
configures the maximum number of characters that will be cloned before
63-
cutting overlong strings;
61+
:method:`Symfony\\Component\\VarDumper\\Cloner\\VarCloner::setMinDepth`
62+
.. versionadded:: 3.4
63+
The ``setMinDepth()`` method was introduced in Symfony 3.4.
64+
65+
Configures the minimum tree depth where we are guaranteed to clone
66+
all the items. After this depth is reached, only ``setMaxItems``
67+
items will be cloned. The default value is ``1``, which is consistent
68+
with older Symfony versions.
6469

65-
In both cases, specifying ``-1`` removes any limit.
70+
:method:`Symfony\\Component\\VarDumper\\Cloner\\VarCloner::setMaxString`
71+
Configures the maximum number of characters that will be cloned before
72+
cutting overlong strings. Specifying ``-1`` removes the limit.
6673

6774
Before dumping it, you can further limit the resulting
6875
:class:`Symfony\\Component\\VarDumper\\Cloner\\Data` object using the following methods:

controller/soap_web_service.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ In this case, the SOAP service will allow the client to call a method called
4040
{
4141

4242
$message = new \Swift_Message('Hello Service')
43-
->setTo('[email protected]')
44-
->setBody($name . ' says hi!');
43+
->setTo('[email protected]')
44+
->setBody($name.' says hi!');
4545

4646
$this->mailer->send($message);
4747

controller/upload_file.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ Finally, you need to update the code of the controller that handles the form::
132132
/** @var Symfony\Component\HttpFoundation\File\UploadedFile $file */
133133
$file = $product->getBrochure();
134134

135-
// Generate a unique name for the file before saving it
136-
$fileName = md5(uniqid()).'.'.$file->guessExtension();
135+
$fileName = $this->generateUniqueFileName().'.'.$file->guessExtension();
137136

138137
// Move the file to the directory where brochures are stored
139138
$file->move(
@@ -154,6 +153,16 @@ Finally, you need to update the code of the controller that handles the form::
154153
'form' => $form->createView(),
155154
));
156155
}
156+
157+
/**
158+
* @return string
159+
*/
160+
private function generateUniqueFileName()
161+
{
162+
// md5() reduces the similarity of the file names generated by
163+
// uniqid(), which is based on timestamps
164+
return md5(uniqid());
165+
}
157166
}
158167

159168
Now, create the ``brochures_directory`` parameter that was used in the

deployment.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ Make sure you clear and warm-up your Symfony cache:
167167

168168
.. code-block:: terminal
169169
170-
$ php bin/console cache:clear --env=prod --no-debug --no-warmup
171-
$ php bin/console cache:warmup --env=prod
170+
$ php bin/console cache:clear --env=prod --no-debug
172171
173172
E) Dump your Assetic Assets
174173
~~~~~~~~~~~~~~~~~~~~~~~~~~~

frontend/encore/advanced-config.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ state of the current configuration to build a new one:
6363
// build the first configuration
6464
const firstConfig = Encore.getWebpackConfig();
6565
66+
// Set a unique name for the config (needed later!)
67+
firstConfig.name = 'firstConfig';
68+
6669
// reset Encore to build the second config
6770
Encore.reset();
6871
@@ -79,9 +82,19 @@ state of the current configuration to build a new one:
7982
// build the second configuration
8083
const secondConfig = Encore.getWebpackConfig();
8184
85+
// Set a unique name for the config (needed later!)
86+
secondConfig.name = 'secondConfig';
87+
8288
// export the final configuration as an array of multiple configurations
8389
module.exports = [firstConfig, secondConfig];
8490
91+
When running Encore, both configurations will be built in parallel. If you
92+
prefer to build configs separately, pass the ``--config-name`` option:
93+
94+
.. code-block:: terminal
95+
96+
$ yarn run encore dev --config-name firstConfig
97+
8598
.. _`configuration options`: https://webpack.js.org/configuration/
8699
.. _`Webpack's watchOptions`: https://webpack.js.org/configuration/watch/#watchoptions
87100
.. _`array of configurations`: https://github.com/webpack/docs/wiki/configuration#multiple-configurations

introduction/from_flat_php_to_symfony2.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ nice way to group related pages. The controller functions are also sometimes cal
578578
The two controllers (or actions) are still lightweight. Each uses the
579579
:doc:`Doctrine ORM library </doctrine>` to retrieve objects from the
580580
database and the Templating component to render a template and return a
581-
``Response`` object. The list ``list.html.twig`` template is now quite a bit simpler,
581+
``Response`` object. The ``list.html.twig`` template is now quite a bit simpler,
582582
and uses Twig:
583583

584584
.. code-block:: html+twig
@@ -669,9 +669,9 @@ It's a beautiful thing.
669669
Where Symfony Delivers
670670
----------------------
671671

672-
In the rest of documentation articles, you'll learn more about how each piece of
673-
Symfony works and how you can organize your project. For now, celebrate at how
674-
migrating the blog from flat PHP to Symfony has improved life:
672+
In the rest of the documentation articles, you'll learn more about how each piece of
673+
Symfony works and how you can organize your project. For now, celebrate how
674+
migrating the blog from flat PHP to Symfony has improved your life:
675675

676676
* Your application now has **clear and consistently organized code** (though
677677
Symfony doesn't force you into this). This promotes **reusability** and

0 commit comments

Comments
 (0)