DebugKit\View\Helper\ToolbarHelper::makeNeatArray PHP Method

makeNeatArray() public method

Recursively goes through an array and makes neat HTML out of it.
public makeNeatArray ( mixed $values, integer $openDepth, integer $currentDepth, boolean $doubleEncode = false, SplObjectStorage $currentAncestors = null ) : string
$values mixed Array to make pretty.
$openDepth integer Depth to add open class
$currentDepth integer current depth.
$doubleEncode boolean Whether or not to double encode.
$currentAncestors SplObjectStorage Object references found down the path.
return string
    public function makeNeatArray($values, $openDepth = 0, $currentDepth = 0, $doubleEncode = false, \SplObjectStorage $currentAncestors = null)
    {
        if ($currentAncestors === null) {
            $ancestors = new \SplObjectStorage();
        } elseif (is_object($values)) {
            $ancestors = new \SplObjectStorage();
            $ancestors->addAll($currentAncestors);
            $ancestors->attach($values);
        } else {
            $ancestors = $currentAncestors;
        }
        $className = "neat-array depth-{$currentDepth}";
        if ($openDepth > $currentDepth) {
            $className .= ' expanded';
        }
        $nextDepth = $currentDepth + 1;
        $out = "<ul class=\"{$className}\">";
        if (!is_array($values)) {
            if (is_bool($values)) {
                $values = [$values];
            }
            if ($values === null) {
                $values = [null];
            }
            if (is_object($values) && method_exists($values, 'toArray')) {
                $values = $values->toArray();
            }
        }
        if (empty($values)) {
            $values[] = '(empty)';
        }
        if ($this->sort && is_array($values) && $currentDepth === 0) {
            ksort($values);
        }
        foreach ($values as $key => $value) {
            $out .= '<li><strong>' . h($key, $doubleEncode) . '</strong>';
            if (is_array($value) && count($value) > 0) {
                $out .= '(array)';
            } elseif (is_object($value)) {
                $out .= '(object)';
            }
            if ($value === null) {
                $value = '(null)';
            }
            if ($value === false) {
                $value = '(false)';
            }
            if ($value === true) {
                $value = '(true)';
            }
            if (empty($value) && $value != 0) {
                $value = '(empty)';
            }
            if ($value instanceof Closure) {
                $value = 'function';
            }
            $isObject = is_object($value);
            if ($isObject && $ancestors->contains($value)) {
                $isObject = false;
                $value = ' - recursion';
            }
            if (($value instanceof ArrayAccess || $value instanceof Iterator || is_array($value) || $isObject) && !empty($value)) {
                $out .= $this->makeNeatArray($value, $openDepth, $nextDepth, $doubleEncode, $ancestors);
            } else {
                $out .= h($value, $doubleEncode);
            }
            $out .= '</li>';
        }
        $out .= '</ul>';
        return $out;
    }