2014-08-29 21:55:41 +10:00
|
|
|
<?php namespace Cms\Twig;
|
|
|
|
|
|
|
|
use Twig_Extension;
|
|
|
|
use Twig_Environment;
|
|
|
|
use Twig_SimpleFunction;
|
|
|
|
use Cms\Classes\Controller;
|
2014-08-30 12:23:12 +10:00
|
|
|
use Cms\Classes\ComponentBase;
|
|
|
|
use Illuminate\Pagination\Paginator;
|
|
|
|
use Illuminate\Support\Collection;
|
2014-10-11 12:13:25 +11:00
|
|
|
use October\Rain\Database\Model;
|
2014-08-29 21:55:41 +10:00
|
|
|
|
|
|
|
class DebugExtension extends Twig_Extension
|
|
|
|
{
|
2014-08-30 12:23:12 +10:00
|
|
|
const PAGE_CAPTION = 'Page variables';
|
2014-10-23 20:32:55 +10:00
|
|
|
const ARRAY_CAPTION = 'Array variables';
|
2014-08-30 12:23:12 +10:00
|
|
|
const OBJECT_CAPTION = 'Object variables';
|
2014-08-30 12:34:03 +10:00
|
|
|
const COMPONENT_CAPTION = 'Component variables';
|
2014-08-30 12:23:12 +10:00
|
|
|
|
2014-08-29 21:55:41 +10:00
|
|
|
/**
|
|
|
|
* @var \Cms\Classes\Controller A reference to the CMS controller.
|
|
|
|
*/
|
|
|
|
protected $controller;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var integer Helper for rendering table row styles.
|
|
|
|
*/
|
|
|
|
protected $zebra = 1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var boolean If no variable is passed, true.
|
|
|
|
*/
|
2014-08-30 12:23:12 +10:00
|
|
|
protected $variablePrefix = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array Collection of method/property comments.
|
|
|
|
*/
|
|
|
|
protected $commentMap = [];
|
|
|
|
|
2014-10-11 01:42:04 +02:00
|
|
|
protected $blockMethods = [
|
|
|
|
'componentDetails',
|
|
|
|
'defineProperties',
|
|
|
|
'getPropertyOptions',
|
|
|
|
'offsetExists',
|
|
|
|
'offsetGet',
|
|
|
|
'offsetSet',
|
|
|
|
'offsetUnset'
|
|
|
|
];
|
2014-08-29 21:55:41 +10:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the extension instance.
|
|
|
|
* @param \Cms\Classes\Controller $controller The CMS controller object.
|
|
|
|
*/
|
|
|
|
public function __construct(Controller $controller)
|
|
|
|
{
|
|
|
|
$this->controller = $controller;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list of global functions to add to the existing list.
|
|
|
|
*
|
|
|
|
* @return array An array of global functions
|
|
|
|
*/
|
|
|
|
public function getFunctions()
|
|
|
|
{
|
|
|
|
return array(
|
2014-10-11 01:42:04 +02:00
|
|
|
new Twig_SimpleFunction('dump', [$this, 'runDump'], array(
|
|
|
|
'is_safe' => ['html'],
|
|
|
|
'needs_context' => true,
|
|
|
|
'needs_environment' => true
|
|
|
|
)),
|
2014-08-29 21:55:41 +10:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-08-30 12:23:12 +10:00
|
|
|
/**
|
|
|
|
* Processes the dump variables, if none is supplied, all the twig
|
|
|
|
* template variables are used
|
|
|
|
* @param Twig_Environment $env
|
|
|
|
* @param array $context
|
|
|
|
* @return string
|
|
|
|
*/
|
2014-08-29 21:55:41 +10:00
|
|
|
public function runDump(Twig_Environment $env, $context)
|
|
|
|
{
|
|
|
|
if (!$env->isDebug()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-30 12:23:12 +10:00
|
|
|
$result = '';
|
2014-08-29 21:55:41 +10:00
|
|
|
|
|
|
|
$count = func_num_args();
|
2014-08-30 12:23:12 +10:00
|
|
|
if ($count == 2) {
|
2014-10-24 19:11:44 +11:00
|
|
|
|
2014-08-30 12:23:12 +10:00
|
|
|
$this->variablePrefix = true;
|
2014-08-29 21:55:41 +10:00
|
|
|
$vars = [];
|
|
|
|
foreach ($context as $key => $value) {
|
|
|
|
if (!$value instanceof Twig_Template) {
|
|
|
|
$vars[$key] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-30 12:23:12 +10:00
|
|
|
$result .= $this->dump($vars, static::PAGE_CAPTION);
|
2014-10-24 19:11:44 +11:00
|
|
|
|
2014-10-11 01:42:04 +02:00
|
|
|
} else {
|
2014-10-24 19:11:44 +11:00
|
|
|
|
2014-08-30 12:23:12 +10:00
|
|
|
$this->variablePrefix = false;
|
2014-08-29 21:55:41 +10:00
|
|
|
for ($i = 2; $i < $count; $i++) {
|
2014-10-24 19:11:44 +11:00
|
|
|
|
2014-08-30 12:34:03 +10:00
|
|
|
$var = func_get_arg($i);
|
2014-10-23 20:32:55 +10:00
|
|
|
|
2014-10-24 19:00:44 +11:00
|
|
|
if ($var instanceof ComponentBase) {
|
2014-10-24 19:17:21 +11:00
|
|
|
$caption = [static::COMPONENT_CAPTION, get_class($var)];
|
2014-10-24 19:01:30 +11:00
|
|
|
} elseif (is_array($var)) {
|
2014-10-23 20:32:55 +10:00
|
|
|
$caption = static::ARRAY_CAPTION;
|
2014-10-24 19:01:30 +11:00
|
|
|
} else {
|
2014-10-24 19:11:44 +11:00
|
|
|
$caption = [static::OBJECT_CAPTION, get_class($var)];
|
2014-10-23 20:32:55 +10:00
|
|
|
}
|
|
|
|
|
2014-10-24 19:11:44 +11:00
|
|
|
$result .= $this->dump($var, $caption);
|
2014-08-29 21:55:41 +10:00
|
|
|
}
|
2014-10-24 19:11:44 +11:00
|
|
|
|
2014-08-29 21:55:41 +10:00
|
|
|
}
|
|
|
|
|
2014-08-30 12:23:12 +10:00
|
|
|
return $result;
|
2014-08-29 21:55:41 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the name of the extension.
|
|
|
|
*
|
|
|
|
* @return string The extension name
|
|
|
|
*/
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return 'debug';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dump information about a variable
|
|
|
|
*
|
|
|
|
* @param mixed $variable Variable to dump
|
2014-10-24 19:11:44 +11:00
|
|
|
* @param mixed $caption Caption [and subcaption] of the dump
|
2014-08-29 21:55:41 +10:00
|
|
|
* @return void
|
|
|
|
*/
|
2014-10-24 19:11:44 +11:00
|
|
|
public function dump($variables = null, $caption = null)
|
2014-08-29 21:55:41 +10:00
|
|
|
{
|
2014-08-30 12:23:12 +10:00
|
|
|
$this->commentMap = [];
|
|
|
|
$this->zebra = 1;
|
2014-08-29 21:55:41 +10:00
|
|
|
$info = [];
|
|
|
|
|
2014-08-30 12:23:12 +10:00
|
|
|
if (!is_array($variables)) {
|
2014-10-11 01:42:04 +02:00
|
|
|
if ($variables instanceof Paginator) {
|
2014-08-30 12:23:12 +10:00
|
|
|
$variables = $this->paginatorToArray($variables);
|
2014-10-11 01:42:04 +02:00
|
|
|
} elseif (is_object($variables)) {
|
2014-08-30 12:23:12 +10:00
|
|
|
$variables = $this->objectToArray($variables);
|
2014-10-11 01:42:04 +02:00
|
|
|
} else {
|
2014-08-30 12:23:12 +10:00
|
|
|
$variables = [$variables];
|
2014-10-11 01:42:04 +02:00
|
|
|
}
|
2014-08-30 12:23:12 +10:00
|
|
|
}
|
2014-08-29 21:55:41 +10:00
|
|
|
|
|
|
|
$output = [];
|
|
|
|
$output[] = '<table>';
|
2014-08-30 12:23:12 +10:00
|
|
|
|
2014-10-11 01:42:04 +02:00
|
|
|
if ($caption) {
|
2014-10-24 19:11:44 +11:00
|
|
|
$output[] = $this->makeTableHeader($caption);
|
2014-10-11 01:42:04 +02:00
|
|
|
}
|
2014-08-30 12:23:12 +10:00
|
|
|
|
2014-08-29 21:55:41 +10:00
|
|
|
foreach ($variables as $key => $item) {
|
|
|
|
$output[] = $this->makeTableRow($key, $item);
|
|
|
|
}
|
|
|
|
$output[] = '</table>';
|
|
|
|
|
|
|
|
$html = implode(PHP_EOL, $output);
|
|
|
|
|
2014-08-30 12:23:12 +10:00
|
|
|
return '<pre style="' . $this->getContainerCss() . '">' . $html . '</pre>';
|
2014-08-29 21:55:41 +10:00
|
|
|
}
|
|
|
|
|
2014-08-30 12:23:12 +10:00
|
|
|
/**
|
|
|
|
* Builds the HTML used for the table header.
|
2014-10-24 19:11:44 +11:00
|
|
|
* @param mixed $caption Caption [and subcaption] of the dump
|
2014-08-30 12:23:12 +10:00
|
|
|
* @return string
|
|
|
|
*/
|
2014-10-24 19:11:44 +11:00
|
|
|
protected function makeTableHeader($caption)
|
2014-08-29 21:55:41 +10:00
|
|
|
{
|
2014-10-24 19:11:44 +11:00
|
|
|
if (is_array($caption)) {
|
|
|
|
list($caption, $subcaption) = $caption;
|
|
|
|
}
|
|
|
|
|
2014-08-29 21:55:41 +10:00
|
|
|
$output = [];
|
|
|
|
$output[] = '<tr>';
|
2014-10-23 20:32:55 +10:00
|
|
|
$output[] = '<th colspan="3" colspan="100" style="'.$this->getHeaderCss().'">';
|
|
|
|
$output[] = $caption;
|
2014-10-24 19:00:44 +11:00
|
|
|
|
2014-10-24 19:11:44 +11:00
|
|
|
if (isset($subcaption)) {
|
2014-10-23 20:32:55 +10:00
|
|
|
$output[] = '<div style="'.$this->getSubheaderCss().'">'.$subcaption.'</div>';
|
2014-10-24 19:00:44 +11:00
|
|
|
}
|
|
|
|
|
2014-10-23 20:32:55 +10:00
|
|
|
$output[] = '</td>';
|
2014-08-29 21:55:41 +10:00
|
|
|
$output[] = '</tr>';
|
|
|
|
return implode(PHP_EOL, $output);
|
|
|
|
}
|
|
|
|
|
2014-08-30 12:23:12 +10:00
|
|
|
/**
|
|
|
|
* Builds the HTML used for each table row.
|
|
|
|
* @param mixed $key
|
|
|
|
* @param mixed $variable
|
|
|
|
* @return string
|
|
|
|
*/
|
2014-08-29 21:55:41 +10:00
|
|
|
protected function makeTableRow($key, $variable)
|
|
|
|
{
|
|
|
|
$this->zebra = $this->zebra ? 0 : 1;
|
2014-08-30 12:23:12 +10:00
|
|
|
$css = $this->getDataCss($variable);
|
2014-08-29 21:55:41 +10:00
|
|
|
$output = [];
|
|
|
|
$output[] = '<tr>';
|
2014-08-30 12:23:12 +10:00
|
|
|
$output[] = '<td style="'.$css.'">'.$this->evalKeyLabel($key).'</td>';
|
|
|
|
$output[] = '<td style="'.$css.'">'.$this->evalVarLabel($variable).'</td>';
|
|
|
|
$output[] = '<td style="'.$css.'">'.$this->evalVarDesc($variable, $key).'</td>';
|
2014-08-29 21:55:41 +10:00
|
|
|
$output[] = '</tr>';
|
|
|
|
return implode(PHP_EOL, $output);
|
|
|
|
}
|
|
|
|
|
2014-08-30 12:23:12 +10:00
|
|
|
protected function evalKeyLabel($key)
|
2014-08-29 21:55:41 +10:00
|
|
|
{
|
2014-08-30 12:23:12 +10:00
|
|
|
if ($this->variablePrefix === true) {
|
|
|
|
$output = '{{ <span>%s</span> }}';
|
2014-10-11 01:42:04 +02:00
|
|
|
} elseif (is_array($this->variablePrefix)) {
|
2014-08-30 12:23:12 +10:00
|
|
|
$prefix = implode('.', $this->variablePrefix);
|
|
|
|
$output = '{{ <span>'.$prefix.'.%s</span> }}';
|
2014-10-11 01:42:04 +02:00
|
|
|
} elseif ($this->variablePrefix) {
|
2014-08-30 12:23:12 +10:00
|
|
|
$output = '{{ <span>'.$this->variablePrefix.'.%s</span> }}';
|
2014-10-11 01:42:04 +02:00
|
|
|
} else {
|
2014-08-30 12:23:12 +10:00
|
|
|
$output = '%s';
|
|
|
|
}
|
|
|
|
|
|
|
|
return sprintf($output, $key);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Evaluate the variable description
|
|
|
|
* @param mixed $variable
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function evalVarLabel($variable)
|
|
|
|
{
|
|
|
|
$type = $this->getType($variable);
|
|
|
|
switch ($type) {
|
2014-08-29 21:55:41 +10:00
|
|
|
case 'object':
|
2014-08-30 12:23:12 +10:00
|
|
|
return $this->evalObjLabel($variable);
|
2014-08-29 21:55:41 +10:00
|
|
|
|
|
|
|
case 'array':
|
2014-08-30 12:23:12 +10:00
|
|
|
return $type . '('.count($variable).')';
|
2014-08-29 21:55:41 +10:00
|
|
|
|
|
|
|
default:
|
2014-08-30 12:23:12 +10:00
|
|
|
return $type;
|
2014-08-29 21:55:41 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-30 12:23:12 +10:00
|
|
|
/**
|
|
|
|
* Evaluate an object type for label
|
|
|
|
* @param object $variable
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function getType($variable)
|
|
|
|
{
|
|
|
|
$type = gettype($variable);
|
2014-10-11 01:42:04 +02:00
|
|
|
if ($type == 'string' && substr($variable, 0, 12) == '___METHOD___') {
|
2014-08-30 12:23:12 +10:00
|
|
|
return 'method';
|
2014-10-11 01:42:04 +02:00
|
|
|
}
|
2014-08-30 12:23:12 +10:00
|
|
|
|
|
|
|
return $type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Evaluate an object type for label
|
|
|
|
* @param object $variable
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function evalObjLabel($variable)
|
|
|
|
{
|
|
|
|
$class = get_class($variable);
|
2014-09-29 13:12:34 +10:00
|
|
|
$label = class_basename($variable);
|
2014-08-30 12:23:12 +10:00
|
|
|
|
2014-10-11 01:42:04 +02:00
|
|
|
if ($variable instanceof ComponentBase) {
|
2014-08-30 12:23:12 +10:00
|
|
|
$label = '<strong>Component</strong>';
|
2014-10-11 01:42:04 +02:00
|
|
|
} elseif ($variable instanceof Collection) {
|
2014-08-30 12:23:12 +10:00
|
|
|
$label = 'Collection('.$variable->count().')';
|
2014-10-11 01:42:04 +02:00
|
|
|
} elseif ($variable instanceof Paginator) {
|
2014-08-30 12:34:03 +10:00
|
|
|
$label = 'Paged Collection('.$variable->count().')';
|
2014-10-11 01:42:04 +02:00
|
|
|
} elseif ($variable instanceof Model) {
|
2014-08-30 12:23:12 +10:00
|
|
|
$label = 'Model';
|
2014-10-11 01:42:04 +02:00
|
|
|
}
|
2014-08-30 12:23:12 +10:00
|
|
|
|
|
|
|
return '<abbr title="'.e($class).'">'.$label.'</abbr>';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Evaluate the variable description
|
|
|
|
* @param mixed $variable
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function evalVarDesc($variable, $key)
|
2014-08-29 21:55:41 +10:00
|
|
|
{
|
2014-08-30 12:23:12 +10:00
|
|
|
$type = $this->getType($variable);
|
|
|
|
|
2014-10-11 01:42:04 +02:00
|
|
|
if ($type == 'method') {
|
2014-08-30 12:23:12 +10:00
|
|
|
return $this->evalMethodDesc($variable);
|
2014-10-11 01:42:04 +02:00
|
|
|
}
|
2014-08-30 12:23:12 +10:00
|
|
|
|
2014-10-11 01:42:04 +02:00
|
|
|
if (isset($this->commentMap[$key])) {
|
2014-08-30 12:23:12 +10:00
|
|
|
return $this->commentMap[$key];
|
2014-10-11 01:42:04 +02:00
|
|
|
}
|
2014-08-30 12:23:12 +10:00
|
|
|
|
2014-10-11 01:42:04 +02:00
|
|
|
if ($type == 'array') {
|
2014-08-30 12:23:12 +10:00
|
|
|
return $this->evalArrDesc($variable);
|
2014-10-11 01:42:04 +02:00
|
|
|
}
|
2014-08-30 12:23:12 +10:00
|
|
|
|
2014-10-11 01:42:04 +02:00
|
|
|
if ($type == 'object') {
|
2014-08-30 12:23:12 +10:00
|
|
|
return $this->evalObjDesc($variable);
|
2014-10-11 01:42:04 +02:00
|
|
|
}
|
2014-08-30 12:23:12 +10:00
|
|
|
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Evaluate an method type for description
|
|
|
|
* @param object $variable
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function evalMethodDesc($variable)
|
|
|
|
{
|
|
|
|
$parts = explode('|', $variable);
|
2014-10-11 01:42:04 +02:00
|
|
|
if (count($parts) < 2) {
|
2014-08-30 12:23:12 +10:00
|
|
|
return null;
|
2014-10-11 01:42:04 +02:00
|
|
|
}
|
2014-08-30 12:23:12 +10:00
|
|
|
|
|
|
|
$method = $parts[1];
|
|
|
|
return isset($this->commentMap[$method]) ? $this->commentMap[$method] : null;
|
2014-08-29 21:55:41 +10:00
|
|
|
}
|
|
|
|
|
2014-08-30 12:23:12 +10:00
|
|
|
/**
|
|
|
|
* Evaluate an array type for description
|
|
|
|
* @param array $variable
|
|
|
|
* @return string
|
|
|
|
*/
|
2014-08-29 21:55:41 +10:00
|
|
|
protected function evalArrDesc($variable)
|
|
|
|
{
|
|
|
|
$output = [];
|
|
|
|
foreach ($variable as $key => $value) {
|
|
|
|
$output[] = '<abbr title="'.e(gettype($value)).'">'.$key.'</abbr>';
|
|
|
|
}
|
|
|
|
|
|
|
|
return implode(', ', $output);
|
|
|
|
}
|
|
|
|
|
2014-08-30 12:23:12 +10:00
|
|
|
/**
|
|
|
|
* Evaluate an object type for description
|
|
|
|
* @param array $variable
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function evalObjDesc($variable)
|
|
|
|
{
|
|
|
|
$output = [];
|
|
|
|
if ($variable instanceof ComponentBase) {
|
|
|
|
$details = $variable->componentDetails();
|
|
|
|
$output[] = '<abbr title="'.array_get($details, 'description').'">';
|
|
|
|
$output[] = array_get($details, 'name');
|
|
|
|
$output[] = '</abbr>';
|
|
|
|
}
|
|
|
|
|
|
|
|
return implode('', $output);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Object helpers
|
|
|
|
//
|
|
|
|
|
|
|
|
protected function paginatorToArray(Paginator $paginator)
|
|
|
|
{
|
|
|
|
$this->commentMap = [
|
|
|
|
'links()' => 'Renders links for navigating the collection',
|
|
|
|
'currentPage' => 'Get the current page for the request.',
|
|
|
|
'lastPage' => 'Get the last page that should be available.',
|
|
|
|
'perPage' => 'Get the number of items to be displayed per page.',
|
|
|
|
'total' => 'Get the total number of items in the complete collection.',
|
|
|
|
'from' => 'Get the number of the first item on the paginator.',
|
|
|
|
'to' => 'Get the number of the last item on the paginator.',
|
|
|
|
'count' => 'Returns the number of items in this collection',
|
|
|
|
];
|
|
|
|
|
|
|
|
return [
|
|
|
|
'links' => '___METHOD___|links()',
|
|
|
|
'currentPage' => '___METHOD___|currentPage',
|
|
|
|
'lastPage' => '___METHOD___|lastPage',
|
|
|
|
'perPage' => '___METHOD___|perPage',
|
|
|
|
'total' => '___METHOD___|total',
|
|
|
|
'from' => '___METHOD___|from',
|
|
|
|
'to' => '___METHOD___|to',
|
|
|
|
'count' => '___METHOD___|count',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function objectToArray($object)
|
|
|
|
{
|
|
|
|
$class = get_class($object);
|
|
|
|
$info = new \ReflectionClass($object);
|
|
|
|
|
|
|
|
$this->commentMap[$class] = [];
|
|
|
|
|
|
|
|
$methods = [];
|
|
|
|
foreach ($info->getMethods() as $method) {
|
2014-10-11 01:42:04 +02:00
|
|
|
if (!$method->isPublic()) {
|
|
|
|
continue; // Only public
|
|
|
|
}
|
|
|
|
if ($method->class != $class) {
|
|
|
|
continue; // Only locals
|
|
|
|
}
|
2014-08-30 12:23:12 +10:00
|
|
|
$name = $method->getName();
|
2014-10-11 01:42:04 +02:00
|
|
|
if (in_array($name, $this->blockMethods)) {
|
|
|
|
continue; // Blocked methods
|
|
|
|
}
|
|
|
|
if (preg_match('/^on[A-Z]{1}[\w+]*$/', $name)) {
|
|
|
|
continue; // AJAX methods
|
|
|
|
}
|
|
|
|
if (preg_match('/^get[A-Z]{1}[\w+]*Options$/', $name)) {
|
|
|
|
continue; // getSomethingOptions
|
|
|
|
}
|
|
|
|
if (substr($name, 0, 1) == '_') {
|
|
|
|
continue; // Magic/hidden method
|
|
|
|
}
|
2014-08-30 12:23:12 +10:00
|
|
|
$name .= '()';
|
|
|
|
$methods[$name] = '___METHOD___|'.$name;
|
|
|
|
$this->commentMap[$name] = $this->evalDocBlock($method);
|
|
|
|
}
|
|
|
|
|
|
|
|
$vars = [];
|
|
|
|
foreach ($info->getProperties() as $property) {
|
2014-10-11 01:42:04 +02:00
|
|
|
if (!$property->isPublic()) {
|
|
|
|
continue; // Only public
|
|
|
|
}
|
|
|
|
if ($property->class != $class) {
|
|
|
|
continue; // Only locals
|
|
|
|
}
|
2014-08-30 12:23:12 +10:00
|
|
|
$name = $property->getName();
|
|
|
|
$vars[$name] = $object->{$name};
|
|
|
|
$this->commentMap[$name] = $this->evalDocBlock($property);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $methods + $vars;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function evalDocBlock($reflectionObj)
|
|
|
|
{
|
|
|
|
$comment = $reflectionObj->getDocComment();
|
|
|
|
$comment = substr($comment, 3, -2);
|
|
|
|
|
|
|
|
$parts = explode('@', $comment);
|
|
|
|
$comment = array_shift($parts);
|
|
|
|
$comment = trim(trim($comment), '*');
|
|
|
|
$comment = implode(' ', array_map('trim', explode('*', $comment)));
|
|
|
|
|
|
|
|
return $comment;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Style helpers
|
|
|
|
//
|
|
|
|
|
2014-08-29 21:55:41 +10:00
|
|
|
/**
|
|
|
|
* Get the CSS string for the output data
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2014-08-30 12:23:12 +10:00
|
|
|
protected function getDataCss($variable)
|
2014-08-29 21:55:41 +10:00
|
|
|
{
|
2014-08-30 12:23:12 +10:00
|
|
|
$css = [
|
2014-08-29 21:55:41 +10:00
|
|
|
'padding' => '7px',
|
|
|
|
'background-color' => $this->zebra ? '#D8D9DB' : '#FFF',
|
|
|
|
'color' => '#405261',
|
2014-08-30 12:23:12 +10:00
|
|
|
];
|
|
|
|
|
|
|
|
$type = gettype($variable);
|
2014-10-11 01:42:04 +02:00
|
|
|
if ($type == 'NULL') {
|
2014-08-30 12:23:12 +10:00
|
|
|
$css['color'] = '#999';
|
2014-10-11 01:42:04 +02:00
|
|
|
}
|
2014-08-30 12:23:12 +10:00
|
|
|
|
|
|
|
return $this->arrayToCss($css);
|
2014-08-29 21:55:41 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the CSS string for the output container
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function getContainerCss()
|
|
|
|
{
|
|
|
|
return $this->arrayToCss([
|
|
|
|
'background-color' => '#F3F3F3',
|
|
|
|
'border' => '1px solid #bbb',
|
|
|
|
'border-radius' => '4px',
|
|
|
|
'font-size' => '12px',
|
2014-08-30 12:34:03 +10:00
|
|
|
'line-height' => '18px',
|
|
|
|
'margin' => '20px',
|
2014-08-29 21:55:41 +10:00
|
|
|
'padding' => '7px',
|
|
|
|
'display' => 'inline-block',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the CSS string for the output header
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function getHeaderCss()
|
|
|
|
{
|
|
|
|
return $this->arrayToCss([
|
|
|
|
'font-size' => '18px',
|
|
|
|
'font-weight' => 'normal',
|
|
|
|
'margin' => '0',
|
|
|
|
'padding' => '10px',
|
|
|
|
'background-color' => '#7B8892',
|
|
|
|
'color' => '#FFF',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2014-10-23 20:32:55 +10:00
|
|
|
/**
|
|
|
|
* 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',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2014-08-29 21:55:41 +10:00
|
|
|
/**
|
|
|
|
* Convert a key/value pair array into a CSS string
|
|
|
|
*
|
|
|
|
* @param array $rules List of rules to process
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function arrayToCss(array $rules)
|
|
|
|
{
|
|
|
|
$strings = [];
|
|
|
|
|
|
|
|
foreach ($rules as $key => $value) {
|
|
|
|
$strings[] = $key . ': ' . $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return join('; ', $strings);
|
|
|
|
}
|
|
|
|
}
|