[英]Symfony 2.8 to 3.0 migration
我想將symfony 2.8
項目升級到3.0
,我將composer.json
的版本更改為3.0.*
但是在完成composer更新后,控制台中出現以下錯誤:
[RuntimeException的]
執行“'cache:clear --no-warmup'”命令時發生錯誤:
PHP致命錯誤:找不到類'Symfony \\ Component \\ HttpKernel \\ Kernel'
/var/www/html/t/EcoPro/app/AppKernel.php,第6行
聽起來您的代碼無法從Symfony中找到Kernel類。 因為它仍然應該存在,所以您可以在3.0分支的Symfony存儲庫中看到,我認為在更新期間出現了問題。
我建議首先運行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文檔作為參考,但也可以運行測試並檢查日志以了解不贊成使用的呼叫 。 對於3.3+版本,這將變得更加容易,因為這些版本具有單獨的棄用日志 ,您可以在var/log
與其他日志文件一起找到。
一旦確定可以使用新的主要版本運行代碼,只需使用以下composer命令:
composer require symfony/lts:"^3.0"
這只是為了確保在此過程中我們不會意外安裝任何4.0版本的Symfony組件。 一旦您想升級到Symfony 4,就可以使用composer remove symfony/lts
來刪除此依賴項,然后運行update。
放置lts meta包后,您可以更新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或已安裝的某些捆綁包。 有一些有用的命令可用於更新它們。
首先,您一次只能更新一個依賴項:
composer update doctrine/orm
當您添加--with-dependencies
選項時,它還會更新主義/ orm的依賴關系。
您總是可以詢問composer why
或composer why-not
提供依賴項,還可以選擇版本,以檢查為什么存在依賴項以及為什么不更新依賴項。 只需輸入composer help why-not
如何使用它。 當您要更新諸如doctrine / orm之類的依賴項時,此功能特別有用,但是composer會拋出一個無法做到的錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.