Customvar view helper: show structured data

refs #7569
This commit is contained in:
Thomas Gelf 2014-11-06 16:10:52 +01:00
parent cd9e3693e4
commit a8326350d1
1 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,55 @@
<?php
class Zend_View_Helper_Customvar extends Zend_View_Helper_Abstract
{
/**
* Create dispatch instance
*
* @return self
*/
public function checkPerformance()
{
return $this;
}
public function customvar($struct)
{
if (is_string($struct) || is_int($struct) || is_float($struct)) {
return $this->view->escape((string) $struct);
} elseif (is_array($struct)) {
return $this->renderArray($struct);
} elseif (is_object($struct)) {
return $this->renderObject($struct);
}
}
protected function renderArray($array)
{
if (empty($array)) {
return '[]';
}
$out = "<ul>\n";
foreach ($array as $val) {
$out .= '<li>' . $this->customvar($val) . "</li>\n";
}
return $out . "</ul>\n";
}
protected function renderObject($object)
{
if (empty($object)) {
return '{}';
}
$out = "{<ul>\n";
foreach ($object as $key => $val) {
$out .= '<li>'
. $this->view->escape($key)
. ' => '
. $this->customvar($val)
. "</li>\n";
}
return $out . "</ul>}";
}
}