Skip to content

Commit 8cfaffc

Browse files
committed
Merge branch '3.4' into 4.0
* 3.4: (28 commits) Correcting my bad english with a bilingual friend Add XmlEncoder documentation with $context available options This doc doesn't apply to version 3.4 Refactored the code Mention and recommend to use PHP-CS-Fixer when contributing code Updated the "custom data collector" article 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 ...
2 parents 0855709 + 5aa7f8a commit 8cfaffc

File tree

13 files changed

+197
-162
lines changed

13 files changed

+197
-162
lines changed

bundles.rst

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -77,43 +77,16 @@ called ``AcmeTestBundle.php``::
7777

7878
This empty class is the only piece you need to create the new bundle. Though
7979
commonly empty, this class is powerful and can be used to customize the behavior
80-
of the bundle.
80+
of the bundle. Now that you've created the bundle, enable it::
8181

82-
Now that you've created the bundle, enable it via the ``AppKernel`` class::
83-
84-
// app/AppKernel.php
85-
public function registerBundles()
86-
{
87-
$bundles = array(
88-
// ...
89-
90-
// register your bundle
91-
new Acme\TestBundle\AcmeTestBundle(),
92-
);
82+
// config/bundles.php
83+
return [
9384
// ...
94-
95-
return $bundles;
96-
}
85+
Acme\TestBundle\AcmeTestBundle::class => ['all' => true],
86+
];
9787

9888
And while it doesn't do anything yet, AcmeTestBundle is now ready to be used.
9989

100-
And as easy as this is, Symfony also provides a command-line interface for
101-
generating a basic bundle skeleton:
102-
103-
.. code-block:: terminal
104-
105-
$ php bin/console generate:bundle --namespace=Acme/TestBundle
106-
107-
The bundle skeleton generates a basic controller, template and routing
108-
resource that can be customized. You'll learn more about Symfony's command-line
109-
tools later.
110-
111-
.. tip::
112-
113-
Whenever creating a new bundle or using a third-party bundle, always make
114-
sure the bundle has been enabled in ``registerBundles()``. When using
115-
the ``generate:bundle`` command, this is done for you.
116-
11790
Bundle Directory Structure
11891
--------------------------
11992

@@ -131,7 +104,7 @@ of the most common elements of a bundle:
131104
necessary).
132105

133106
``Resources/config/``
134-
Houses configuration, including routing configuration (e.g. ``routing.yml``).
107+
Houses configuration, including routing configuration (e.g. ``routing.yaml``).
135108

136109
``Resources/views/``
137110
Holds templates organized by controller name (e.g. ``Random/index.html.twig``).

components/form.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ to bootstrap or access Twig and add the :class:`Symfony\\Bridge\\Twig\\Extension
174174

175175
use Symfony\Component\Form\Forms;
176176
use Symfony\Bridge\Twig\Extension\FormExtension;
177-
use Symfony\Bridge\Twig\Form\TwigRenderer;
177+
use Symfony\Component\Form\FormRenderer;
178178
use Symfony\Bridge\Twig\Form\TwigRendererEngine;
179179

180180
// the Twig file that holds all the default markup for rendering forms
@@ -195,8 +195,8 @@ to bootstrap or access Twig and add the :class:`Symfony\\Bridge\\Twig\\Extension
195195
)));
196196
$formEngine = new TwigRendererEngine(array($defaultFormTheme), $twig);
197197
$twig->addRuntimeLoader(new \Twig_FactoryRuntimeLoader(array(
198-
TwigRenderer::class => function () use ($formEngine, $csrfManager) {
199-
return new TwigRenderer($formEngine, $csrfManager);
198+
FormRenderer::class => function () use ($formEngine, $csrfManager) {
199+
return new FormRenderer($formEngine, $csrfManager);
200200
},
201201
)));
202202

components/lock.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ method can be safely called repeatedly, even if the lock is already acquired.
5959
to be used by several services, they should share the same ``Lock`` instance
6060
returned by the ``Factory::createLock`` method.
6161

62+
.. tip::
63+
64+
If you don't release the lock explicitly, it will be released automatically
65+
on instance destruction. In some cases, it can be useful to lock a resource
66+
across several requests. To disable the automatic release behavior, set the
67+
third argument of the ``createLock()`` method to ``false``.
68+
6269
Blocking Locks
6370
--------------
6471

components/serializer.rst

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

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);

0 commit comments

Comments
 (0)