Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit79e0d0d

Browse files
committed
Merge branch '2.3' into 2.7
* 2.3: Update tools.rst [#5894] Minor tweaks and removing the todo sections for now Added a new section of tips and tricks to upgrade bundles to Symfony 3.0 Fixed a lot of issues reported by Wouter Completed the section "Test your Bundle in Symfony 3" Completed the section "Look for Deprecations and Fix Them" Completed "Allow to Install Symfony 3 Components" section Added an article to explain how to upgrade third-party bundles to Symfony 3
2 parents2f9866c +812be2c commit79e0d0d

File tree

4 files changed

+198
-1
lines changed

4 files changed

+198
-1
lines changed

‎cookbook/deployment/tools.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ specifically tailored to the requirements of Symfony.
8282
This Python-based library provides a basic suite of operations for executing
8383
local or remote shell commands and uploading/downloading files.
8484

85+
`Deployer`_
86+
This is another native PHP rewrite of Capistrano, with some ready recipes for
87+
Symfony.
88+
8589
Bundles
8690
There are some `bundles that add deployment features`_ directly into your
8791
Symfony console.
@@ -200,4 +204,4 @@ other potential things like pushing assets to a CDN (see `Common Post-Deployment
200204
.. _`Memcached`:http://memcached.org/
201205
.. _`Redis`:http://redis.io/
202206
.. _`Symfony plugin`:https://github.com/capistrano/symfony/
203-
207+
.. _`Deployer`:http://deployer.org/

‎cookbook/map.rst.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@
243243
* :doc:`/cookbook/upgrade/patch_version`
244244
* :doc:`/cookbook/upgrade/minor_version`
245245
* :doc:`/cookbook/upgrade/major_version`
246+
* :doc:`/cookbook/upgrade/bundles`
246247

247248
* :doc:`/cookbook/validation/index`
248249

‎cookbook/upgrade/bundles.rst

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
..index::
2+
single: Upgrading; Bundle; Major Version
3+
4+
Upgrading a Third-Party Bundle for a Major Symfony Version
5+
==========================================================
6+
7+
Symfony 3 was released on November 2015. Although this version doesn't contain
8+
any new feature, it removes all the backwards compatibility layers included in
9+
the previous 2.8 version. If your bundle uses any deprecated feature and it's
10+
published as a third-party bundle, applications upgrading to Symfony 3 will no
11+
longer be able to use it.
12+
13+
Allowing to Install Symfony 3 Components
14+
----------------------------------------
15+
16+
Most third-party bundles define their Symfony dependencies using the ``~2.N`` or
17+
``^2.N`` constraints in the ``composer.json`` file. For example:
18+
19+
..code-block::json
20+
21+
{
22+
"require": {
23+
"symfony/framework-bundle":"~2.3",
24+
"symfony/finder":"~2.3",
25+
"symfony/validator":"~2.3"
26+
}
27+
}
28+
29+
These constraints prevent the bundle from using Symfony 3 components, so it makes
30+
it impossible to install it in a Symfony 3 based application. This issue is very
31+
easy to solve thanks to the flexibility of Composer dependencies constraints.
32+
Just replace ``~2.N`` by ``~2.N|~3.0`` (or ``^2.N`` by ``^2.N|~3.0``).
33+
34+
The above example can be updated to work with Symfony 3 as follows:
35+
36+
..code-block::json
37+
38+
{
39+
"require": {
40+
"symfony/framework-bundle":"~2.3|~3.0",
41+
"symfony/finder":"~2.3|~3.0",
42+
"symfony/validator":"~2.3|~3.0"
43+
}
44+
}
45+
46+
..tip::
47+
48+
Another common version constraint found on third-party bundles is ``>=2.N``.
49+
You should avoid using that constraint because it's too generic (it means
50+
that your bundle is compatible with any future Symfony version). Use instead
51+
``~2.N|~3.0`` or ``^2.N|~3.0`` to make your bundle future-proof.
52+
53+
Looking for Deprecations and Fix Them
54+
-------------------------------------
55+
56+
Besides allowing users to use your bundle with Symfony 3, your bundle must stop using
57+
any feature deprecated by the 2.8 version because they are removed in 3.0 (you'll get
58+
exceptions or PHP errors). The easiest way to detect deprecations is to install
59+
the `symfony/phpunit-bridge package`_ and then run the test suite.
60+
61+
First, install the component as a ``dev`` dependency of your bundle:
62+
63+
..code-block::bash
64+
65+
$ composer require --dev symfony/phpunit-bridge
66+
67+
Then, run your test suite and look for the deprecation list displayed after the
68+
PHPUnit test report:
69+
70+
..code-block::bash
71+
72+
$ phpunit
73+
74+
# ... PHPUnit output
75+
76+
Remaining deprecation notices (3)
77+
78+
The"pattern" optionin file ... is deprecated since version 2.2 and will be
79+
removedin 3.0. Use the"path" optionin the route definition instead ...
80+
81+
Twig Function"form_enctype" is deprecated. Use"form_start" insteadin ...
82+
83+
The Symfony\Component\Security\Core\SecurityContext class is deprecated since
84+
version 2.6 and will be removedin 3.0. Use ...
85+
86+
Fix the reported deprecations, run the test suite again and repeat the process
87+
until no deprecation usage is reported.
88+
89+
Useful Resources
90+
~~~~~~~~~~~~~~~~
91+
92+
There are several resources that can help you detect, understand and fix the use
93+
of deprecated features:
94+
95+
`Official Symfony Guide to Upgrade from 2.x to 3.0`_
96+
The full list of changes required to upgrade to Symfony 3.0 and grouped
97+
by component.
98+
`SensioLabs DeprecationDetector`_
99+
It runs a static code analysis against your project's source code to find
100+
usages of deprecated methods, classes and interfaces. It works for any PHP
101+
application, but it includes special detectors for Symfony applications,
102+
where it can also detect usages of deprecated services.
103+
`Symfony Upgrade Fixer`_
104+
It analyzes Symfony projects to find deprecations. In addition it solves
105+
automatically some of them thanks to the growing list of supported "fixers".
106+
107+
Testing your Bundle in Symfony 3
108+
--------------------------------
109+
110+
Now that your bundle has removed all deprecations, it's time to test it for real
111+
in a Symfony 3 application. Assuming that you already have a Symfony 3 application,
112+
you can test the updated bundle locally without having to install it through
113+
Composer.
114+
115+
If your operating system supports symbolic links, just point the appropriate
116+
vendor directory to your local bundle root directory:
117+
118+
..code-block::bash
119+
120+
$ ln -s /path/to/your/local/bundle/ vendor/you-vendor-name/your-bundle-name
121+
122+
If your operating system doesn't support symbolic links, you'll need to copy
123+
your local bundle directory into the appropriate directory inside ``vendor/``.
124+
125+
Update the Travis CI Configuration
126+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
127+
128+
In addition to running tools locally, it's recommended to set-up Travis CI service
129+
to run the tests of your bundle using different Symfony configurations. Use the
130+
following recommended configuration as the starting point of your own configuration:
131+
132+
..code-block::yaml
133+
134+
language:php
135+
sudo:false
136+
php:
137+
-5.3
138+
-5.6
139+
-7.0
140+
141+
matrix:
142+
include:
143+
-php:5.3.3
144+
env:COMPOSER_FLAGS='--prefer-lowest --prefer-stable' SYMFONY_DEPRECATIONS_HELPER=weak
145+
-php:5.6
146+
env:SYMFONY_VERSION='2.3.*'
147+
-php:5.6
148+
env:DEPENDENCIES='dev' SYMFONY_VERSION='2.8.*@dev'
149+
-php:5.6
150+
env:SYMFONY_VERSION='3.0.*@dev'
151+
152+
before_install:
153+
-composer self-update
154+
-if [ "$DEPENDENCIES" == "dev" ]; then perl -pi -e 's/^}$/,"minimum-stability":"dev"}/' composer.json; fi;
155+
-if [ "$SYMFONY_VERSION" != "" ]; then composer --no-update require symfony/symfony:${SYMFONY_VERSION}; fi;
156+
157+
install:composer update $COMPOSER_FLAGS
158+
159+
script:phpunit
160+
161+
Updating your Code to Support Symfony 2.x and 3.x at the Same Time
162+
------------------------------------------------------------------
163+
164+
The real challenge of adding Symfony 3 support for your bundles is when you want
165+
to support both Symfony 2.x and 3.x simultaneously using the same code. There
166+
are some edge cases where you'll need to deal with the API differences.
167+
168+
Before diving into the specifics of the most common edge cases, the general
169+
recommendation is to **not rely on the Symfony Kernel version** to decide which
170+
code to use::
171+
172+
if (Kernel::VERSION_ID <= 20800) {
173+
// code for Symfony 2.x
174+
} else {
175+
// code for Symfony 3.x
176+
}
177+
178+
Instead of checking the Symfony Kernel version, check the version of the specific
179+
component. For example, the OptionsResolver API changed in its 2.6 version by
180+
adding a ``setDefined()`` method. The recommended check in this case would be::
181+
182+
if (!method_exists('Symfony\Component\OptionsResolver\OptionsResolver', 'setDefined')) {
183+
// code for the old OptionsResolver API
184+
} else {
185+
// code for the new OptionsResolver API
186+
}
187+
188+
.. _`symfony/phpunit-bridge package`:https://github.com/symfony/phpunit-bridge
189+
.. _`Official Symfony Guide to Upgrade from 2.x to 3.0`:https://github.com/symfony/symfony/blob/2.8/UPGRADE-3.0.md
190+
.. _`SensioLabs DeprecationDetector`:https://github.com/sensiolabs-de/deprecation-detector
191+
.. _`Symfony Upgrade Fixer`:https://github.com/umpirsky/Symfony-Upgrade-Fixer

‎cookbook/upgrade/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ There are three types of upgrades, all needing a little different preparation:
1616
/cookbook/upgrade/patch_version
1717
/cookbook/upgrade/minor_version
1818
/cookbook/upgrade/major_version
19+
/cookbook/upgrade/bundles

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp