From fcf31b05aee587ee64f641c376dca4295aeb48eb Mon Sep 17 00:00:00 2001 From: Sam Georges Date: Sat, 30 Aug 2014 12:34:03 +1000 Subject: [PATCH] Added new dump() Twig function --- CHANGELOG.md | 3 +++ modules/cms/twig/DebugExtension.php | 22 ++++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ffe05d98..a199e475d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +* **Build 14x** (2014-09-xx) + - Add new `dump()` Twig function (config app.debug must be true). + * **Build 139** (2014-08-30) - Components and variables can now be accessed in the page code section via `$this->foo` in addition to `$this['foo']`. - AJAX handlers in the CMS can now invoke the page cycle without rendering the page using `$this->pageCycle()`. diff --git a/modules/cms/twig/DebugExtension.php b/modules/cms/twig/DebugExtension.php index fa8fc22fb..4ed828d6e 100644 --- a/modules/cms/twig/DebugExtension.php +++ b/modules/cms/twig/DebugExtension.php @@ -14,6 +14,7 @@ class DebugExtension extends Twig_Extension { const PAGE_CAPTION = 'Page variables'; const OBJECT_CAPTION = 'Object variables'; + const COMPONENT_CAPTION = 'Component variables'; /** * @var \Cms\Classes\Controller A reference to the CMS controller. @@ -88,7 +89,12 @@ class DebugExtension extends Twig_Extension else { $this->variablePrefix = false; for ($i = 2; $i < $count; $i++) { - $result .= $this->dump(func_get_arg($i), static::OBJECT_CAPTION); + $var = func_get_arg($i); + $caption = $var instanceof ComponentBase + ? static::COMPONENT_CAPTION + : static::OBJECT_CAPTION; + + $result .= $this->dump($var, $caption); } } @@ -245,6 +251,9 @@ class DebugExtension extends Twig_Extension elseif ($variable instanceof Collection) $label = 'Collection('.$variable->count().')'; + elseif ($variable instanceof Paginator) + $label = 'Paged Collection('.$variable->count().')'; + elseif ($variable instanceof Model) $label = 'Model'; @@ -362,12 +371,12 @@ class DebugExtension extends Twig_Extension $methods = []; foreach ($info->getMethods() as $method) { - if (!$method->isPublic()) continue; + if (!$method->isPublic()) continue; // Only public + if ($method->class != $class) continue; // Only locals $name = $method->getName(); 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 ($method->class != $class) continue; // Only locals if (substr($name, 0, 1) == '_') continue; // Magic/hidden method $name .= '()'; $methods[$name] = '___METHOD___|'.$name; @@ -376,7 +385,8 @@ class DebugExtension extends Twig_Extension $vars = []; foreach ($info->getProperties() as $property) { - if (!$property->isPublic()) continue; + if (!$property->isPublic()) continue; // Only public + if ($property->class != $class) continue; // Only locals $name = $property->getName(); $vars[$name] = $object->{$name}; $this->commentMap[$name] = $this->evalDocBlock($property); @@ -435,8 +445,8 @@ class DebugExtension extends Twig_Extension 'border' => '1px solid #bbb', 'border-radius' => '4px', 'font-size' => '12px', - 'line-height' => '1.4em', - 'margin' => '30px', + 'line-height' => '18px', + 'margin' => '20px', 'padding' => '7px', 'display' => 'inline-block', ]);