gpt4 book ai didi

Symfony LTS : how to upgrade from 2. 8 到 3.4?

转载 作者:行者123 更新时间:2023-12-04 17:15:14 25 4
gpt4 key购买 nike

Symfony 2.8 是 2.x 的最后一个版本分支和之前的 LTS。

Symfony 3.4 是 3.x 的最后一个版本分支和当前的 LTS。

2.8 升级 Symfony 需要哪些步骤至 3.4并切换到最后一个 LTS?

最佳答案

准备升级

检查 composer.json 中列出的所有依赖项和包已经发布了一个与 Symfony 3.4 兼容的版本,你可以通过在 Packagist 上搜索每个包来做到这一点,例如 EasyAdmin与 Symfony 3 兼容,因为 requires 中的依赖项不限于 Symfony 2(我们会看到类似 symfony/*: ~2.3 的东西)。如果其中一个依赖项与 Symfony 3 不兼容,则您必须找到替换包或修补这些库。

Composer .json

为了从 Symfony 升级您的应用程序 2.8到 Symfony 3.4您必须通过更改 composer.json 文件来更新您的依赖项:

( […] 表示代码不变)

旧 ( 2.8 ) 版本:

{
[…]
"autoload-dev": {
"files": [ "vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php" ]
},
"require": {
"php": ">=5.3.9",
"doctrine/doctrine-bundle": "~1.4",
"doctrine/orm": "^2.4.8",
"incenteev/composer-parameter-handler": "~2.0",
"sensio/distribution-bundle": "~4.0",
"sensio/framework-extra-bundle": "^3.0.2",
"symfony/monolog-bundle": "^3.0.2",
"symfony/swiftmailer-bundle": "~2.3,>=2.3.10",
"symfony/symfony": "2.8.*",
"twig/twig": "^1.0||^2.0"
},
"require-dev": {
"sensio/generator-bundle": "~3.0",
"symfony/phpunit-bridge": "~2.7"
},
"config": {
"bin-dir": "bin",
"platform": {
"php": "5.6"
},
"sort-packages": true
},
"extra": {
"symfony-app-dir": "app",
"symfony-web-dir": "web",
"symfony-assets-install": "relative",
[…]
"branch-alias": {
"dev-master": "2.8-dev"
}
}
}

新 ( 3.4 ) 版本:

{
[…]
"autoload-dev": {
"psr-4": { "Tests\\": "tests/" },
"files": [ "vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php" ]
},
"require": {
"php": ">=5.5.9",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/orm": "^2.5",
"incenteev/composer-parameter-handler": "^2.0",
"sensio/distribution-bundle": "^5.0.19",
"sensio/framework-extra-bundle": "^5.0.0",
"symfony/monolog-bundle": "^3.1.0",
"symfony/polyfill-apcu": "^1.0",
"symfony/swiftmailer-bundle": "^2.6.4",
"symfony/symfony": "3.4.*",
"twig/twig": "^1.0||^2.0"
},
"require-dev": {
"sensio/generator-bundle": "^3.0",
"symfony/phpunit-bridge": "^3.0"
},
"config": {
"platform": {
"php": "5.6"
},
"sort-packages": true
},

"extra": {
"symfony-app-dir": "app",
"symfony-bin-dir": "bin",
"symfony-var-dir": "var",
"symfony-web-dir": "web",
"symfony-tests-dir": "tests",
"symfony-assets-install": "relative",
[…]
"branch-alias": {
"dev-master": "3.4-dev"
}
}
}

概括
  • autoload-dev.psr-4已添加(必须使用测试目录的路径更改)
  • Symfony 和依赖项已更新
  • symfony/polyfill-apcu是一个新的依赖
  • extra已更新以使用新的目录结构:var用于临时文件等
  • config.bin-dir已被删除

  • 更多升级详情: → 3.0 , → 3.1 , → 3.2 , → 3.3 , → 3.4

    应用程序/AppKernel.php

    添加 getRootDir并更新 registerContainerConfiguration职能:

    public function getRootDir()
    {
    return __DIR__;
    }

    public function registerContainerConfiguration(LoaderInterface $loader)
    {
    $loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
    }

    缓存和日志

    如果你想把 cachelogsvar/ ,您必须更新您的 app/AppKernel.php通过添加以下几行文件:

    public function getCacheDir()
    {
    return dirname(__DIR__).'/var/cache/'.$this->getEnvironment();
    }
    public function getLogDir()
    {
    return dirname(__DIR__).'/var/logs';
    }

    然后创建 var/目录并放置一个空文件 .gitkeep
    并将这些更改应用于您的 .gitignore文件:

    /var/cache/*
    /var/logs/*
    !var/cache/.gitkeep
    !var/logs/.gitkeep

    另见: What is the new Symfony 3 directory structure?

    最后的步骤

    更新 composer.json 文件后,您必须更新依赖项:

    composer update

    然后你可能需要刷新缓存:

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

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

    # create Symfony "2.8.*" project in the "2.8" directory
    composer create-project symfony/framework-standard-edition "2.8" "2.8.*" --no-interaction -v
    # create Symfony "3.4.*" project in the "3.4" directory
    composer create-project symfony/framework-standard-edition "3.4" "3.4.*" --no-interaction -v
    # compare the Symfony 2.8 and 3.4 composer.json files
    diff -u 2.8/composer.json 3.4/composer.json

    差异可在 GitHub 获得也。

    奖金: enable autowiring of services .

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

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com