Skip to content

Commit

Permalink
Customvar view helper: show structured data
Browse files Browse the repository at this point in the history
refs #7569
  • Loading branch information
Thomas-Gelf committed Nov 6, 2014
1 parent cd9e369 commit a832635
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions modules/monitoring/application/views/helpers/Customvar.php
@@ -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>}";
}

}

0 comments on commit a832635

Please sign in to comment.