_hive() private static method

private static _hive ( &$bee )
Ejemplo n.º 1
0
 /**
  * Render a dump for the properties of an array or objeect
  *
  * @param mixed &$data
  * @access private
  * @static
  */
 private static function _vars(&$data)
 {
     $_is_object = is_object($data);
     // test for references in order to
     // prevent endless recursion loops
     $_recursion_marker = Krumo::_marker();
     if ($_is_object) {
         if (($hash = spl_object_hash($data)) && isset(self::$objectRecursionProtection[$hash])) {
             $_r = self::$objectRecursionProtection[$hash];
         } else {
             $_r = NULL;
         }
     } else {
         $_r = isset($data[$_recursion_marker]) ? $data[$_recursion_marker] : null;
     }
     // recursion detected
     if ($_r > 0) {
         return Krumo::_recursion();
     }
     // stain it
     Krumo::_hive($data);
     // render it
     $collapsed = Krumo::_isCollapsed(self::$_level, count($data) - 1);
     if ($collapsed) {
         $collapse_style = 'style="display: none;"';
     } else {
         $collapse_style = '';
     }
     print "<div class=\"krumo-nest\" {$collapse_style}>";
     print "<ul class=\"krumo-node\">";
     // we're descending one level deeper
     self::$_level++;
     // Object?? - use Reflection
     if ($_is_object) {
         $reflection = new ReflectionObject($data);
         $properties = $reflection->getProperties();
         foreach ($properties as $property) {
             $prefix = null;
             $setAccessible = false;
             if ($property->isPrivate()) {
                 $setAccessible = true;
                 $prefix = 'private';
             } elseif ($property->isProtected()) {
                 $setAccessible = true;
                 $prefix = 'protected';
             } elseif ($property->isPublic()) {
                 $prefix = 'public';
             }
             $name = $property->getName();
             if ($setAccessible) {
                 $property->setAccessible(true);
             }
             $value = $property->getValue($data);
             Krumo::_dump($value, "<span>{$prefix}</span>&nbsp;{$name}");
             if ($setAccessible) {
                 $property->setAccessible(false);
             }
         }
     } else {
         // keys
         $keys = array_keys($data);
         // iterate
         foreach ($keys as $k) {
             // skip marker
             if ($k === $_recursion_marker) {
                 continue;
             }
             // get real value
             $v =& $data[$k];
             Krumo::_dump($v, $k);
         }
     }
     print "</ul>\n</div>";
     self::$_level--;
 }