Skip to content

Commit 5aa7f8a

Browse files
committed
Merge branch '3.3' into 3.4
* 3.3: (23 commits) Renamed the channel to "app" Add XmlEncoder documentation with $context available options Mention and recommend to use PHP-CS-Fixer when contributing code Reworded the note about dump() availability per environment Fixed an example in the form testing article Improved the routing debug article Mention that we are using Bootstrap Datepicker Remove information about default priority Fix missing blank line Add note about LocaleListener ...
2 parents 29900e9 + ec0075a commit 5aa7f8a

File tree

9 files changed

+118
-44
lines changed

9 files changed

+118
-44
lines changed

components/serializer.rst

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,63 @@ you indicate that you're expecting an array instead of a single object.
864864
$data = ...; // The serialized data from the previous example
865865
$persons = $serializer->deserialize($data, 'Acme\Person[]', 'json');
866866
867+
The ``XmlEncoder``
868+
------------------
869+
870+
This encoder transforms arrays into XML and vice versa. For example, take an
871+
object normalized as following::
872+
873+
array('foo' => array(1, 2), 'bar' => true);
874+
875+
The ``XmlEncoder`` encodes this object as follows:
876+
877+
.. code-block:: xml
878+
879+
<?xml version="1.0"?>
880+
<response>
881+
<foo>1</foo>
882+
<foo>2</foo>
883+
<bar>1</bar>
884+
</response>
885+
886+
The array keys beginning with ``@`` are considered XML attributes::
887+
888+
array('foo' => array('@bar' => 'value'));
889+
890+
// is encoded as follows:
891+
// <?xml version="1.0"?>
892+
// <response>
893+
// <foo bar="value" />
894+
// </response>
895+
896+
Context
897+
~~~~~~~
898+
899+
The ``encode()`` method defines a third optional parameter called ``context``
900+
which defines the configuration options for the XmlEncoder an associative array::
901+
902+
$xmlEncoder->encode($array, 'xml', $context);
903+
904+
These are the options available:
905+
906+
``xml_format_output``
907+
If set to true, formats the generated XML with line breaks and indentation.
908+
909+
``xml_version``
910+
Sets the XML version attribute (default: ``1.1``).
911+
912+
``xml_encoding``
913+
Sets the XML encoding attribute (default: ``utf-8``).
914+
915+
``xml_standalone``
916+
Adds standalone attribute in the generated XML (default: ``true``).
917+
918+
``xml_root_node_name``
919+
Sets the root node name (default: ``response``).
920+
921+
``remove_empty_tags``
922+
If set to true, removes all empty tags in the generated XML.
923+
867924
Recursive Denormalization and Type Safety
868925
-----------------------------------------
869926

contributing/code/standards.rst

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
Coding Standards
22
================
33

4-
When contributing code to Symfony, you must follow its coding standards. To
5-
make a long story short, here is the golden rule: **Imitate the existing
6-
Symfony code**. Most open-source Bundles and libraries used by Symfony also
7-
follow the same guidelines, and you should too.
4+
Symfony code is contributed by thousands of developers around the world. To make
5+
every piece of code look and feel familiar, Symfony defines some coding standards
6+
that all contributions must follow.
87

9-
Remember that the main advantage of standards is that every piece of code
10-
looks and feels familiar, it's not about this or that being more readable.
8+
These Symfony coding standards are based on the `PSR-1`_, `PSR-2`_ and `PSR-4`_
9+
standards, so you may already know most of them.
1110

12-
Symfony follows the standards defined in the `PSR-0`_, `PSR-1`_, `PSR-2`_ and `PSR-4`_
13-
documents.
11+
Making your Code Follow the Coding Standards
12+
--------------------------------------------
1413

15-
Since a picture - or some code - is worth a thousand words, here's a short
16-
example containing most features described below:
14+
Instead of reviewing your code manually, Symfony makes it simple to ensure that
15+
your contributed code matches the expected code syntax. First, install the
16+
`PHP CS Fixer tool`_ and then, run this command to fix any problem:
17+
18+
.. code-block:: terminal
19+
20+
$ cd your-project/
21+
$ php php-cs-fixer.phar fix -v
22+
23+
If you forget to run this command and make a pull request with any syntax issue,
24+
our automated tools will warn you about that and will provide the solution.
25+
26+
Symfony Coding Standards in Detail
27+
----------------------------------
28+
29+
If you want to learn about the Symfony coding standards in detail, here's a
30+
short example containing most features described below:
1731

1832
.. code-block:: html+php
1933

@@ -122,7 +136,7 @@ example containing most features described below:
122136
}
123137

124138
Structure
125-
---------
139+
~~~~~~~~~
126140

127141
* Add a single space after each comma delimiter;
128142

@@ -181,7 +195,7 @@ Structure
181195
* Do not use spaces around ``[`` offset accessor and before ``]`` offset accessor.
182196

183197
Naming Conventions
184-
------------------
198+
~~~~~~~~~~~~~~~~~~
185199

186200
* Use camelCase, not underscores, for variable, function and method
187201
names, arguments;
@@ -228,7 +242,7 @@ Service Naming Conventions
228242
to ``something.service_name``).
229243

230244
Documentation
231-
-------------
245+
~~~~~~~~~~~~~
232246

233247
* Add PHPDoc blocks for all classes, methods, and functions (though you may
234248
be asked to remove PHPDoc that do not add value);
@@ -239,14 +253,17 @@ Documentation
239253

240254
* Omit the ``@return`` tag if the method does not return anything;
241255

242-
* The ``@package`` and ``@subpackage`` annotations are not used.
256+
* The ``@package`` and ``@subpackage`` annotations are not used;
257+
258+
* Inline the ``@inheritdoc`` tag.
243259

244260
License
245-
-------
261+
~~~~~~~
246262

247263
* Symfony is released under the MIT license, and the license block has to be
248264
present at the top of every PHP file, before the namespace.
249265

266+
.. _`PHP CS Fixer tool`: http://cs.sensiolabs.org/
250267
.. _`PSR-0`: http://www.php-fig.org/psr/psr-0/
251268
.. _`PSR-1`: http://www.php-fig.org/psr/psr-1/
252269
.. _`PSR-2`: http://www.php-fig.org/psr/psr-2/

form/unit_testing.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ The simplest ``TypeTestCase`` implementation looks like the following::
4949

5050
$form = $this->factory->create(TestedType::class);
5151

52-
$object = TestObject::fromArray($formData);
52+
$object = new TestObject();
53+
// ...populate $object properties with the data stored in $formData
5354

5455
// submit the data to the form directly
5556
$form->submit($formData);

reference/dic_tags.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ channel when injecting the logger in a service.
658658
AppBundle\Log\CustomLogger:
659659
arguments: ['@logger']
660660
tags:
661-
- { name: monolog.logger, channel: acme }
661+
- { name: monolog.logger, channel: app }
662662
663663
.. code-block:: xml
664664
@@ -671,7 +671,7 @@ channel when injecting the logger in a service.
671671
<services>
672672
<service id="AppBundle\Log\CustomLogger">
673673
<argument type="service" id="logger" />
674-
<tag name="monolog.logger" channel="acme" />
674+
<tag name="monolog.logger" channel="app" />
675675
</service>
676676
</services>
677677
</container>
@@ -683,7 +683,7 @@ channel when injecting the logger in a service.
683683
684684
$container->register(CustomLogger::class)
685685
->addArgument(new Reference('logger'))
686-
->addTag('monolog.logger', array('channel' => 'acme'));
686+
->addTag('monolog.logger', array('channel' => 'app'));
687687
688688
.. tip::
689689

reference/forms/types/date.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ picker:
108108

109109
<script>
110110
$(document).ready(function() {
111-
// configure the bootstrap datepicker
111+
// you may need to change this code if you are not using Bootstrap Datepicker
112112
$('.js-datepicker').datepicker({
113113
format: 'yyyy-mm-dd'
114114
});

routing/debug.rst

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,13 @@ How to Visualize And Debug Routes
66

77
While adding and customizing routes, it's helpful to be able to visualize
88
and get detailed information about your routes. A great way to see every
9-
route in your application is via the ``debug:router`` console command. Execute
10-
the command by running the following from the root of your project.
9+
route in your application is via the ``debug:router`` console command, which
10+
lists *all* the configured routes in your application:
1111

1212
.. code-block:: terminal
1313
1414
$ php bin/console debug:router
1515
16-
This command will print a helpful list of *all* the configured routes in
17-
your application:
18-
19-
.. code-block:: text
20-
2116
------------------ -------- -------- ------ ----------------------------------------------
2217
Name Method Scheme Host Path
2318
------------------ -------- -------- ------ ----------------------------------------------
@@ -30,21 +25,18 @@ your application:
3025
------------------ -------- -------- ------ ----------------------------------------------
3126
3227
You can also get very specific information on a single route by including
33-
the route name after the command:
28+
the route name as the command argument:
3429

3530
.. code-block:: terminal
3631
3732
$ php bin/console debug:router article_show
3833
39-
Likewise, if you want to test whether a URL matches a given route, you can
40-
use the ``router:match`` console command:
34+
Likewise, if you want to test whether a URL matches a given route, use the
35+
``router:match`` command. This is useful to debug routing issues and find out
36+
which route is associated with the given URL:
4137

4238
.. code-block:: terminal
4339
4440
$ php bin/console router:match /blog/my-latest-post
4541
46-
This command will print which route the URL matches.
47-
48-
.. code-block:: text
49-
5042
Route "blog_show" matches

service_container.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,8 @@ made. To do that, you create a new class::
371371
->addPart(
372372
'Someone just updated the site. We told them: '.$happyMessage
373373
);
374-
$this->mailer->send($message);
375-
376-
return $happyMessage;
374+
375+
return $this->mailer->send($message) > 0;
377376
}
378377
}
379378

@@ -387,8 +386,10 @@ you can use the service immediately::
387386
{
388387
// ...
389388

390-
$message = $siteUpdateManager->notifyOfSiteUpdate();
391-
$this->addFlash('success', $message);
389+
if ($siteUpdateManager->notifyOfSiteUpdate()) {
390+
$this->addFlash('success', 'Notification mail was sent successfully.');
391+
}
392+
392393
// ...
393394
}
394395

templating/debug.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ The same mechanism can be used in Twig templates thanks to ``dump()`` function:
4646
</a>
4747
{% endfor %}
4848

49-
By design, the ``dump()`` function is only available if the ``kernel.debug``
50-
setting (in ``config.yml``) is ``true``, to avoid leaking sensitive information
51-
in production. In fact, trying to use the ``dump()`` function when ``kernel.debug``
52-
is ``false`` (for example in the ``prod`` environment) will result in an
53-
application error.
49+
By design, the ``dump()`` function is only available in the ``dev`` and ``test``
50+
environments, to avoid leaking sensitive information in production. In fact,
51+
trying to use the ``dump()`` function in the ``prod`` environment will result in
52+
a PHP error.

translation/locale.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ it::
2626
$request->setLocale($locale);
2727
}
2828

29+
.. note::
30+
31+
The custom listener must be called **before** ``LocaleListener``, which
32+
initializes the locale based on the current request. To do so, set your
33+
listener priority to a higher value than ``LocaleListener`` priority (which
34+
you can obtain running the ``debug:event kernel.request`` command).
35+
2936
Read :doc:`/session/locale_sticky_session` for more information on making
3037
the user's locale "sticky" to their session.
3138

0 commit comments

Comments
 (0)