Laravel 5.1 升级到 5.2 出现错误

14

当我尝试使用官方指南将我们现有的Laravel 5.1项目更新到Laravel 5.2时,在composer update后运行post update时,我会遇到错误。

php artisan clear-compiled

运行后出现以下错误:

Class Illuminate\Foundation\Composer does not exist

有人遇到过类似的问题吗?当我使用no scripts标志运行composer update时,它可以正常更新,所以这是一个clear-compiled的问题。

以下是我的服务提供商和composer.json文件。

服务提供商:

    Illuminate\Auth\AuthServiceProvider::class,
    Illuminate\Broadcasting\BroadcastServiceProvider::class,
    Illuminate\Bus\BusServiceProvider::class,
    Illuminate\Cache\CacheServiceProvider::class,
    Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
    Illuminate\Cookie\CookieServiceProvider::class,
    Illuminate\Database\DatabaseServiceProvider::class,
    Illuminate\Encryption\EncryptionServiceProvider::class,
    Illuminate\Filesystem\FilesystemServiceProvider::class,
    Illuminate\Foundation\Providers\FoundationServiceProvider::class,
    Illuminate\Hashing\HashServiceProvider::class,
    Illuminate\Mail\MailServiceProvider::class,
    Illuminate\Pagination\PaginationServiceProvider::class,
    Illuminate\Pipeline\PipelineServiceProvider::class,
    Illuminate\Queue\QueueServiceProvider::class,
    // Illuminate\Redis\RedisServiceProvider::class,
    Vetruvet\PhpRedis\PhpRedisServiceProvider::class,
    Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
    Illuminate\Session\SessionServiceProvider::class,
    Illuminate\Translation\TranslationServiceProvider::class,
    Illuminate\Validation\ValidationServiceProvider::class,
    Illuminate\View\ViewServiceProvider::class,
    Collective\Html\HtmlServiceProvider::class,
    Laravel\Socialite\SocialiteServiceProvider::class,
    Intervention\Image\ImageServiceProvider::class,
    Torann\GeoIP\GeoIPServiceProvider::class,
    Jenssegers\Agent\AgentServiceProvider::class,
    Barryvdh\Debugbar\ServiceProvider::class,

composer.json

{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
    "php": ">=5.5.9",
    "laravel/framework": "5.2.*",
    "fzaninotto/faker": "^1.6@dev",
    "laravelcollective/html": "5.2.*",
    "laravelcollective/remote": "~5.2",
    "kriswallsmith/assetic": "^1.3@dev",
    "pda/pheanstalk": "^3.0@dev",
    "aws/aws-sdk-php-laravel": "~3.0",
    "illuminate/http": "~5.2",
    "illuminate/session": "~5.2",
    "illuminate/support": "~5.2",
    "nesbot/carbon": "~1.18",
    "guzzlehttp/guzzle": "~5.3|~6.0",
    "vetruvet/laravel-phpredis": "dev-master",
    "predis/predis": "^1.1@dev",
    "laravel/socialite": "^3.0@dev",
    "intervention/image": "^2.3@dev",
    "brightcove/api": "^1.0@dev",
    "torann/geoip": "dev-master",
    "graham-campbell/throttle": "~5.1",
    "jenssegers/agent": "^3.0@dev"
},
"require-dev": {
    "mockery/mockery": "0.9.*",
    "phpunit/phpunit": "~4.0",
    "phpspec/phpspec": "~2.1",
    "symfony/dom-crawler": "~3.0",
    "symfony/css-selector": "~3.0",
    "barryvdh/laravel-debugbar": "^2.0@dev",
    "laracasts/generators": "dev-master"
},
"repositories": [
    {
        "type": "git",
        "url": "https://github.com/nardev/laravel-vzaar.git"
    }
],
"autoload": {
    "classmap": [
        "database",
        "app/Models",
        "app/Footgoll"
    ],
    "files": [
        "app/helpers.php"
    ],
    "psr-4": {
        "Myapp\\": "app/"
    }
},
"autoload-dev": {
    "classmap": [
        "tests/TestCase.php"
    ]
},
"scripts": {
    "post-install-cmd": [
        "php artisan clear-compiled",
        "php artisan optimize"
    ],
    "post-update-cmd": [
        "php artisan clear-compiled",
        "php artisan optimize"
    ],
    "post-root-package-install": [
        "php -r \"copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
        "php artisan key:generate"
    ]
},
"config": {
    "preferred-install": "dist"
},
"minimum-stability": "dev",
"prefer-stable": true
}

当我运行:

grep -nH -d recurse 'Composer' bootstrap/ app/ config/

返回的结果如下:

bootstrap/autoload.php:7:| 注册 Composer 自动加载器 bootstrap/autoload.php:10:| Composer 提供了一个方便的、自动生成的类加载器 bootstrap/autoload.php:42:| 当在本地工作时,Composer 可以帮助我们自动加载类。

这是 autoload.php 文件的外观:

    <?php

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Register The Composer Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any our classes "manually". Feels great to relax.
|
*/

require __DIR__.'/../vendor/autoload.php';

/*
|--------------------------------------------------------------------------
| Include The Compiled Class File
|--------------------------------------------------------------------------
|
| To dramatically increase your application's performance, you may use a
| compiled class file which contains all of the classes commonly used
| by a request. The Artisan "optimize" is used to create this file.
|
*/

$compiledPath = __DIR__.'/cache/compiled.php';

if (file_exists($compiledPath)) {
    require $compiledPath;
}

/*
|--------------------------------------------------------------------------
| Register The Workbench Loaders
|--------------------------------------------------------------------------
|
| The Laravel workbench provides a convenient place to develop packages
| when working locally. However we will need to load in the Composer
| auto-load files for the packages so that these can be used here.
|
*/
if (is_dir($workbench = __DIR__.'/../workbench'))
{
    Xtwoend\Workbench\Starter::start($workbench);
}

这可能与工作台有关吗?

更新:将Composer.php从5.1返回到vendor/laravel/framework/src/Illuminate/Foundation的可怕修复使应用程序正常运行,但我确实需要更好的解决方案,一个可以推送到生产环境的解决方案。


我也遇到了同样的问题,正在寻找解决方案。 - murze
1
不,自动加载与此无关。那些只是注释。grep 命令显示没有对 Composer 类的引用。我认为删除 compiled.php 文件可以解决问题,你可能只需要再次运行 composer。 - andrewtweber
1
对于未来的读者,您可以自动升级Laravel 5.1到Laravel 5.2 - rohit_wason
6个回答

3
你所遇到的错误是关于你使用的软件包。由于Composer类的位置已经改变,因此无法定位。
从升级说明中可以看到:

Illuminate\Foundation\Support\Composer 类已经移动到 Illuminate\Support\Composer

请等待拉取请求被接受,例如 laracasts/generators 软件包,该软件包包含在你的 composer.json 文件中,目前还不兼容 Laravel 5.2。

https://github.com/laracasts/Laravel-5-Generators-Extended/issues/81

因此,出现此错误的最常用软件包之一是cviebrock/eloquent-sluggablehttps://github.com/cviebrock/eloquent-sluggable/issues/214
你只能等待合并请求被接受,或者编辑供应商文件,但这不是一个很好的选择。

顺便说一句,我的Sluggable包现在应该支持5.2了,截至3.1.4版本。 - Colin

2
尝试。
php artisan optimize --force

如果出错,请删除vendor/compiled.php文件,然后运行上面的命令。这将重新创建vendor/compiled.php类。
上面的命令将删除两个文件:
bootstrap/compiled.php文件。当您优化类时会创建此文件。 app/storage/meta/services.json文件。当Laravel尝试优化应用程序使用的服务提供商的加载时会创建此文件。 来源 当我运行clear-compiled命令时,它删除了我的项目中的vendor/compiled.php。
由于您没有编译过的类,因此可能不需要删除。这可能是您遇到问题的原因。不要费心清除已编译的类。
我也正在升级一个从4.2到5.0的大型应用程序。有很多问题.. :)

刚刚尝试运行它。我的Artisan命令实际上是不可用的,当我运行php artisan whatever时,同样的错误一直弹出。 - Deveram
@Deveram请再检查一下我的答案。 - Oguzhan
我的供应商目录中根本没有compiled.php文件。 - Deveram
类似的问题在下面的链接中得到了解决。建议查看一下。https://github.com/laravel/framework/issues/8520 - Oguzhan

1
尝试这个:
composer update --no-scripts
这使我能够看到为什么“ composer update”失败的详细说明。对我来说,我正在更新到laravel 5.2,但忘记了将“ laravelcollective / html:“ 5.1。*”更新为“ laravelcollective / html:“ 5.2。*”。
在这里找到 https://dev59.com/WZXfa4cB1Zd3GeqPlua6#36515184

1

1

可能是SocialiteServiceProvider,也可能还有其他服务提供者。

昨晚我在升级时遇到了这个问题,很多服务提供者也需要升级他们的代码到5.2。

AdamWathan\EloquentOAuthL5\Installation似乎直接使用了Composer类,移除此服务提供者后您就可以继续升级了。


0

好的,我刚刚用5.2创建了一个新的Laravel应用程序,并再次添加了所有代码和依赖项,现在似乎可以工作了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接