yiisoft / yii2-debug

Debug Extension for Yii 2
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
202 stars 149 forks source link

Unsupported configuration type: object #481

Closed ak-el-a closed 2 years ago

ak-el-a commented 2 years ago

What steps will reproduce the problem?

Open index route with any browser

What's expected?

Expacted to see index page

What do you get instead?

Have an error

Invalid Configuration – yii\base\InvalidConfigException Unsupported configuration type: object image

Additional info

rollback yii2-debug to 2.1.16 solved this issue Q A
Yii version 2.0.45
PHP version 7.4
Operating system Linux 3.10.0-962.3.2.lve1.5.54.el7.x86_64 x86_64
bizley commented 2 years ago

What is your app config?

ak-el-a commented 2 years ago

config.txt

bizley commented 2 years ago

I'm not sure what is the cause for this in your case, I'm currently looking at the application using the newest debug and everything is fine. Could you maybe provide the config for your log component? It's dotted out in your file. (btw. use three ``` to format the code).

OmgDef commented 2 years ago

I faced the same issue during update an old project from php 7.4 to 8.1 (Yii version 2.0.45) My config is

if (!YII_ENV_TEST) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
        'allowedIPs' => ['127.0.0.1', '::1', '10.211.55.*'],
    ];

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        'allowedIPs' => ['127.0.0.1', '::1', '10.211.55.*'],
    ];
}
bizley commented 2 years ago

As I said we need a minimal reproducible example to verify that.

Almeev commented 2 years ago

I faced the same problem, minified the line $this->logTarget = $app->getLog()->targets['debug'] = Yii::createObject($this->logTarget, [$this]); to the line $this->logTarget = $app->getLog()->targets['debug'] = new LogTarget($this); in vendor\yiisoft\yii2-debug\src\Module.php file and everything worked

bizley commented 2 years ago

What is exactly in $this->logTarget before this line?

Almeev commented 2 years ago

public $logTarget = 'yii\debug\LogTarget';

bizley commented 2 years ago

If this is a string at that line it should not cause the error saying that the object was passed to Yii::createObject().

Almeev commented 2 years ago

In the vendor\yiisoft\yii2\BaseYii.php, createObject method, there is such a construction if (!is_array($type)) { throw new InvalidConfigException('Unsupported configuration type: ' .gettype($type)); }

Almeev commented 2 years ago

yii\debug\LogTarget is an object

bizley commented 2 years ago

What is the state of that property before the line I mentioned in your app on runtime? If you are saying it's 'yii\debug\LogTarget' then it's a class-string, not an object.

Almeev commented 2 years ago

Returns an object of class yii\debug\LogTarget before execution

Almeev commented 2 years ago

Part of the log: 'yii\debug\LogTarget#1 ( [module] => yii\debug\Module#2 ( [allowedIPs] => [ 0 => \'127.0.0.1\' 1 => \'::1\' ] [allowedHosts] => [] [checkAccessCallback] => null [controllerNamespace] => \'yii\\debug\\controllers\' [logTarget] => yii\debug\LogTarget#1(...) [panels] => [

bizley commented 2 years ago

Hmm, ok, we need to look deeper what is going on here.

Almeev commented 2 years ago

This happened after composer update

ak-el-a commented 2 years ago

The same for me - happened after composer update.

samdark commented 2 years ago

What's the version of yii-debug you have? Please paste output of composer show yiisoft/yii2-debug.

OmgDef commented 2 years ago

@samdark I am having this issue with 2.1.19. 2.1.18 works fine.

name     : yiisoft/yii2-debug
descrip. : The debugger extension for the Yii framework
keywords : debug, debugger, yii2
versions : * 2.1.19
type     : yii2-extension
license  : BSD 3-Clause "New" or "Revised" License (BSD-3-Clause) (OSI approved) https://spdx.org/licenses/BSD-3-Clause.html#licenseText
homepage :
source   : [git] https://github.com/yiisoft/yii2-debug.git 84d20d738b0698298f851fcb6fc25e748d759223
dist     : [zip] https://api.github.com/repos/yiisoft/yii2-debug/zipball/84d20d738b0698298f851fcb6fc25e748d759223 84d20d738b0698298f851fcb6fc25e748d759223
path     : /var/www/api-v2-81/vendor/yiisoft/yii2-debug
names    : yiisoft/yii2-debug

support
forum : http://www.yiiframework.com/forum/
irc : irc://irc.freenode.net/yii
issues : https://github.com/yiisoft/yii2-debug/issues
source : https://github.com/yiisoft/yii2-debug
wiki : http://www.yiiframework.com/wiki/

autoload
psr-4
yii\debug\ => src

requires
ext-mbstring *
php >=5.4
yiisoft/yii2 ~2.0.13

requires (dev)
cweagans/composer-patches ^1.7
phpunit/phpunit 4.8.34
yiisoft/yii2-coding-standards ~2.0
yiisoft/yii2-swiftmailer *
Almeev commented 2 years ago

I have the same situation

@samdark I am having this issue with 2.1.19. 2.1.18 works fine.

name     : yiisoft/yii2-debug
descrip. : The debugger extension for the Yii framework
keywords : debug, debugger, yii2
versions : * 2.1.19
type     : yii2-extension
license  : BSD 3-Clause "New" or "Revised" License (BSD-3-Clause) (OSI approved) https://spdx.org/licenses/BSD-3-Clause.html#licenseText
homepage :
source   : [git] https://github.com/yiisoft/yii2-debug.git 84d20d738b0698298f851fcb6fc25e748d759223
dist     : [zip] https://api.github.com/repos/yiisoft/yii2-debug/zipball/84d20d738b0698298f851fcb6fc25e748d759223 84d20d738b0698298f851fcb6fc25e748d759223
path     : /var/www/api-v2-81/vendor/yiisoft/yii2-debug
names    : yiisoft/yii2-debug

support
forum : http://www.yiiframework.com/forum/
irc : irc://irc.freenode.net/yii
issues : https://github.com/yiisoft/yii2-debug/issues
source : https://github.com/yiisoft/yii2-debug
wiki : http://www.yiiframework.com/wiki/

autoload
psr-4
yii\debug\ => src

requires
ext-mbstring *
php >=5.4
yiisoft/yii2 ~2.0.13

requires (dev)
cweagans/composer-patches ^1.7
phpunit/phpunit 4.8.34
yiisoft/yii2-coding-standards ~2.0
yiisoft/yii2-swiftmailer *

I have the same situation

bizley commented 2 years ago

@ak-el-a @OmgDef @Almeev I still cannot reproduce it, please provide me something to work with, I asked for logs config for example (and for minimal reproducible example on the top of that). So far it looks like something is calling debug's bootstrap method twice in your case and it would be nice to see what is causing it. Anyway, as a precaution we could add a flag to mark the debug as already bootstrapped but first I would like to see the cause of that error.

simialbi commented 2 years ago

@ak-el-a @OmgDef @Almeev @bizley I could reproduce it. It happens when you have the bootstraping process twice. E.g. in an advanced application where you have e.g. this code in the common/config/main.php and in the frontend/config/main.php:

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][]      = 'debug';
    $config['modules']['debug'] = [
        'class'      => 'yii\debug\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        'allowedIPs' => ['127.0.0.1'],
        'traceLine'  => '<a href="idea://open?url=file://{file}&line={line}">{text}</a>'
    ];
}
bizley commented 2 years ago

So it's a sort of "misconfiguration" on the user's side, right? If I'm not mistaken advanced app template is not doing it on itself.

Now here's an interesting case - should we:

  1. Leave it as it is since it's a user problem?
  2. Add a flag to the debug's module to prevent bootstrapping it twice?
  3. Modify Yii's bootstrapping to prevent double bootstrap for everything?
simialbi commented 2 years ago

Yeah seems like a misconfiguration by user. I prefer 1 or 3.

bizley commented 2 years ago

@yiisoft/core-developers ?

samdark commented 2 years ago

I'd leave it as is.

bizley commented 2 years ago

Ok. @ak-el-a @OmgDef @Almeev please correct your configs and let us know if that was it. I'm closing the issue - it will be reopened if needed, just write here if something new develops.

ak-el-a commented 2 years ago

If I comment out the second call to the bootstrap component in frontend\config\main-local.php, I can use the latest version of yii2-debug (2.1.19). Thanks guys for your work.

OmgDef commented 2 years ago

@bizley Thanks a lot guys. It worked out for me as well.

Almeev commented 2 years ago

Thanks a lot guys. It worked out for me as well.

Sarke commented 2 years ago

This issue occurred for me as well.

It was introduced by a recent PR #469 because it doesn't consider that $this->logTarget can be an object. Yes, this could be triggered by a misconfiguration, but it is inherently caused by

  1. Treating $this->logTarget as both a string (class name) or initialized object.
  2. Not accounting for the $this->logTarget being already set, see https://github.com/yiisoft/yii2-debug/blob/master/src/Module.php#L268

This should be consistent with how Yii2 normally deals with this type of config, by allowing it to be either a string, an array with class key, or an object. Example:

    public function init()
    {
        parent::init();
        if (is_array($this->theme)) {
            if (!isset($this->theme['class'])) {
                $this->theme['class'] = 'yii\base\Theme';
            }
            $this->theme = Yii::createObject($this->theme);
        } elseif (is_string($this->theme)) {
            $this->theme = Yii::createObject($this->theme);
        }
    }

https://github.com/yiisoft/yii2/blob/6599713d2bcf4440190cec2b950b1738d7ddfae4/framework/base/View.php#L115-L126

@bizley I suggest we re-open this.

bizley commented 2 years ago

Ok, you are right about the enhancement. But since this is it - an enhancement - let's deal it separately. 👍🏻