Symfony2 LTS:如何从 2.3 升级到 2.7? [英] Symfony2 LTS: how to upgrade from 2.3 to 2.7?

查看:22
本文介绍了Symfony2 LTS:如何从 2.3 升级到 2.7?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Symfony 2.7 于 2015 年 4 月 30 日发布,是 2.3 版本之后的当前 LTS(长期支持)版本.Symfony 2.3 的这些版本的维护将于 2016 年 5 月结束,Symfony 2.7 的维护将于 2018 年 5 月结束.两个版本的安全修复程序将在维护结束后的一年内发布.

Symfony 2.7 was released on 30th April 2015 and is the current LTS (Long Term Support) version after the 2.3 version. Maintenance for these versions will end on May 2016 for Symfony 2.3 and May 2018 for Symfony 2.7. Security fixes will be released during one year after end of maintenance for both versions.

正如 Massimiliano Arione 在公告评论中所建议的,从 Symfony 2.3 升级到 2.7 需要哪些更改,而无需检查所有次要升级(2.3 → 2.4、2.4 → 2.5 等)?

As suggested by Massimiliano Arione in the announce comments, what are the changes required to upgrade from Symfony 2.3 from 2.7 without having to check all the minor upgrades (2.3 → 2.4, 2.4 → 2.5, etc.)?

推荐答案

正如 Med 在评论中提醒的那样,Symfony2 开发人员已经尝试在 2.x 分支中保持向后兼容性.所以只要以后不想切换到3.0分支,可以忽略2.3和2.7之间的变化,因为它们大多是弃用的变化.

As reminded by Med in a comment, Symfony2 developers have tried to keep backward compatibility in the 2.x branch. So as long as you don't want to switch to the 3.0 branch later, you can ignore the changes between 2.3 and 2.7 because they are mostly deprecation changes.

为了将您的应用程序从 Symfony 2.3 升级到 Symfony 2.7,您必须更新您的 composer.json 文件:

In order to upgrade you app from Symfony 2.3 to Symfony 2.7 you'll have to update your composer.json file:

([…] 表示代码不变)

旧(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", 已被移除
  • Symfony version is updated
  • PSR-4 is used instead of PSR-0
  • twig/extensions is not installed by default, you may need to add it if you use Twig extensions
  • sensio/generator-bundle is required only in dev environment
  • scripts part has been updated
  • "minimum-stability": "stable", has been removed

一旦您更新了 composer.json 文件,您就必须更新依赖项:

Once you have updated your composer.json file, you have to update the dependencies:

composer update --prefer-dist -vv

那么你可能需要刷新缓存:

Then you may need to flush the cache:

php app/console cache:clear --env=dev

注意:我使用以下命令来获取 composer.json 文件:

Note: I used the following command in order to get the composer.json files:

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

(we use 2.3.* and not 2.3 because we want the last version (2.3.31 today) and not the initial release (2.3.0))

差异也可以在 GitHub 上找到,但是 composer.json 文件已经更新多次,所以可能和你的文件不一样.

The diff is available at GitHub too, but the composer.json file of Symfony 2.3 has been updated multiple times, so it may be different from your file.

这篇关于Symfony2 LTS:如何从 2.3 升级到 2.7?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆