craft\debug\RequestPanel::save modify actionParams
key to prevent yii\debug\FlattenException
when Yii::$app->requestedParams
contains Closures
#14982
-
Currently Yii2 Debug Toolbar logs the entire This is usually quite good, but sometimes we use Let's say we have a site request for an entry. In that case This Entry has not yet loaded relation fields:
Unfortunately Closures cannot be serialized thus the data cannot be rendered and a FlattenArrayException is thrown What I usually do is to overwrite your class RequestPanel extends \craft\debug\RequestPanel
{
public function save(): array
{
$save = parent::save();
if(isset($save['actionParams']) && \is_array($save['actionParams'])){
$save['actionParams'] = $this->filterParams($save['actionParams']);
}
return $save;
}
protected function filterParams(array $params): array
{
foreach ($params as $key => $value){
if($value instanceof ElementInterface){
$params[$key] = $value::class . '::' . $value->getRef();
} else if(is_array($value)){
$params[$key] = $this->filterParams($value);
} else if(\is_object($value)){
$params[$key] = $value::class;
} else {
$params[$key] = $value;
}
}
return $params;
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Thanks for pointing that out! I’ve updated The change was a little involved, so I made it for 4.10 and 5.2. |
Beta Was this translation helpful? Give feedback.
Thanks for pointing that out!
I’ve updated
RequestPanel
to start pre-serializing any objects withinactionParams
viaVarDumper::dump()
, soserialize()
doesn’t potentially throw an error due to closures. (4484216)The change was a little involved, so I made it for 4.10 and 5.2.