Skip to content

Commit 4feae13

Browse files
committed
Merge branch '4.0'
* 4.0: Fixed a typo Improved the guide about upgrading apps to Flex Recommend to use PHPUnitBridge instead of PHPUnit Fixes and simplifications Improve routing debug page Improved the example to generate URLs in the console Minor typo minor symfony#8704 Client's history clear alternative (takman1) [Serializer] Add new default normalizers use the ref role instead of URLs Update timezone.rst Update timezone.rst
2 parents 640d0ee + 604e4b7 commit 4feae13

File tree

10 files changed

+160
-60
lines changed

10 files changed

+160
-60
lines changed

console/request_context.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ router service and override its settings::
8585
$context->setScheme('https');
8686
$context->setBaseUrl('my/path');
8787

88-
// ... your code here
88+
$url = $this->router->generate('route-name', array('param-name' => 'param-value'));
89+
// ...
8990
}
9091
}

form/disabling_validation.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ for example whether an uploaded file was too large or whether non-existing
2121
fields were submitted.
2222

2323
The submission of extra form fields can be controlled with the
24-
`allow_extra_fields config option`_ and the maximum upload file size should be
25-
handled via your PHP and web server configuration.
26-
27-
.. _`allow_extra_fields config option`: https://symfony.com/doc/current/reference/forms/types/form.html#allow-extra-fields
24+
:ref:`allow_extra_fields config option <form-option-allow-extra-fields>` and
25+
the maximum upload file size should be handled via your PHP and web server
26+
configuration.

reference/forms/types/form.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ Field Options
5050

5151
.. include:: /reference/forms/types/options/action.rst.inc
5252

53+
.. _form-option-allow-extra-fields:
54+
5355
allow_extra_fields
5456
~~~~~~~~~~~~~~~~~~
5557

reference/forms/types/timezone.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ manually, but then you should just use the ``ChoiceType`` directly.
1717
+-------------+------------------------------------------------------------------------+
1818
| Rendered as | can be various tags (see :ref:`forms-reference-choice-tags`) |
1919
+-------------+------------------------------------------------------------------------+
20+
| Options | - `input`_ |
21+
| | - `regions`_ |
22+
+-------------+------------------------------------------------------------------------+
2023
| Overridden | - `choices`_ |
2124
| options | |
2225
+-------------+------------------------------------------------------------------------+
@@ -45,6 +48,27 @@ manually, but then you should just use the ``ChoiceType`` directly.
4548
| Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\TimezoneType` |
4649
+-------------+------------------------------------------------------------------------+
4750

51+
Field Options
52+
-------------
53+
54+
input
55+
~~~~~
56+
57+
**type**: ``string`` **default**: ``string``
58+
59+
The format of the *input* data - i.e. the format that the timezone is stored
60+
on your underlying object. Valid values are:
61+
62+
* ``string`` (e.g. ``America/New_York``)
63+
* ``datetimezone`` (a ``DateTimeZone`` object)
64+
65+
regions
66+
~~~~~~~
67+
68+
**type**: ``int`` **default**: ``\DateTimeZone::ALL``
69+
70+
The available regions in the timezone choice list. For example: ``DateTimeZone::AMERICA | DateTimeZone::EUROPE``
71+
4872
Overridden Options
4973
------------------
5074

routing/debug.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ your application:
1818

1919
.. code-block:: text
2020
21-
homepage ANY /
22-
contact GET /contact
23-
contact_process POST /contact
24-
article_show ANY /articles/{_locale}/{year}/{title}.{_format}
25-
blog ANY /blog/{page}
26-
blog_show ANY /blog/{slug}
21+
------------------ -------- -------- ------ ----------------------------------------------
22+
Name Method Scheme Host Path
23+
------------------ -------- -------- ------ ----------------------------------------------
24+
homepage ANY ANY ANY /
25+
contact GET ANY ANY /contact
26+
contact_process POST ANY ANY /contact
27+
article_show ANY ANY ANY /articles/{_locale}/{year}/{title}.{_format}
28+
blog ANY ANY ANY /blog/{page}
29+
blog_show ANY ANY ANY /blog/{slug}
30+
------------------ -------- -------- ------ ----------------------------------------------
2731
2832
You can also get very specific information on a single route by including
2933
the route name after the command:

serializer.rst

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,37 @@ you need it or it can be used in a controller::
4444
Adding Normalizers and Encoders
4545
-------------------------------
4646

47-
Once enabled, the serializer service will be available in the container
48-
and will be loaded with four :ref:`encoders <component-serializer-encoders>`
49-
(:class:`Symfony\\Component\\Serializer\\Encoder\\JsonEncoder`,
50-
:class:`Symfony\\Component\\Serializer\\Encoder\\XmlEncoder`,
51-
:class:`Symfony\\Component\\Serializer\\Encoder\\YamlEncoder`, and
52-
:class:`Symfony\\Component\\Serializer\\Encoder\\CsvEncoder`) and the
53-
:ref:`ObjectNormalizer normalizer <component-serializer-normalizers>`.
54-
55-
You can load normalizers and/or encoders by tagging them as
47+
Once enabled, the ``serializer`` service will be available in the container.
48+
It comes with a set of useful :ref:`encoders <component-serializer-encoders>`
49+
and :ref:`normalizers <component-serializer-normalizers>`.
50+
51+
Encoders supporting the following formats are enabled:
52+
53+
* JSON: :class:`Symfony\\Component\\Serializer\\Encoder\\JsonEncoder`
54+
* XML: :class:`Symfony\\Component\\Serializer\\Encoder\\XmlEncoder`
55+
56+
As well as the following normalizers:
57+
58+
* :class:`Symfony\\Component\\Serializer\\Normalizer\\ObjectNormalizer` to
59+
handle typical data objects
60+
* :class:`Symfony\\Component\\Serializer\\Normalizer\\DateTimeNormalizer` for
61+
objects implementing the :class:`DateTimeInterface` interface
62+
* :class:`Symfony\\Component\\Serializer\\Normalizer\\DataUriNormalizer` to
63+
transform :class:`SplFileInfo` objects in `Data URIs`_
64+
* :class:`Symfony\\Component\\Serializer\\Normalizer\\JsonSerializableNormalizer`
65+
to deal with objects implementing the :class:`JsonSerializable` interface
66+
* :class:`Symfony\\Component\\Serializer\\Normalizer\\ArrayDenormalizer` to
67+
denormalize arrays of objects using a format like `MyObject[]` (note the `[]` suffix)
68+
69+
Custom normalizers and/or encoders can also be loaded by tagging them as
5670
:ref:`serializer.normalizer <reference-dic-tags-serializer-normalizer>` and
5771
:ref:`serializer.encoder <reference-dic-tags-serializer-encoder>`. It's also
5872
possible to set the priority of the tag in order to decide the matching order.
5973

6074
Here is an example on how to load the
61-
:class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer`:
75+
:class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer`, a
76+
faster alternative to the `ObjectNormalizer` when data objects always use
77+
getters and setters:
6278

6379
.. configuration-block::
6480

@@ -193,3 +209,4 @@ take a look at how this bundle works.
193209
.. _`ApiPlatform`: https://github.com/api-platform/core
194210
.. _`JSON-LD`: http://json-ld.org
195211
.. _`Hydra Core Vocabulary`: http://hydra-cg.com
212+
.. _`Data URIs`: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs

setup/bundles.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ PHPUnit test report:
6969

7070
.. code-block:: terminal
7171
72-
$ phpunit
72+
# this command is available after running "composer require --dev symfony/phpunit-bridge"
73+
$ ./bin/phpunit
7374
7475
# ... PHPUnit output
7576

setup/flex.rst

Lines changed: 79 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Symfony application by executing the following command:
129129
Upgrading Existing Applications to Flex
130130
---------------------------------------
131131

132-
Using Symfony Flex is optional, even in Symfony 4, where Flex will be used by
132+
Using Symfony Flex is optional, even in Symfony 4, where Flex is used by
133133
default. However, Flex is so convenient and improves your productivity so much
134134
that it's strongly recommended to upgrade your existing applications to it.
135135

@@ -163,41 +163,95 @@ is not enough. You must also upgrade the directory structure to the one shown
163163
above. There's no automatic tool to make this upgrade, so you must follow these
164164
manual steps:
165165

166-
#. Create a new empty Symfony application (``composer create-project
167-
symfony/skeleton my-project-flex``)
166+
#. Install Flex as a dependency of your project:
168167

169-
#. Merge the ``require`` and ``require-dev`` dependencies defined in your
170-
original project's ``composer.json`` file to the ``composer.json`` file of the
171-
new project (don't copy the ``symfony/symfony`` dependency, but add the
172-
relevant components you are effectively using in your project).
168+
.. code-block:: terminal
173169
174-
#. Install the dependencies in the new project executing ``composer update``.
175-
This will make Symfony Flex generate all the configuration files in
176-
``config/packages/``
170+
$ composer require symfony/flex
177171
178-
#. Review the generated ``config/packages/*.yaml`` files and make any needed
179-
changes according to the configuration defined in the
180-
``app/config/config_*.yml`` file of your original project. Beware that this is
181-
the most time-consuming and error-prone step of the upgrade process.
172+
#. If the project's ``composer.json`` file contains ``symfony/symfony`` dependency,
173+
it still depends on the Symfony Standard edition, which is no longer available
174+
in Symfony 4. First, remove this dependency:
182175

183-
#. Move the original parameters defined in ``app/config/parameters.*.yml`` to
184-
the new ``config/services.yaml`` and ``.env`` files depending on your needs.
176+
.. code-block:: terminal
185177
186-
#. Move the original source code from ``src/{App,...}Bundle/`` to ``src/`` and
187-
update the namespaces of every PHP file to be ``App\...`` (advanced IDEs can do
188-
this automatically).
178+
$ composer remove symfony/symfony
189179
190-
#. Move the original templates from ``app/Resources/views/`` to ``templates/``
191-
and ``app/Resources/translations`` to ``translations/``. There may be a few
192-
other files you need to move into a new location.
180+
Now you must add in ``composer.json`` all the Symfony dependencies required
181+
by your project. A quick way to do that is to add all the components that
182+
were included in the previous ``symfony/symfony`` dependency and later you
183+
can remove anything you don't really need:
193184

194-
#. Make any other change needed by your application. For example, if your
195-
original ``web/app_*.php`` front controllers were customized, add those changes
196-
to the new ``public/index.php`` controller.
185+
.. code-block:: terminal
186+
187+
$ composer require annotations assets doctrine twig profiler \
188+
logger mailer form fixtures security translation validator
189+
190+
#. If the project's ``composer.json`` file doesn't contain ``symfony/symfony``
191+
dependency, it already defines its dependencies explicitly, as required by
192+
Flex. You just need to reinstall all dependencies to force Flex generate the
193+
config files in ``config/``, which is the most tedious part of the upgrade
194+
process:
195+
196+
.. code-block:: terminal
197+
198+
$ rm -fr /vendor/*
199+
$ composer install
200+
201+
#. No matter which of the previous steps you followed. At this point, you'll have
202+
lots of new config files in ``config/``. They contain the default config
203+
defined by Symfony, so you must check your original files in ``app/config/``
204+
and make the needed changes in the new files. Flex config doesn't use suffixes
205+
in config files, so the old ``app/config/config_dev.yml`` goes to
206+
``config/packages/dev/*.yaml``, etc.
207+
208+
#. The most important config file is ``app/config/services.yml``, which now is
209+
located at ``config/services.yaml``. Copy the contents of the
210+
`default services.yaml file`_ and then add your own service configuration.
211+
Later you can revisit this file because thanks to Symfony's
212+
:doc:`autowiring feature </service_container/3.3-di-changes>` you can remove
213+
most of the service configuration.
214+
215+
#. Move the rest of the ``app/`` contents as follows (and after that, remove the
216+
``app/`` directory):
217+
218+
* ``app/Resources/views/`` -> ``templates/``
219+
* ``app/Resources/translations/`` -> ``translations/``
220+
* ``app/Resources/<BundleName>/views/`` -> ``templates/<BundleName>/``
221+
* rest of ``app/Resources/`` files -> ``src/Resources/``
222+
223+
#. Move the original PHP source code from ``src/AppBundle/*`` to ``src/``. In
224+
addition to moving the files, update the ``autoload`` and ``autoload-dev``
225+
values of the ``composer.json`` file as `shown in this example`_ to use
226+
``App\`` and ``App\Tests\`` as the application namespaces (advanced IDEs can
227+
do this automatically).
228+
229+
If you used multiple bundles to organize your code, you must reorganize your
230+
code into ``src/``. For example, if you had ``src/UserBundle/Controller/DefaultController.php``
231+
and ``src/ProductBundle/Controller/DefaultController.php``, you could move
232+
them to ``src/Controller/UserController.php`` and ``src/Controller/ProductController.php``.
233+
234+
#. Move the public assets, such as images or compiled CSS/JS files, from
235+
``src/AppBundle/Resources/public/`` to ``public/`` (e.g. ``public/images/``).
236+
237+
Move the source of the assets (e.g. the SCSS files) to ``assets/`` and use
238+
:doc:`Webpack Encore </frontend>` to manage and compile them.
239+
240+
#. Create the new ``public/index.php`` front controller
241+
`copying Symfony's index.php source`_ and, if you made any customization in
242+
your ``web/app.php`` and ``web/app_dev.php`` files, copy those changes into
243+
the new file. You can now remove the old ``web/`` dir.
244+
245+
#. Update the ``bin/console`` script `copying Symfony's bin/console source`_
246+
and changing anything according to your original console script.
197247

198248
.. _`Symfony Flex`: https://github.com/symfony/flex
199249
.. _`Symfony Installer`: https://github.com/symfony/symfony-installer
200250
.. _`Symfony Standard Edition`: https://github.com/symfony/symfony-standard
201251
.. _`Main recipe repository`: https://github.com/symfony/recipes
202252
.. _`Contrib recipe repository`: https://github.com/symfony/recipes-contrib
203253
.. _`Symfony Recipes documentation`: https://github.com/symfony/recipes/blob/master/README.rst
254+
.. _`default services.yaml file`: https://github.com/symfony/recipes/blob/master/symfony/framework-bundle/3.3/config/services.yaml
255+
.. _`shown in this example`: https://github.com/symfony/skeleton/blob/8e33fe617629f283a12bbe0a6578bd6e6af417af/composer.json#L24-L33
256+
.. _`copying Symfony's index.php source`: https://github.com/symfony/recipes/blob/master/symfony/framework-bundle/3.3/public/index.php
257+
.. _`copying Symfony's bin/console source`: https://github.com/symfony/recipes/tree/master/symfony/console/3.3

setup/upgrade_major.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ Now, you can start fixing the notices:
7575

7676
.. code-block:: text
7777
78-
$ phpunit
78+
# this command is available after running "composer require --dev symfony/phpunit-bridge"
79+
$ ./bin/phpunit
7980
...
8081
8182
OK (10 tests, 20 assertions)

testing.rst

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ Symfony integrates with an independent library - called PHPUnit - to give
1515
you a rich testing framework. This article won't cover PHPUnit itself, but
1616
it has its own excellent `documentation`_.
1717

18-
.. note::
18+
First, install PHPUnit support in your Symfony application running this command:
19+
20+
.. code-block:: terminal
1921
20-
It's recommended to use the latest stable PHPUnit version, `installed as
21-
PHAR`_.
22+
$ composer require --dev phpunit
2223
2324
Each test - whether it's a unit test or a functional test - is a PHP class
2425
that should live in the ``tests/`` directory of your application. If you follow
@@ -27,7 +28,7 @@ command:
2728

2829
.. code-block:: terminal
2930
30-
$ phpunit
31+
$ ./bin/phpunit
3132
3233
PHPUnit is configured by the ``phpunit.xml.dist`` file in the root of your
3334
Symfony application.
@@ -99,16 +100,13 @@ Running tests for a given file or directory is also very easy:
99100
.. code-block:: terminal
100101
101102
# run all tests of the application
102-
$ phpunit
103+
$ ./bin/phpunit
103104
104-
# run all tests in the Util directory
105-
$ phpunit tests/Util
105+
# run all tests in the Util/ directory
106+
$ ./bin/phpunit tests/Util
106107
107108
# run tests for the Calculator class
108-
$ phpunit tests/Util/CalculatorTest.php
109-
110-
# run all tests for the entire Bundle
111-
$ phpunit tests/
109+
$ ./bin/phpunit tests/Util/CalculatorTest.php
112110
113111
.. index::
114112
single: Tests; Functional tests
@@ -926,4 +924,3 @@ Learn more
926924

927925
.. _`$_SERVER`: http://php.net/manual/en/reserved.variables.server.php
928926
.. _`documentation`: https://phpunit.de/manual/current/en/
929-
.. _`installed as PHAR`: https://phpunit.de/manual/current/en/installation.html#installation.phar

0 commit comments

Comments
 (0)