Closed ak-el-a closed 2 years ago
What is your app config?
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).
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.*'],
];
}
As I said we need a minimal reproducible example to verify that.
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
public $logTarget = 'yii\debug\LogTarget';
If this is a string at that line it should not cause the error saying that the object was passed to Yii::createObject().
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)); }
yii\debug\LogTarget is an object
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.
Returns an object of class yii\debug\LogTarget before execution
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] => [
Hmm, ok, we need to look deeper what is going on here.
This happened after composer update
The same for me - happened after composer update.
What's the version of yii-debug you have? Please paste output of composer show yiisoft/yii2-debug
.
@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
@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
@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.
@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>'
];
}
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:
Yeah seems like a misconfiguration by user. I prefer 1 or 3.
@yiisoft/core-developers ?
I'd leave it as is.
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.
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.
@bizley Thanks a lot guys. It worked out for me as well.
Thanks a lot guys. It worked out for me as well.
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
$this->logTarget
as both a string (class name) or initialized object.$this->logTarget
being already set, see https://github.com/yiisoft/yii2-debug/blob/master/src/Module.php#L268This 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);
}
}
@bizley I suggest we re-open this.
Ok, you are right about the enhancement. But since this is it - an enhancement - let's deal it separately. 👍🏻
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](https://user-images.githubusercontent.com/20139761/163724279-c25b86de-1620-409f-b085-81938e336a94.png)
Additional info