mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Merge pull request #714 from Flynsarmy/develop
Make dump show object type
This commit is contained in:
commit
7b171ed3d8
@ -12,6 +12,7 @@ use October\Rain\Database\Model;
|
|||||||
class DebugExtension extends Twig_Extension
|
class DebugExtension extends Twig_Extension
|
||||||
{
|
{
|
||||||
const PAGE_CAPTION = 'Page variables';
|
const PAGE_CAPTION = 'Page variables';
|
||||||
|
const ARRAY_CAPTION = 'Array variables';
|
||||||
const OBJECT_CAPTION = 'Object variables';
|
const OBJECT_CAPTION = 'Object variables';
|
||||||
const COMPONENT_CAPTION = 'Component variables';
|
const COMPONENT_CAPTION = 'Component variables';
|
||||||
|
|
||||||
@ -100,11 +101,20 @@ class DebugExtension extends Twig_Extension
|
|||||||
$this->variablePrefix = false;
|
$this->variablePrefix = false;
|
||||||
for ($i = 2; $i < $count; $i++) {
|
for ($i = 2; $i < $count; $i++) {
|
||||||
$var = func_get_arg($i);
|
$var = func_get_arg($i);
|
||||||
$caption = $var instanceof ComponentBase
|
$subcaption = null;
|
||||||
? static::COMPONENT_CAPTION
|
|
||||||
: static::OBJECT_CAPTION;
|
|
||||||
|
|
||||||
$result .= $this->dump($var, $caption);
|
if ( $var instanceof ComponentBase )
|
||||||
|
$caption = static::COMPONENT_CAPTION;
|
||||||
|
elseif ( is_array($var) )
|
||||||
|
$caption = static::ARRAY_CAPTION;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$caption = static::OBJECT_CAPTION;
|
||||||
|
$subcaption = get_class($var);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$result .= $this->dump($var, $caption, $subcaption);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,9 +136,10 @@ class DebugExtension extends Twig_Extension
|
|||||||
*
|
*
|
||||||
* @param mixed $variable Variable to dump
|
* @param mixed $variable Variable to dump
|
||||||
* @param string $caption Caption of the dump
|
* @param string $caption Caption of the dump
|
||||||
|
* @param string $subcaption Subcaption of the dump
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function dump($variables = null, $caption = null)
|
public function dump($variables = null, $caption = null, $subcaption = null)
|
||||||
{
|
{
|
||||||
$this->commentMap = [];
|
$this->commentMap = [];
|
||||||
$this->zebra = 1;
|
$this->zebra = 1;
|
||||||
@ -148,7 +159,7 @@ class DebugExtension extends Twig_Extension
|
|||||||
$output[] = '<table>';
|
$output[] = '<table>';
|
||||||
|
|
||||||
if ($caption) {
|
if ($caption) {
|
||||||
$output[] = $this->makeTableHeader($caption);
|
$output[] = $this->makeTableHeader($caption, $subcaption);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($variables as $key => $item) {
|
foreach ($variables as $key => $item) {
|
||||||
@ -164,13 +175,18 @@ class DebugExtension extends Twig_Extension
|
|||||||
/**
|
/**
|
||||||
* Builds the HTML used for the table header.
|
* Builds the HTML used for the table header.
|
||||||
* @param string $caption
|
* @param string $caption
|
||||||
|
* @param string $subcaption
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function makeTableHeader($caption)
|
protected function makeTableHeader($caption, $subcaption = null)
|
||||||
{
|
{
|
||||||
$output = [];
|
$output = [];
|
||||||
$output[] = '<tr>';
|
$output[] = '<tr>';
|
||||||
$output[] = '<th colspan="100" style="'.$this->getHeaderCss().'">'.$caption.'</td>';
|
$output[] = '<th colspan="3" colspan="100" style="'.$this->getHeaderCss().'">';
|
||||||
|
$output[] = $caption;
|
||||||
|
if ($subcaption)
|
||||||
|
$output[] = '<div style="'.$this->getSubheaderCss().'">'.$subcaption.'</div>';
|
||||||
|
$output[] = '</td>';
|
||||||
$output[] = '</tr>';
|
$output[] = '</tr>';
|
||||||
return implode(PHP_EOL, $output);
|
return implode(PHP_EOL, $output);
|
||||||
}
|
}
|
||||||
@ -499,6 +515,24 @@ class DebugExtension extends Twig_Extension
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the CSS string for the output subheader
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function getSubheaderCss()
|
||||||
|
{
|
||||||
|
return $this->arrayToCss([
|
||||||
|
'font-size' => '12px',
|
||||||
|
'font-weight' => 'normal',
|
||||||
|
'font-style' => 'italic',
|
||||||
|
'margin' => '0',
|
||||||
|
'padding' => '0',
|
||||||
|
'background-color' => '#7B8892',
|
||||||
|
'color' => '#FFF',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a key/value pair array into a CSS string
|
* Convert a key/value pair array into a CSS string
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user