如何正确更新 Symfony3.3 到 Symfony4.X?

How to properly update Symfony3.3 to Symfony4.X?

解释:

我无法将 symfony3 更新到 symfony4,无论我如何修复它们,它都会抛出各种不同的错误。

我尝试过的:

我正在关注 the official documentation 的重大更新,并且我已确保我有 0 个弃用。

我更新了我的 composer.json 如下:

{
    "...": "...",

    "require": {
        "symfony/symfony": "^4.0",
    },
    "...": "..."
}

错误:

Your requirements could not be resolved to an installable set of packages.

Problem 1 - Conclusion: remove symfony/assetic-bundle v2.8.2 - Conclusion: don't install symfony/assetic-bundle v2.8.2 - Conclusion: don't install symfony/symfony v4.0.3 - Conclusion: don't install symfony/symfony v4.0.2 - Installation request for symfony/assetic-bundle (locked at v2.8.2, required as ^2.8) -> satisfiable by symfony/assetic-bundle[v2.8.2].

现在,我继续卸载 symfony/assetic-bundle,但它给出了以下相同的错误:

然后当没有任何东西可以删除时(此时非常令人沮丧),它只是说:

Problem 1 - Conclusion: don't install symfony/symfony v4.0.3 - Conclusion: don't install symfony/symfony v4.0.2 - Conclusion: don't install symfony/symfony v4.0.1 - sensio/generator-bundle v3.1.7 requires symfony/yaml [...]

  • Installation request for sensio/generator-bundle (locked at v3.1.7, required as ^3.0) -> satisfiable by sensio/generator-bundle[v3.1.7].

问题:

如何正确解决错误(如上所示)以及如何正确将 symfony 更新到 4.0?

composer.json 片段:

"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": "^3.0.2",
        "symfony/monolog-bundle": "^3.1.0",
        "symfony/polyfill-apcu": "^1.0",
        "symfony/swiftmailer-bundle": "^2.3.10",
        "symfony/symfony": "^4.0",
        "twig/twig": "^1.0||^2.0"
    },
    "require-dev": {
        "sensio/generator-bundle": "3.1.7",
        "symfony/phpunit-bridge": "^3.0"
    },

在这个阶段,我创建了 Symfony4 框架并复制粘贴了我之前项目中的文件。这是一项乏味的任务,因为有些事情确实会发生变化。

以下是可帮助您升级的基本步骤列表:

  1. 关注 Symfony documentation 摆脱代码中可能存在的任何弃用

  2. 创建 Symfony4 框架

  3. 将您的特定文件复制粘贴到它们各自的位置。
  4. "Bundles" 在某种意义上不存在,所以您的目录应该是这样的:src/Controllerssrc/Services
  5. 更新您的 namespaces,默认情况下它们应该是 App\ControllerApp\Services
  6. 数据库连接信息放在根目录下的 .env 文件中。

随时编辑此 post 以提供更多有价值的信息。