yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.91k forks source link

Issue after upgrading php 7.2 and composer update #15895

Closed vzani closed 6 years ago

vzani commented 6 years ago

After upgrading php to 7.2 and running composer update, started facing the following issues:


An Error occurred while handling another error:
yii\base\InvalidConfigException: Unknown component ID: request in /home/xxx/public_html/poc/vendor/yiisoft/yii2/di/ServiceLocator.php:139
Stack trace:
#0 /home/xxx/public_html/poc/vendor/yiisoft/yii2/base/Module.php(742): yii\di\ServiceLocator->get('request', true)
#1 /home/xxx/public_html/poc/vendor/yiisoft/yii2/web/Application.php(160): yii\base\Module->get('request')
#2 /home/xxx/public_html/poc/vendor/yiisoft/yii2/web/ErrorHandler.php(501): yii\web\Application->getRequest()
#3 /home/xxx/public_html/poc/vendor/yiisoft/yii2/web/ErrorHandler.php(115): yii\web\ErrorHandler->shouldRenderSimpleHtml()
#4 /home/xxx/public_html/poc/vendor/yiisoft/yii2/base/ErrorHandler.php(104): yii\web\ErrorHandler->renderException(Object(yii\base\InvalidConfigException))
#5 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\base\InvalidConfigException))
#6 {main}
Previous exception:
yii\base\InvalidConfigException: The configuration for the "log" component must contain a "__class" element. in /home/www/public_html/poc/vendor/yiisoft/yii2/di/ServiceLocator.php:206
Stack trace:
#0 /home/xxx/public_html/poc/vendor/yiisoft/yii2/di/ServiceLocator.php(262): yii\di\ServiceLocator->set('log', Array)
#1 /home/xxx/public_html/poc/vendor/yiisoft/yii2/base/Component.php(180): yii\di\ServiceLocator->setComponents(Array)
#2 /home/xxx/public_html/poc/vendor/yiisoft/yii2/BaseYii.php(566): yii\base\Component->__set('components', Array)
#3 /home/xxx/public_html/poc/vendor/yiisoft/yii2/base/BaseObject.php(97): yii\BaseYii::configure(Object(yii\web\Application), Array)
#4 /home/xxx/public_html/poc/vendor/yiisoft/yii2/base/Application.php(207): yii\base\BaseObject->__construct(Array)
#5 /home/xxx/public_html/poc/index.php(19): yii\base\Application->__construct(Array)
#6 {main}

My composer.json require:

"require": {
    "php": ">=5.4.0",
    "bower-asset/jquery": ">=2.2.1",
    "yiisoft/yii2": ">=2.0.6",
    "yiisoft/yii2-bootstrap": "*",        
    "yiisoft/yii2-swiftmailer": "*",
    "kartik-v/yii2-nav-x": "*",
    "kartik-v/yii2-icons": "*",
    "newerton/yii2-jcrop": "dev-master",
    "kartik-v/yii2-grid": "@dev",
    "yiisoft/yii2-imagine": "~2.0.0",
    "serhatozles/yii2-simplehtmldom": "dev-master",
    "yiisoft/yii2-authclient": "~2.0.0",
    "kartik-v/yii2-widgets": "*",
    "kartik-v/yii2-datecontrol": "dev-master",      
    "alexandernst/yii2-device-detect": "0.0.9",
    "filsh/yii2-oauth2-server": "2.0.1.x-dev",
    "kartik-v/yii2-mpdf": "dev-master",
    "kartik-v/yii2-helpers": "dev-master"

}

My "components"

    'components' => [
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'useFileTransport' => false
        ],

        'user' => [
            'identityClass' => 'common\models\User',
            'enableAutoLogin' => false,
            //'enableSession' => true,

        ],

        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'urlManager' => [
            'class' => 'yii\web\UrlManager',
            'enableStrictParsing' => true,
            'showScriptName' => false,
            'enablePrettyUrl' => true,

            'rules' => [
                '/' => '/index',
                '<controller:[-\w]+>/<id:\d+>' => '<controller>/view',
                '<controller:[-\w]+>/<action:[-\w]+>/<id:\d+>' => '<controller>/<action>',
                '<controller:[-\w]+>/<action:[-\w]+>' => '<controller>/<action>',

            ],
        ], 

    ]

Thanks

leandrogehlen commented 6 years ago

you need to change :

yiisoft/yii2": ">=2.0.6" to "yiisoft/yii2": "~2.0.14"

samdark commented 6 years ago

Yes. As notes in multiple 2.0 release announcements:

Since there is Yii 2.1 in development now, make sure you have a version constraint in your composer.json, that does not allow it to be installed automatically on update, so when next major version of Yii is released, your project won't break by itself. A version constraint that does not include 2.1 is for example ~2.0.14, make sure you do not have >= or * in version constraints in composer.json.

dpanzer commented 6 years ago

Aside from this issue about constraining the version in the composer file, I found that I was able to solve the actual error by modifying the log key as follows:

'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
            'class' => 'yii\log\Logger',
        ],

The message is straightforward - it needs a class for the log, so you give it one.

dieos2 commented 1 year ago

sorry but where is this component file?