Skip to content

Commit 086368c

Browse files
authored
Merge pull request #775 from cakephp/fix-dumps
Fix sorting and collapsing of dump output
2 parents 98eba19 + be4e6fe commit 086368c

File tree

6 files changed

+43
-19
lines changed

6 files changed

+43
-19
lines changed

Diff for: src/Cache/Engine/DebugEngine.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,10 @@ public function set($key, $value, $ttl = null): bool
159159
/**
160160
* @inheritDoc
161161
*/
162-
public function setMultiple($data, $ttl = null): bool
162+
public function setMultiple($values, $ttl = null): bool
163163
{
164164
$start = microtime(true);
165-
$result = $this->_engine->setMultiple($data);
165+
$result = $this->_engine->setMultiple($values);
166166
$duration = microtime(true) - $start;
167167

168168
$this->track('set');

Diff for: src/Log/Engine/DebugKitLog.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ class DebugKitLog extends BaseLog
3131
/**
3232
* Captures log messages in memory
3333
*
34-
* @param string $type The type of message being logged.
34+
* @param mixed $level The type of message being logged.
3535
* @param string $message The message being logged.
3636
* @param array $context Additional context data
3737
* @return void
3838
*/
39-
public function log($type, $message, array $context = [])
39+
public function log($level, $message, array $context = [])
4040
{
41-
if (!isset($this->_logs[$type])) {
42-
$this->_logs[$type] = [];
41+
if (!isset($this->_logs[$level])) {
42+
$this->_logs[$level] = [];
4343
}
44-
$this->_logs[$type][] = [date('Y-m-d H:i:s'), $this->_format($message)];
44+
$this->_logs[$level][] = [date('Y-m-d H:i:s'), $this->_format($message)];
4545
}
4646

4747
/**

Diff for: src/View/Helper/ToolbarHelper.php

+5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public function dump($value)
7272
$restore = true;
7373
$debugger->setConfig('exportFormatter', HtmlFormatter::class);
7474
}
75+
76+
if ($this->sort && is_array($value)) {
77+
ksort($value);
78+
}
79+
7580
$contents = Debugger::exportVar($value, 25);
7681
if ($restore) {
7782
$debugger->setConfig('exportFormatter', $exportFormatter);

Diff for: templates/layout/panel.php

-11
This file was deleted.

Diff for: tests/TestCase/View/Helper/ToolbarHelperTest.php

+18
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Cake\TestSuite\TestCase;
2323
use Cake\View\View;
2424
use DebugKit\View\Helper\ToolbarHelper;
25+
use SimpleXmlElement;
2526
use stdClass;
2627

2728
/**
@@ -78,10 +79,27 @@ public function testDumpCoerceHtml()
7879
Debugger::configInstance('exportFormatter'),
7980
'Should restore setting'
8081
);
82+
8183
// Restore back to original value.
8284
Debugger::configInstance('exportFormatter', $restore);
8385
}
8486

87+
public function testDumpSorted()
88+
{
89+
$path = '//*[@class="cake-dbg-array-item"]/*[@class="cake-dbg-string"]';
90+
$data = ['z' => 1, 'a' => 99, 'm' => 123];
91+
$result = $this->Toolbar->dump($data);
92+
$xml = new SimpleXmlElement($result);
93+
$elements = $xml->xpath($path);
94+
$this->assertSame(["'z'", "'a'", "'m'"], array_map('strval', $elements));
95+
96+
$this->Toolbar->setSort(true);
97+
$result = $this->Toolbar->dump($data);
98+
$xml = new SimpleXmlElement($result);
99+
$elements = $xml->xpath($path);
100+
$this->assertSame(["'a'", "'m'", "'z'"], array_map('strval', $elements));
101+
}
102+
85103
/**
86104
* Test makeNeatArray with basic types.
87105
*

Diff for: webroot/js/toolbar-app.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,14 @@ Toolbar.prototype = {
150150
// Slide panel into place - css transitions.
151151
_this.content.addClass('enabled');
152152
contentArea.html(response);
153+
_this.bindVariableSort();
154+
_this.bindDebugBlock();
155+
153156
_this.bindNeatArray();
154157
});
155158
},
156159

157-
bindNeatArray: function() {
160+
bindVariableSort: function() {
158161
var sortButton = this.content.find('.neat-array-sort');
159162
var _this = this;
160163
sortButton.click(function() {
@@ -165,7 +168,16 @@ Toolbar.prototype = {
165168
}
166169
_this.loadPanel(_this.currentPanel());
167170
});
171+
},
172+
173+
bindDebugBlock: function () {
174+
if (window.__cakeDebugBlockInit) {
175+
window.__cakeDebugBlockInit();
176+
}
177+
},
168178

179+
bindNeatArray: function() {
180+
var _this = this;
169181
var lists = this.content.find('.depth-0');
170182
lists.find('ul').hide()
171183
.parent().addClass('expandable collapsed');

0 commit comments

Comments
 (0)