This class stores the Krumo API for rendering and displaying the structured information it is reporting
Example #1
0
 /**
  * Render a dump for a string value
  *
  * @param mixed $data
  * @param string $name
  * @access private
  * @static
  */
 private static function _string($data, $name)
 {
     $collapsed = Krumo::_isCollapsed(self::$_level, 1);
     if ($collapsed) {
         $collapse_style = 'style="display: none;"';
     } else {
         $collapse_style = '';
     }
     // extra
     $_extra = false;
     $_ = $data;
     // Get the truncate length from the config, or default to 100
     $truncate_length = Krumo::_config('display', 'truncate_length', 100);
     $display_cr = Krumo::_config('display', 'carriage_returns', true);
     if (strLen($data) > $truncate_length) {
         $_ = substr($data, 0, $truncate_length - 1);
         $_extra = true;
     }
     $_ = htmlentities($_);
     if ($display_cr) {
         $_ = preg_replace("/\\n/", "<strong class=\"krumo-carrage-return\"> &para; </strong>", $_);
     } else {
         $_ = nl2br($_);
     }
     $expand_class = '';
     if ($_extra) {
         $expand_class = 'krumo-expand';
     }
     print "<li class=\"krumo-child\">";
     print "<div class=\"krumo-element {$expand_class}\" ";
     if ($_extra) {
         print " onClick=\"krumo.toggle(this);\" ";
     }
     print "onMouseOver=\"krumo.over(this);\" onMouseOut=\"krumo.out(this);\">\n";
     print "<a class=\"krumo-name\">{$name}</a> ";
     print "<em class=\"krumo-type\">String(<strong class=\"krumo-string-length\">" . strlen($data) . "</strong>)</em> ";
     print Krumo::get_separator() . " <strong class=\"krumo-string\">" . $_;
     // This has to go AFTER the htmlspecialchars
     if ($_extra) {
         print "&hellip;";
     }
     print "</strong>";
     $ut = Krumo::is_datetime($name, $data);
     if ($ut) {
         print " ~ <strong class=\"krumo-datetime\">{$ut}</strong>";
     }
     // callback
     if (is_callable($data)) {
         print "<span class=\"krumo-callback\"> | ";
         print "(<em class=\"krumo-type\">Callback</em>) <strong class=\"krumo-string\">" . htmlSpecialChars($_) . "()</strong></span>";
     }
     print "</div>";
     if ($_extra) {
         $data = htmlentities($data);
         if ($display_cr) {
             $data = preg_replace("/\\n/", "<strong class=\"krumo-carrage-return\"> &para; </strong>", $data);
         } else {
             $data = nl2br($data);
         }
         print "<div class=\"krumo-nest\" {$collapse_style}>";
         print "<ul class=\"krumo-node\">";
         print "<li class=\"krumo-child\"> <div class=\"krumo-preview\">" . $data . "</div></li>";
         print "</ul></div>";
     }
     print "</li>";
 }
Example #2
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;
 }
Example #3
0
 /**
  * Output pretty-printed arrays / objects.
  *
  * @see \krumo::dump
  * @see https://github.com/oodle/krumo
  *
  * @param  mixed $var
  * @return string
  */
 public function printDump($var)
 {
     $output = \Krumo::dump($var, KRUMO_CAPTURE);
     return $output;
 }
Example #4
0
 /**
  * Render a dump for a string value
  *
  * @param mixed $data
  * @param string $name
  * @access private
  * @static
  */
 private static function _string($data, $name)
 {
     $collapsed = Krumo::_isCollapsed(self::$_level, 1);
     if ($collapsed) {
         $collapse_style = 'style="display: none;"';
     } else {
         $collapse_style = '';
     }
     // extra
     $_ = $data;
     // Get the truncate length from the config, or default to 100
     $truncate_length = Krumo::_config('display', 'truncate_length', 100);
     $display_cr = Krumo::_config('display', 'carriage_returns', true);
     if (strlen($data) > $truncate_length) {
         $_ = substr($data, 0, $truncate_length - 1);
         $_extra = true;
     } else {
         $_extra = false;
     }
     $icon = '';
     // Check to see if the line has any carriage returns
     if (preg_match("/\n|\r/", $data)) {
         $slash_n = substr_count($data, "\n");
         $slash_r = substr_count($data, "\r");
         $title .= "Note: String contains ";
         if ($slash_n) {
             $title .= "{$slash_n} " . krumo::plural($slash_n, "new line");
         }
         if ($slash_n && $slash_r) {
             $title .= " and ";
         }
         if ($slash_r) {
             $title .= "{$slash_r} " . krumo::plural($slash_r, "carriage return");
         }
         $icon = Krumo::get_icon("information", $title);
         // We flag this as extra so the dropdown can show the correctly formatted version
         $_extra = true;
     }
     $_ = htmlentities($_);
     // Convert all the \r or \n to visible paragraph markers
     if ($display_cr) {
         $_ = preg_replace("/(\\r\\n|\\n|\\r)/", "<strong class=\"krumo-carrage-return\"> &para; </strong>", $_);
     } else {
         $_ = nl2br($_);
     }
     $expand_class = '';
     if ($_extra) {
         $expand_class = 'krumo-expand';
     }
     print "<li class=\"krumo-child\">";
     print "<div class=\"krumo-element {$expand_class}\" ";
     if ($_extra) {
         print " onClick=\"krumo.toggle(this);\" ";
     }
     print "onMouseOver=\"krumo.over(this);\" onMouseOut=\"krumo.out(this);\">\n";
     print "<a class=\"krumo-name\">{$name}</a> ";
     print "<em class=\"krumo-type\">String(<strong class=\"krumo-string-length\">" . strlen($data) . "</strong>)</em> {$icon}";
     print Krumo::get_separator() . " <strong class=\"krumo-string\">" . $_;
     // This has to go AFTER the htmlspecialchars
     if (strlen($data) > $truncate_length) {
         print "&hellip;";
     }
     print "</strong>";
     $ut = Krumo::is_datetime($name, $data);
     if ($ut) {
         print " ~ <strong class=\"krumo-datetime\">{$ut}</strong>";
     }
     // callback
     if (is_callable($data)) {
         print "<span class=\"krumo-callback\"> | ";
         print "(<em class=\"krumo-type\">Callback</em>) <strong class=\"krumo-string\">" . htmlSpecialChars($_) . "()</strong></span>";
     }
     print "</div>";
     if ($_extra) {
         $data = htmlentities($data);
         $data = nl2br($data);
         print "<div class=\"krumo-nest\" {$collapse_style}>";
         print "<ul class=\"krumo-node\">";
         print "<li class=\"krumo-child\"> <div class=\"krumo-preview\">" . $data . "</div></li>";
         print "</ul></div>";
     }
     print "</li>";
 }