Symfony2 LTS : how to upgrade from 2. 3 到 2.7?

标签 symfony upgrade symfony-2.3 symfony-2.7

Symfony 2.7 是 released on 30th April 2015current 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.3 从 2.7 升级而无需检查所有次要升级(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文件已经更新了多次,所以可能和你的文件不一样。

    关于Symfony2 LTS : how to upgrade from 2. 3 到 2.7?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30570276/

    相关文章:

    symfony - "Remember me"使用自定义用户提供程序、用户实体等时测试失败

    javascript - 使用 Symfony 和 Twig 从 href 中的外部 JavaScript 文件调用函数

    php - 如何从 Symfony 的 HttpFoundation 组件检索基本身份验证凭据?

    mysql - 如何解决 Doctrine 中出现的异常(exception)(Symfony 4)?

    python - 如何从我的虚拟环境中更新/升级 pip 本身?

    ruby-on-rails - 我应该升级 - jaunty 9.0.4 服务器 - 因为它不是 LTS?

    php - where查询+主义

    PHP:Yii1 到 Yii2 升级

    php - Symfony 2.3 无法使用 php composer.phar update 删除文件

    php - 如何从 Symfony2 中的 PUT 请求获取参数?