예제 #1
0
 /**
  * Dump information about a variable
  *
  * @param mixed $data,...
  * @access public
  * @static
  * @return bool
  */
 public static function dump($data, $second = '')
 {
     if (static::isCli()) {
         $args = func_get_args();
         krumo::cli_dump($args);
         return true;
     }
     // If we're capturing call dump() with just data and capture the output
     if ($second === KRUMO_RETURN) {
         ob_start();
         static::dump($data);
         $str = ob_get_clean();
         return $str;
         // If we were given expand all, set the global variable
     } elseif ($second === KRUMO_EXPAND_ALL) {
         static::$expand_all = true;
         static::dump($data);
         return true;
     } elseif ($second === KRUMO_NO_SORT) {
         self::$sort = false;
         Krumo::dump($data);
         return true;
     } elseif ($second === KRUMO_SORT) {
         self::$sort = true;
         Krumo::dump($data);
         return true;
     }
     $clearObjectRecursionProtection = false;
     if (static::$objectRecursionProtection === null) {
         static::$objectRecursionProtection = array();
         $clearObjectRecursionProtection = true;
     }
     // disabled
     if (!static::_debug()) {
         return false;
     }
     // more arguments
     if (func_num_args() > 1) {
         $_ = func_get_args();
         $result = true;
         foreach ($_ as $d) {
             $result = $result && static::dump($d);
         }
         return $result;
     }
     // find caller
     $_ = debug_backtrace();
     while ($d = array_pop($_)) {
         $callback = static::$lineNumberTestCallback;
         $function = strToLower($d['function']);
         if (in_array($function, array("krumo", "k", "kd")) || strToLower(@$d['class']) == 'krumo' || is_callable($callback) && call_user_func($callback, $d)) {
             break;
         }
     }
     $showVersion = static::_config('display', 'show_version', true);
     $showCallInfo = static::_config('display', 'show_call_info', true);
     $krumoUrl = 'https://github.com/mmucklo/krumo';
     //////////////////////
     // Start HTML header//
     //////////////////////
     print "<div class=\"krumo-root\">\n";
     print "\t<ul class=\"krumo-node krumo-first\">\n";
     // The actual item itself
     static::_dump($data);
     if ($showVersion || $showCallInfo) {
         print "\t\t<li class=\"krumo-footnote\" onDblClick=\"toggle_expand_all();\">\n";
         if ($showCallInfo && isset($d['file']) && $d['file']) {
             print "<span class=\"krumo-call\" style=\"white-space:nowrap;\">";
             print "Called from <strong><code>" . $d['file'] . "</code></strong>, ";
             print "line <strong><code>" . $d['line'] . "</code></strong></span>";
         }
         if ($showVersion) {
             $version = static::version();
             print "<span class=\"krumo-version\" style=\"white-space:nowrap;\">\n";
             print "<strong class=\"krumo-version-number\">Krumo version {$version}</strong> | <a href=\"{$krumoUrl}\" target=\"_blank\">{$krumoUrl}</a>\n";
             print "</span>\n";
         }
         print "</li>";
     }
     print "</ul></div>\n";
     print "<!-- Krumo - HTML -->\n\n";
     // Output the CSS and JavaScript AFTER the HTML
     static::_css();
     ////////////////////
     // End HTML header//
     ////////////////////
     // flee the hive
     $_recursion_marker = static::_marker();
     if ($hive =& static::_hive($dummy)) {
         foreach ($hive as $i => $bee) {
             if (is_object($bee)) {
                 if (($hash = spl_object_hash($bee)) && isset(static::$objectRecursionProtection[$hash])) {
                     unset(static::$objectRecursionProtection[$hash]);
                 }
             } elseif (isset($hive[$i]->{$_recursion_marker})) {
                 unset($hive[$i][$_recursion_marker]);
             }
         }
     }
     if ($clearObjectRecursionProtection) {
         static::$objectRecursionProtection = null;
     }
     return true;
 }