2015-06-01 104 views
4

Symfony 2.7是released on 30th April 2015并且是current LTS (Long Term Support) version after the 2.3 version。这些版本的维护将于2016年5月结束Symfony 2.3和2018年5月Symfony 2.7。安全修复将在两个版本的维护结束后的一年内发布。Symfony2 LTS:如何从2.3升级到2.7?

正如Massimiliano Arione in the announce comments所建议的那样,从Symfony 2.3升级到2.7需要做什么改动,而不必检查所有次要升级(2.3→2.4,2.4→2.5等)?

+2

2.7不兼容2.3,它弃用了一些类和方法。所以把2.7而不是2.3放在你的作曲家里应该没问题 – Med

+0

Med:你说的对,但有一些例外:https://github.com/symfony/symfony/issues/14377#issuecomment-94386014 https:// github.com/symfony/symfony/blob/2.7/UPGRADE-2.6.md#known-backwards-compatibility-breaks –

+0

如果您担心这些例外情况,您有2个选择,请等待次要版本更正这些例外情况,或修改你的代码。也许尝试对一个重复的env进行升级并运行一些测试以确保您的应用程序仍然正常 – Med

回答

25

正如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是不是默认安装的,则可能需要,如果你使用的树枝扩展添加它
  • sensio/generator-bundle只需要dev环境
  • scripts部分已更新
  • "minimum-stability": "stable",已被删除

一旦你已经更新了composer.json文件,你必须更新依赖关系:

composer update --prefer-dist -vv 

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

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

注意:我使用了以下公司mmand为了获得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的文件可以是composer.json。3已多次更新,因此它可能与您的文件不同。

+1

在新版本(2.7)中,您应该将php要求更改为'“php”:“> = 5.3.9”',因为'“symfony/symfony”:“2.7。*”包需要它。 –

+1

@DaniSancas你是对的,但我不明白为什么'5.3.3'在[symfony-standard]中使用(https://github.com/symfony/symfony-standard/blob/2.7/composer.json )和'5.3.9'在[symfony]中使用(https://github.com/symfony/symfony/blob/2.7/composer.json)。 –

+0

也许他们忘记了改变它:我认为在第一次alpha发布之前很久以前我就已经看到了Symfony 2.7的'5.3.3'要求。也许他们在开发过程中引入了以前出乎意料的东西,迫使他们使用'5.3.9',然后他们忘了在其他地方改变它......但仅仅是一种理论,我不知道为什么。 –