如何修复未捕获的异常'ReflectionException'消息'类日志不存在'?

时间:2016-07-17 08:11:58

标签: php laravel composer-php windows-server-2012-r2

我在 Windows Server 20012 R2 上遇到了作曲家的问题。我正在尝试部署网站,每次运行composer installcomposer update时,我都会收到以下信息:

$ composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postInstall
> php artisan optimize
Script php artisan optimize handling the post-install-cmd event returned with an error


  [RuntimeException]
  Error Output:


install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--ignore-platform-reqs] [--] [<packages>]...

当我检查 php错误日志时,我发现以下内容:

[17-Jul-2016 08:04:58 UTC] PHP Fatal error:  Uncaught exception 'ReflectionException' with message 'Class log does not exist' in C:\PATH_TO_PROJECT\vendor\laravel\framework\src\Illuminate\Container\Container.php:734
Stack trace:
#0 C:\PATH_TO_PROJECT\vendor\laravel\framework\src\Illuminate\Container\Container.php(734): ReflectionClass->__construct('log')
#1 C:\PATH_TO_PROJECT\vendor\laravel\framework\src\Illuminate\Container\Container.php(629): Illuminate\Container\Container->build('log', Array)
#2 C:\PATH_TO_PROJECT\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(697): Illuminate\Container\Container->make('log', Array)
#3 C:\PATH_TO_PROJECT\vendor\laravel\framework\src\Illuminate\Container\Container.php(849): Illuminate\Foundation\Application->make('Psr\\Log\\LoggerI...')
#4 C:\PATH_TO_PROJECT\vendor\laravel\framework\src\Illuminate\ in C:\PATH_TO_PROJECT\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 734

当我在 Ubuntu服务器上尝试相同项目时,一切正常!我试过在互联网上找到的每一个答案,但没有任何对我有用。有关如何解决此问题的任何建议?为什么会这样?

Windows服务器PHP版本为5.6。

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.*",
        "intervention/image": "^2.3",
        "greggilbert/recaptcha": "2.*",
        "laravelcollective/html": "5.2.*",
        "vsch/laravel-translation-manager": "*"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~4.0",
        "symfony/css-selector": "2.8.*|3.0.*",
        "symfony/dom-crawler": "2.8.*|3.0.*"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        },
         "files": ["app/Http/Helpers/helpers.php"]
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-root-package-install": [
            "php -r \"copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ],
        "post-install-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postInstall",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "php artisan optimize"
        ]
    },
    "config": {
        "preferred-install": "dist"
    }
}

4 个答案:

答案 0 :(得分:3)

我能够通过删除 .env 文件中值中的任何空格来解决此问题,例如:

MAIL_PORT= 587
MAIL_FROM_NAME=ABC Medical

为:

MAIL_PORT=587
MAIL_FROM_NAME=ABCMedical

或使用引号:

MAIL_PORT=587
MAIL_FROM_NAME="ABC Medical"

答案 1 :(得分:2)

我在.env中没有引号的空格中传递值时出现此错误,我通过将值包装在引号中来修复它。

答案 2 :(得分:0)

你尝试过吗? composer dump-autoload

你可以添加一个没有dump-autoload

的类

答案 3 :(得分:0)

我可以想到发生此错误的最常见原因如下:

  1. 在USE语句中未包含日志类的范围内调用日志类。
  2. 配置文件包含(解析)错误,而这些错误又不允许您的应用程序找到Log类。检查Laravel中早期加载的文件,例如app.php。