首页 文章

Symfony 2.8到3.0迁移

提问于
浏览
0

我想将 symfony 2.8 项目升级到 3.0 ,我将 composer.json 中的版本更改为 3.0.* 但是在完成作曲家更新后,我在控制台中出现以下错误:

[RuntimeException]执行“'cache:clear --no-warmup'”命令时发生错误:PHP致命错误:/ var / www / html / t /中找不到类'Symfony \ Component \ HttpKernel \ Kernel'第6行的EcoPro / app / AppKernel.php

1 回答

  • 1

    听起来你的代码无法从Symfony找到Kernel类 . 既然它应该仍然存在,正如你在_1273166中看到的那样,我认为在你的更新期间出了问题 .

    我建议先运行 composer diagnose ,看看作曲家本身是否是最新的,你的 composer.json 在语法上是否有效 . 下一步,您应该通过运行 composer show 来验证依赖项的当前版本 . 输出应该如下所示:

    $ composer show
    doctrine/annotations                 v1.2.7  Docblock Annotations Parser
    doctrine/cache                       v1.5.1  Caching library offering an object-oriented API for many cache backends
    doctrine/collections                 v1.3.0  Collections Abstraction library
    doctrine/common                      v2.5.1  Common Library for Doctrine projects
    doctrine/dbal                        v2.5.2  Database Abstraction Layer
    doctrine/doctrine-bundle             1.6.0   Symfony DoctrineBundle
    doctrine/doctrine-cache-bundle       1.2.2   Symfony Bundle for Doctrine Cache
    doctrine/inflector                   v1.1.0  Common String Manipulations with regard to casing and singular/plural rules.
    doctrine/instantiator                1.0.5   A small, lightweight utility to instantiate objects in PHP without invoking their constructors
    doctrine/lexer                       v1.0.1  Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
    doctrine/orm                         v2.5.2  Object-Relational-Mapper for PHP
    incenteev/composer-parameter-handler v2.1.2  Composer script handling your ignored parameter file
    jdorn/sql-formatter                  v1.2.17 a PHP SQL highlighting library
    monolog/monolog                      1.17.2  Sends your logs to files, sockets, inboxes, databases and various web services
    paragonie/random_compat              1.1.0   PHP 5.x polyfill for random_bytes() and random_int() from PHP 7
    psr/log                              1.0.0   Common interface for logging libraries
    sensio/distribution-bundle           v5.0.2  Base bundle for Symfony Distributions
    sensio/framework-extra-bundle        v3.0.11 This bundle provides a way to configure your controllers with annotations
    sensio/generator-bundle              v3.0.0  This bundle generates code for you
    sensiolabs/security-checker          v3.0.2  A security checker for your composer.lock
    swiftmailer/swiftmailer              v5.4.1  Swiftmailer, free feature-rich PHP mailer
    symfony/monolog-bundle               v2.8.2  Symfony MonologBundle
    symfony/phpunit-bridge               v2.8.0  Symfony PHPUnit Bridge
    symfony/polyfill-intl-icu            v1.0.0  Symfony polyfill for intl's ICU-related data and classes
    symfony/polyfill-mbstring            v1.0.0  Symfony polyfill for the Mbstring extension
    symfony/polyfill-php56               v1.0.0  Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
    symfony/polyfill-php70               v1.0.0  Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions
    symfony/polyfill-util                v1.0.0  Symfony utilities for portability of PHP codes
    symfony/swiftmailer-bundle           v2.3.9  Symfony SwiftmailerBundle
    symfony/symfony                      v3.0.0  The Symfony PHP framework
    twig/twig                            v1.23.1 Twig, the flexible, fast, and secure template language for PHP
    

    这应该可以帮助您查看更新是否确实有效 . 如果一切看起来都很好,我会走安全路线并将你的代码恢复到2.8,然后像下面解释的那样进行更新,而不是更改composer.json!

    首先确保修复了现有应用程序中的所有弃用 . 您可以使用UPGRADE-document作为参考,但也可以运行测试和check the logs for deprecated calls . 使用3.3会变得更容易,因为这些版本有一个单独的deprecation-log,您可以在 var/log 中找到其他日志文件 .

    一旦你有理由确定代码将使用新的主要版本运行,只需使用以下composer命令:

    composer require symfony/lts:"^3.0"
    

    这只是为了确保我们在此过程中不会意外安装任何4.0的Symfony组件 . 一旦您想升级到Symfony 4,您可以使用 composer remove symfony/lts 删除此依赖关系,然后运行update .

    在lts元软件包到位后,您可以更新Symfony本身:

    composer require symfony/symfony:^3.0
    

    如果您真的想要一步一步地更新到您的依赖项支持的最新3.x或使用更严格的约束:

    composer require symfony/symfony:3.0.*
    

    如果您愿意,您也可以一步完成这两件事:

    $ composer require symfony/lts:^3.0 symfony/symfony:^3.0
    ./composer.json has been updated
    Loading composer repositories with package information
    Updating dependencies (including require-dev)
    Package operations: 5 installs, 2 updates, 0 removals
    - Updating symfony/symfony (v2.8.32 => v3.4.2): Downloading (100%)
    - Installing psr/simple-cache (1.0.0): Loading from cache
    - Installing psr/link (1.0.0): Loading from cache
    - Installing psr/container (1.0.0): Loading from cache
    - Installing psr/cache (1.0.1): Loading from cache
    - Installing fig/link-util (1.0.0): Loading from cache
    Writing lock file
    Generating autoload files
    > Incenteev\ParameterHandler\ScriptHandler::buildParameters
    Updating the "app/config/parameters.yml" file
    > Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
    > Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache
    
    // Clearing the cache for the dev environment with debug
    // true
    
    
    [OK] Cache for the "dev" environment (debug=true) was successfully cleared.
    
    
    > Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets
    
    Trying to install assets as relative symbolic links.
    
    
    [OK] No assets were provided by any bundle.
    
    
    > Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile
    > Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::prepareDeploymentTarget
    

    这应该足以让Symfony在新版本上使用 . 您可能还有其他依赖项,例如Doctrine或您安装的一些bundle . 有一些有用的命令可用于更新它们 .

    首先,您一次只能更新一个依赖项:

    composer update doctrine/orm
    

    当您添加选项 --with-dependencies 时,它还将更新doctrine / orm的依赖项 .

    您始终可以使用依赖项和可选的版本来询问 composer whycomposer why-not ,以检查依赖项存在的原因以及它不会更新的原因 . 只需输入 composer help why-not 即可查看如何使用它 . 当您想要更新诸如doctrine / orm之类的依赖项时,这尤其有用,但是composer会抛出一个无法执行此操作的错误 .

相关问题