Browse Source

Merge pull request #999 from iJackUA/debug-panel-serialisation-fix

Debug panel : change json_encode/decode to serialise/unserialise
tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
5af1e524e3
  1. 12
      framework/yii/debug/LogTarget.php
  2. 8
      framework/yii/debug/controllers/DefaultController.php
  3. 2
      framework/yii/debug/panels/RequestPanel.php

12
framework/yii/debug/LogTarget.php

@ -45,11 +45,11 @@ class LogTarget extends Target
if (!is_dir($path)) { if (!is_dir($path)) {
mkdir($path); mkdir($path);
} }
$indexFile = "$path/index.json"; $indexFile = "$path/index.php";
if (!is_file($indexFile)) { if (!is_file($indexFile)) {
$manifest = array(); $manifest = array();
} else { } else {
$manifest = json_decode(file_get_contents($indexFile), true); $manifest = unserialize(file_get_contents($indexFile));
} }
$request = Yii::$app->getRequest(); $request = Yii::$app->getRequest();
$manifest[$this->tag] = $summary = array( $manifest[$this->tag] = $summary = array(
@ -62,14 +62,14 @@ class LogTarget extends Target
); );
$this->gc($manifest); $this->gc($manifest);
$dataFile = "$path/{$this->tag}.json"; $dataFile = "$path/{$this->tag}.php";
$data = array(); $data = array();
foreach ($this->module->panels as $id => $panel) { foreach ($this->module->panels as $id => $panel) {
$data[$id] = $panel->save(); $data[$id] = $panel->save();
} }
$data['summary'] = $summary; $data['summary'] = $summary;
file_put_contents($dataFile, json_encode($data)); file_put_contents($dataFile, serialize($data));
file_put_contents($indexFile, json_encode($manifest)); file_put_contents($indexFile, serialize($manifest));
} }
/** /**
@ -93,7 +93,7 @@ class LogTarget extends Target
if (count($manifest) > $this->module->historySize + 10) { if (count($manifest) > $this->module->historySize + 10) {
$n = count($manifest) - $this->module->historySize; $n = count($manifest) - $this->module->historySize;
foreach (array_keys($manifest) as $tag) { foreach (array_keys($manifest) as $tag) {
$file = $this->module->dataPath . "/$tag.json"; $file = $this->module->dataPath . "/$tag.php";
@unlink($file); @unlink($file);
unset($manifest[$tag]); unset($manifest[$tag]);
if (--$n <= 0) { if (--$n <= 0) {

8
framework/yii/debug/controllers/DefaultController.php

@ -74,9 +74,9 @@ class DefaultController extends Controller
protected function getManifest() protected function getManifest()
{ {
if ($this->_manifest === null) { if ($this->_manifest === null) {
$indexFile = $this->module->dataPath . '/index.json'; $indexFile = $this->module->dataPath . '/index.php';
if (is_file($indexFile)) { if (is_file($indexFile)) {
$this->_manifest = array_reverse(json_decode(file_get_contents($indexFile), true), true); $this->_manifest = array_reverse(unserialize(file_get_contents($indexFile)), true);
} else { } else {
$this->_manifest = array(); $this->_manifest = array();
} }
@ -88,8 +88,8 @@ class DefaultController extends Controller
{ {
$manifest = $this->getManifest(); $manifest = $this->getManifest();
if (isset($manifest[$tag])) { if (isset($manifest[$tag])) {
$dataFile = $this->module->dataPath . "/$tag.json"; $dataFile = $this->module->dataPath . "/$tag.php";
$data = json_decode(file_get_contents($dataFile), true); $data = unserialize(file_get_contents($dataFile));
foreach ($this->module->panels as $id => $panel) { foreach ($this->module->panels as $id => $panel) {
if (isset($data[$id])) { if (isset($data[$id])) {
$panel->tag = $tag; $panel->tag = $tag;

2
framework/yii/debug/panels/RequestPanel.php

@ -151,7 +151,7 @@ EOD;
} }
$rows = array(); $rows = array();
foreach ($values as $name => $value) { foreach ($values as $name => $value) {
$rows[] = '<tr><th style="width: 200px;">' . Html::encode($name) . '</th><td>' . Html::encode(var_export($value, true)) . '</td></tr>'; $rows[] = '<tr><th style="width: 200px;">' . Html::encode($name) . '</th><td>' . htmlspecialchars(var_export($value, true), ENT_QUOTES|ENT_SUBSTITUTE, \Yii::$app->charset, TRUE) . '</td></tr>';
} }
$rows = implode("\n", $rows); $rows = implode("\n", $rows);
return <<<EOD return <<<EOD

Loading…
Cancel
Save