Symfony2 LTS:如何从 2.3 升级到 2.7?
Symfony2 LTS: how to upgrade from 2.3 to 2.7?
Symfony 2.7 是 released on 30th April 2015 and is the current LTS (Long Term Support) version after the 2.3 version。 Symfony 2.3 的这些版本的维护将于 2016 年 5 月结束,Symfony 2.7 的维护将于 2018 年 5 月结束。两个版本的维护结束后一年内将发布安全修复程序。
根据 Massimiliano Arione in the announce comments 的建议,从 Symfony 2.7 升级到 2.3 需要做哪些更改,而无需检查所有次要升级(2.3 → 2.4、2.4 → 2.5 等)?
正如 Med 在评论中提醒的那样,Symfony2 开发人员已尝试在 2.x
分支中保持向后兼容性。所以只要你以后不想切换到 3.0
分支,你可以忽略 2.3 和 2.7 之间的变化,因为它们大多是弃用变化。
为了将您的应用程序从 Symfony 2.3 升级到 Symfony 2.7,您必须更新您的 composer.json 文件:
([…]
表示代码不变)
旧(2.3)版本:
{
[…]
"autoload": {
"psr-0": { "": "src/" }
},
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.3.*",
"doctrine/orm": "~2.2,>=2.2.3,<2.5",
"doctrine/dbal": "<2.5",
"doctrine/doctrine-bundle": "~1.2",
"twig/extensions": "1.0.*",
"symfony/assetic-bundle": "~2.3",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"sensio/distribution-bundle": "~2.3",
"sensio/framework-extra-bundle": "~3.0,>=3.0.2",
"sensio/generator-bundle": "~2.3",
"incenteev/composer-parameter-handler": "~2.0"
},
"scripts": {
"post-install-cmd": [
"Incenteev\ParameterHandler\ScriptHandler::buildParameters",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::prepareDeploymentTarget"
],
"post-update-cmd": [
"Incenteev\ParameterHandler\ScriptHandler::buildParameters",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::prepareDeploymentTarget"
]
},
[…]
"minimum-stability": "stable",
"extra": {
[…]
"incenteev-parameters": {
"file": "app/config/parameters.yml"
},
"branch-alias": {
"dev-master": "2.3-dev"
}
}
}
新(2.7)版本:
{
[…]
"autoload": {
"psr-4": { "": "src/", "SymfonyStandard\": "app/SymfonyStandard/" }
},
"require": {
"php": ">=5.3.9",
"symfony/symfony": "2.7.*",
"doctrine/orm": "^2.4.8",
"doctrine/doctrine-bundle": "~1.4",
"symfony/assetic-bundle": "~2.3",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"sensio/distribution-bundle": "~4.0",
"sensio/framework-extra-bundle": "^3.0.2",
"incenteev/composer-parameter-handler": "~2.0"
},
"require-dev": {
"sensio/generator-bundle": "~2.3",
"symfony/phpunit-bridge": "~2.7"
},
"scripts": {
"post-install-cmd": [
"Incenteev\ParameterHandler\ScriptHandler::buildParameters",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::removeSymfonyStandardFiles",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::prepareDeploymentTarget"
],
"post-update-cmd": [
"Incenteev\ParameterHandler\ScriptHandler::buildParameters",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::removeSymfonyStandardFiles",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::prepareDeploymentTarget"
]
},
[…]
"extra": {
[…]
"symfony-assets-install": "relative",
[…]
"branch-alias": {
"dev-master": "2.7-dev"
}
}
}
总结:
- Symfony 版本已更新
使用 PSR-4
代替 PSR-0
twig/extensions
默认没有安装,如果使用Twig扩展可能需要添加
sensio/generator-bundle
仅在 dev
环境中需要
scripts
部分已更新
"minimum-stability": "stable",
已删除
更新 composer.json 文件后,您必须更新依赖项:
composer update --prefer-dist -vv
那么您可能需要刷新缓存:
php app/console cache:clear --env=dev
注意:我使用了以下命令来获取 composer.json 文件:
# create Symfony "2.3.*" project in the "2.3" directory
composer create-project symfony/framework-standard-edition "2.3" "2.3.*" --no-interaction -v
# create Symfony "2.7.*" project in the "2.7" directory
composer create-project symfony/framework-standard-edition "2.7" "2.7.*" --no-interaction -v
# compare the Symfony 2.3 and 2.7 composer.json files
diff -u 2.3/composer.json 2.7/composer.json
(我们使用 2.3.*
而不是 2.3
因为我们想要最后一个版本(2.3.31
今天)而不是初始版本(2.3.0
))
差异在GitHub也可用,但是Symfony 2.3的composer.json文件已经更新了多次,所以它可能与你的文件。
Symfony 2.7 是 released on 30th April 2015 and is the current LTS (Long Term Support) version after the 2.3 version。 Symfony 2.3 的这些版本的维护将于 2016 年 5 月结束,Symfony 2.7 的维护将于 2018 年 5 月结束。两个版本的维护结束后一年内将发布安全修复程序。
根据 Massimiliano Arione in the announce comments 的建议,从 Symfony 2.7 升级到 2.3 需要做哪些更改,而无需检查所有次要升级(2.3 → 2.4、2.4 → 2.5 等)?
正如 Med 在评论中提醒的那样,Symfony2 开发人员已尝试在 2.x
分支中保持向后兼容性。所以只要你以后不想切换到 3.0
分支,你可以忽略 2.3 和 2.7 之间的变化,因为它们大多是弃用变化。
为了将您的应用程序从 Symfony 2.3 升级到 Symfony 2.7,您必须更新您的 composer.json 文件:
([…]
表示代码不变)
旧(2.3)版本:
{
[…]
"autoload": {
"psr-0": { "": "src/" }
},
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.3.*",
"doctrine/orm": "~2.2,>=2.2.3,<2.5",
"doctrine/dbal": "<2.5",
"doctrine/doctrine-bundle": "~1.2",
"twig/extensions": "1.0.*",
"symfony/assetic-bundle": "~2.3",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"sensio/distribution-bundle": "~2.3",
"sensio/framework-extra-bundle": "~3.0,>=3.0.2",
"sensio/generator-bundle": "~2.3",
"incenteev/composer-parameter-handler": "~2.0"
},
"scripts": {
"post-install-cmd": [
"Incenteev\ParameterHandler\ScriptHandler::buildParameters",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::prepareDeploymentTarget"
],
"post-update-cmd": [
"Incenteev\ParameterHandler\ScriptHandler::buildParameters",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::prepareDeploymentTarget"
]
},
[…]
"minimum-stability": "stable",
"extra": {
[…]
"incenteev-parameters": {
"file": "app/config/parameters.yml"
},
"branch-alias": {
"dev-master": "2.3-dev"
}
}
}
新(2.7)版本:
{
[…]
"autoload": {
"psr-4": { "": "src/", "SymfonyStandard\": "app/SymfonyStandard/" }
},
"require": {
"php": ">=5.3.9",
"symfony/symfony": "2.7.*",
"doctrine/orm": "^2.4.8",
"doctrine/doctrine-bundle": "~1.4",
"symfony/assetic-bundle": "~2.3",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"sensio/distribution-bundle": "~4.0",
"sensio/framework-extra-bundle": "^3.0.2",
"incenteev/composer-parameter-handler": "~2.0"
},
"require-dev": {
"sensio/generator-bundle": "~2.3",
"symfony/phpunit-bridge": "~2.7"
},
"scripts": {
"post-install-cmd": [
"Incenteev\ParameterHandler\ScriptHandler::buildParameters",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::removeSymfonyStandardFiles",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::prepareDeploymentTarget"
],
"post-update-cmd": [
"Incenteev\ParameterHandler\ScriptHandler::buildParameters",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::removeSymfonyStandardFiles",
"Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::prepareDeploymentTarget"
]
},
[…]
"extra": {
[…]
"symfony-assets-install": "relative",
[…]
"branch-alias": {
"dev-master": "2.7-dev"
}
}
}
总结:
- Symfony 版本已更新 使用
PSR-4
代替PSR-0
twig/extensions
默认没有安装,如果使用Twig扩展可能需要添加sensio/generator-bundle
仅在dev
环境中需要scripts
部分已更新"minimum-stability": "stable",
已删除
更新 composer.json 文件后,您必须更新依赖项:
composer update --prefer-dist -vv
那么您可能需要刷新缓存:
php app/console cache:clear --env=dev
注意:我使用了以下命令来获取 composer.json 文件:
# create Symfony "2.3.*" project in the "2.3" directory
composer create-project symfony/framework-standard-edition "2.3" "2.3.*" --no-interaction -v
# create Symfony "2.7.*" project in the "2.7" directory
composer create-project symfony/framework-standard-edition "2.7" "2.7.*" --no-interaction -v
# compare the Symfony 2.3 and 2.7 composer.json files
diff -u 2.3/composer.json 2.7/composer.json
(我们使用 2.3.*
而不是 2.3
因为我们想要最后一个版本(2.3.31
今天)而不是初始版本(2.3.0
))
差异在GitHub也可用,但是Symfony 2.3的composer.json文件已经更新了多次,所以它可能与你的文件。