diff --git a/extensions/debug/CHANGELOG.md b/extensions/debug/CHANGELOG.md index 9e89b70fee2..602ecda35a1 100644 --- a/extensions/debug/CHANGELOG.md +++ b/extensions/debug/CHANGELOG.md @@ -4,6 +4,7 @@ Yii Framework 2 debug extension Change Log 2.0.1 under development ----------------------- +- Bug #5402: Debugger was not loading when there were closures, resources or PDO instances in the logged data (samdark) - Enh #5600: Allow configuring debug panels in `yii\debug\Module::panels` as panel class name strings (qiangxue) diff --git a/extensions/debug/LogTarget.php b/extensions/debug/LogTarget.php index ab7e42df049..755fdcf825e 100644 --- a/extensions/debug/LogTarget.php +++ b/extensions/debug/LogTarget.php @@ -55,12 +55,53 @@ public function export() $data[$id] = $panel->save(); } $data['summary'] = $summary; - file_put_contents($dataFile, serialize($data)); + file_put_contents($dataFile, serialize($this->replaceUnserializable($data))); $indexFile = "$path/index.data"; $this->updateIndexFile($indexFile, $summary); } + /** + * Replacing everything that is not serializable with its text representation + * + * @param mixed $value + * @return mixed + */ + private function replaceUnserializable($value) + { + if (is_scalar($value) || $value === null) { + return $value; + } + + if (is_array($value)) { + foreach ($value as &$row) { + $row = $this->replaceUnserializable($row); + } + return $value; + } + + if ($value instanceof \Closure) { + return '\Closure'; + } + + if (is_resource($value)) { + return 'resource'; + } + + if ($value instanceof \PDO) { + return '\PDO'; + } + + $properties = (new \ReflectionObject($value))->getProperties(); + foreach ($properties as &$property) { + $property->setAccessible(true); + $propertyValue = $property->getValue($value); + $property->setValue($value, $this->replaceUnserializable($propertyValue)); + } + + return $value; + } + /** * Updates index file with summary log data * diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index e603dde84e0..dd3b744508a 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -4,6 +4,7 @@ Yii Framework 2 Change Log 2.0.1 under development ----------------------- +- Bug #5402: Debugger was not loading when there were closures, resources or PDO instances in the logged data (samdark) - Bug #5584: `yii\rbac\DbRbacManager` should not delete items when deleting a rule on a database not supporting cascade update (mdmunir) - Bug #5601: Simple conditions in Query::where() and ActiveQuery::where() did not allow `yii\db\Expression` to be used as the value (cebe, stevekr) - Bug: Gii console command help information does not contain global options (qiangxue)