Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* Krumo: Structured information display solution
*
* Krumo is a debugging tool (PHP4/PHP5), which displays structured information
* about any PHP variable. It is a nice replacement for print_r() or var_dump()
* which are used by a lot of PHP developers.
*
* @author Kaloyan K. Tsvetkov <kaloyan@kaloyan.info>
* @license http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License Version 2.1
*
* @package Krumo
*/
//////////////////////////////////////////////////////////////////////////////
/**
* backward compatibility: the DIR_SEP constant isn't used anymore
*/
if(!defined('DIR_SEP')) {
define('DIR_SEP', DIRECTORY_SEPARATOR);
}
/**
* backward compatibility: the PATH_SEPARATOR constant is availble since 4.3.0RC2
*/
if (!defined('PATH_SEPARATOR')) {
define('PATH_SEPARATOR', OS_WINDOWS ? ';' : ':');
}
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
/**
* Set the KRUMO_DIR constant up with the absolute path to Krumo files. If it is
* not defined, include_path will be used. Set KRUMO_DIR only if any other module
* or application has not already set it up.
*/
if (!defined('KRUMO_DIR')) {
define('KRUMO_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);
}
/**
* This constant sets the maximum strings of strings that will be shown
* as they are. Longer strings will be truncated with this length, and
* their `full form` will be shown in a child node.
*/
if (!defined('KRUMO_TRUNCATE_LENGTH')) {
define('KRUMO_TRUNCATE_LENGTH', 50);
}
//////////////////////////////////////////////////////////////////////////////
/**
* Krumo API
*
* This class stores the Krumo API for rendering and
* displaying the structured information it is reporting
*
* @package Krumo
*/
Class krumo {
/**
* Return Krumo version
*
* @return string
* @access public
* @static
*/
static Function version() {
return '0.2a';
}
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
/**
* Prints a debug backtrace
*
* @access public
* @static
*/
static Function backtrace() {
// disabled ?
//
if (!krumo::_debug()) {
return false;
}
// render it
//
return krumo::dump(debug_backtrace());
}
/**
* Prints a list of all currently declared classes.
*
* @access public
* @static
*/
static Function classes() {
// disabled ?
//
if (!krumo::_debug()) {
return false;
}
// render it
//
?>
<div class="krumo-title">
This is a list of all currently declared classes.
</div>
<?php
return krumo::dump(get_declared_classes());
}
/**
* Prints a list of all currently declared interfaces (PHP5 only).
*
* @access public
* @static
*/
static Function interfaces() {
// disabled ?
//
if (!krumo::_debug()) {
return false;
}
// render it
//
?>
<div class="krumo-title">
This is a list of all currently declared interfaces.
</div>
<?php
return krumo::dump(get_declared_interfaces());
}
/**
* Prints a list of all currently included (or required) files.
*
* @access public
* @static
*/
static Function includes() {
// disabled ?
//
if (!krumo::_debug()) {
return false;
}
// render it
//
?>
<div class="krumo-title">
This is a list of all currently included (or required) files.
</div>
<?php
return krumo::dump(get_included_files());
}
/**
* Prints a list of all currently declared functions.
*
* @access public
* @static
*/
static Function functions() {
// disabled ?
//
if (!krumo::_debug()) {
return false;
}
// render it
//
?>
<div class="krumo-title">
This is a list of all currently declared functions.
</div>
<?php
return krumo::dump(get_defined_functions());
}
/**
* Prints a list of all currently declared constants.
*
* @access public
* @static
*/
static Function defines() {
// disabled ?
//
if (!krumo::_debug()) {
return false;
}
// render it
//
?>
<div class="krumo-title">
This is a list of all currently declared constants (defines).
</div>
<?php
return krumo::dump(get_defined_constants());
}
/**
* Prints a list of all currently loaded PHP extensions.
*
* @access public
* @static
*/
static Function extensions() {
// disabled ?
//
if (!krumo::_debug()) {
return false;
}
// render it
//
?>
<div class="krumo-title">
This is a list of all currently loaded PHP extensions.
</div>
<?php
return krumo::dump(get_loaded_extensions());
}
/**
* Prints a list of all HTTP request headers.
*
* @access public
* @static
*/
static Function headers() {
// disabled ?
//
if (!krumo::_debug()) {
return false;
}
// render it
//
?>
<div class="krumo-title">
This is a list of all HTTP request headers.
</div>
<?php
return krumo::dump(getAllHeaders());
}
/**
* Prints a list of the configuration settings read from <i>php.ini</i>
*
* @access public
* @static
*/
static Function phpini() {
// disabled ?
//
if (!krumo::_debug()) {
return false;
}
// render it
//
?>
<div class="krumo-title">
This is a list of the configuration settings read from <code><b><?php echo get_cfg_var('cfg_file_path');?></b></code>.
</div>
<?php
return krumo::dump(parse_ini_file(get_cfg_var('cfg_file_path'), true));
}
/**
* Prints a list of all your configuration settings.
*
* @access public
* @static
*/
static Function conf() {
// disabled ?
//
if (!krumo::_debug()) {
return false;
}
// render it
//
?>
<div class="krumo-title">
This is a list of all your configuration settings.
</div>
<?php
return krumo::dump(ini_get_all());
}
/**
* Prints a list of the specified directories under your <i>include_path</i> option.
*
* @access public
* @static
*/
static Function path() {
// disabled ?
//
if (!krumo::_debug()) {
return false;
}
// render it
//
?>
<div class="krumo-title">
This is a list of the specified directories under your <code><b>include_path</b></code> option.
</div>
<?php
return krumo::dump(explode(PATH_SEPARATOR, ini_get('include_path')));
}
/**
* Prints a list of all the values from the <i>$_REQUEST</i> array.
*
* @access public
* @static
*/
static Function request() {
// disabled ?
//
if (!krumo::_debug()) {
return false;
}
// render it
//
?>
<div class="krumo-title">
This is a list of all the values from the <code><b>$_REQUEST</b></code> array.
</div>
<?php
return krumo::dump($_REQUEST);
}
/**
* Prints a list of all the values from the <i>$_GET</i> array.
*
* @access public
* @static
*/
static Function get() {
// disabled ?
//
if (!krumo::_debug()) {
return false;
}
// render it
//
?>
<div class="krumo-title">
This is a list of all the values from the <code><b>$_GET</b></code> array.
</div>
<?php
return krumo::dump($_GET);
}
/**
* Prints a list of all the values from the <i>$_POST</i> array.
*
* @access public
* @static
*/
static Function post() {
// disabled ?
//
if (!krumo::_debug()) {
return false;
}
// render it
//
?>
<div class="krumo-title">
This is a list of all the values from the <code><b>$_POST</b></code> array.
</div>
<?php
return krumo::dump($_POST);
}
/**
* Prints a list of all the values from the <i>$_SERVER</i> array.
*
* @access public
* @static
*/
static Function server() {
// disabled ?
//
if (!krumo::_debug()) {
return false;
}
// render it
//
?>
<div class="krumo-title">
This is a list of all the values from the <code><b>$_SERVER</b></code> array.
</div>
<?php
return krumo::dump($_SERVER);
}
/**
* Prints a list of all the values from the <i>$_COOKIE</i> array.
*
* @access public
* @static
*/
static Function cookie() {
// disabled ?
//
if (!krumo::_debug()) {
return false;
}
// render it
//
?>
<div class="krumo-title">
This is a list of all the values from the <code><b>$_COOKIE</b></code> array.
</div>
<?php
return krumo::dump($_COOKIE);
}
/**
* Prints a list of all the values from the <i>$_ENV</i> array.
*
* @access public
* @static
*/
static Function env() {
// disabled ?
//
if (!krumo::_debug()) {
return false;
}
// render it
//
?>
<div class="krumo-title">
This is a list of all the values from the <code><b>$_ENV</b></code> array.
</div>
<?php
return krumo::dump($_ENV);
}
/**
* Prints a list of all the values from the <i>$_SESSION</i> array.
*
* @access public
* @static
*/
static Function session() {
// disabled ?
//
if (!krumo::_debug()) {
return false;
}
// render it
//
?>
<div class="krumo-title">
This is a list of all the values from the <code><b>$_SESSION</b></code> array.
</div>
<?php
return krumo::dump($_SESSION);
}
/**
* Prints a list of all the values from an INI file.
*
* @param string $ini_file
*
* @access public
* @static
*/
static Function ini($ini_file) {
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
// disabled ?
//
if (!krumo::_debug()) {
return false;
}
// read it
//
if (!$_ = @parse_ini_file($ini_file, 1)) {
return false;
}
// render it
//
?>
<div class="krumo-title">
This is a list of all the values from the <code><b><?php echo realpath($ini_file) ? realpath($ini_file) : $ini_file;?></b></code> INI file.
</div>
<?php
return krumo::dump($_);
}
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
/**
* Dump information about a variable
*
* @param mixed $data,...
* @access public
* @static
*/
static Function dump($data) {
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
// disabled ?
//
if (!krumo::_debug()) {
return false;
}
// more arguments ?
//
if (func_num_args() > 1) {
$_ = func_get_args();
foreach($_ as $d) {
krumo::dump($d);
}
return;
}
// the css ?
//
krumo::_css();
// find caller
// DEVEL: we added array_reverse() so the proper file+line number is found.
$_ = array_reverse(debug_backtrace());
while($d = array_pop($_)) {
// DEVEL: changed if() condition below
if ((strpos(@$d['file'], 'devel') === FALSE) && (strpos(@$d['file'], 'krumo') === FALSE) && @$d['class'] != 'krumo') {
break;
}
}
// the content
//
?>
<div class="krumo-root" dir="ltr">
<ul class="krumo-node krumo-first">
<?php echo krumo::_dump($data);?>
<li class="krumo-footnote">
<div class="krumo-version" style="white-space:nowrap;">
<h6>Krumo version <?php echo krumo::version();?></h6> | <a
href="http://krumo.sourceforge.net"
target="_blank">http://krumo.sourceforge.net</a>
</div>
<?php if (@$d['file']) { ?>
<span class="krumo-call" style="white-space:nowrap;">
Called from <code><?php echo $d['file']?></code>,
line <code><?php echo $d['line']?></code></span>
<?php } ?>
</li>
</ul>
</div>
<?php
// flee the hive
//
$_recursion_marker = krumo::_marker();
if ($hive =& krumo::_hive($dummy)) {
foreach($hive as $i=>$bee){
if (is_object($bee)) {
unset($hive[$i]->$_recursion_marker);
} else {
unset($hive[$i][$_recursion_marker]);
}
}
}
// PHP 4.x.x array reference bug...
//
if (is_array($data) && version_compare(PHP_VERSION, "5", "<")) {
unset($GLOBALS[krumo::_marker()]);
}
}
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
/**
* Print the skin (CSS)
*
* @return boolean
* @access private
* @static
*/
static Function _css() {
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
static $_css = false;
// already set ?
//
if ($_css) {
return true;
}
$css = '';
// DEVEL: changed for Drupal variables system
$skin = variable_get('devel_krumo_skin', 'orange');
// custom selected skin ?
//
$_ = KRUMO_DIR . "skins/{$skin}/skin.css";
if ($fp = @fopen($_, 'r', 1)) {
$css = fread($fp, filesize($_));
fclose($fp);
}
// defautl skin ?
//
if (!$css && ($skin != 'default')) {
$skin = 'default';
$_ = KRUMO_DIR . "skins/default/skin.css";
$css = join('', @file($_));
}
// print ?
//
if ($_css = $css != '') {
// fix the urls
//
// DEVEL: changed for Drupal path system.
$css_url = base_path() . drupal_get_path('module', 'devel') . "/krumo/skins/{$skin}/";
$css = preg_replace('~%url%~Uis', $css_url, $css);
// the CSS
//
?>
<!-- Using Krumo Skin: <?php echo preg_replace('~^' . preg_quote(realpath(KRUMO_DIR) . DIRECTORY_SEPARATOR) . '~Uis', '', realpath($_));?> -->
<style type="text/css">
<!--/**/
<?php echo $css?>
/**/-->
</style>
<?php
// the JS
//
?>
<script type="text/javascript">
<!--//
<?php echo join(file(KRUMO_DIR . "krumo.js"));?>
//-->
</script>
<?php
}
return $_css;
}
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
/**
* Enable Krumo
*
* @return boolean
* @access public
* @static
*/
static Function enable() {
return true === krumo::_debug(true);
}
/**
* Disable Krumo
*
* @return boolean
* @access public
* @static
*/
static Function disable() {
return false === krumo::_debug(false);
}
/**
* Get\Set Krumo state: whether it is enabled or disabled
*
* @param boolean $state
* @return boolean
* @access private
* @static
*/
static Function _debug($state=null) {
static $_ = true;
// set
//
if (isset($state)) {
$_ = (boolean) $state;
}
// get
//
return $_;
}
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
/**
* Dump information about a variable
*
* @param mixed $data
* @param string $name
* @access private
* @static
*/
static Function _dump(&$data, $name='...') {
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
// object ?
//
if (is_object($data)) {
return krumo::_object($data, $name);
}
// array ?
//
if (is_array($data)) {
// PHP 4.x.x array reference bug...
//
if (version_compare(PHP_VERSION, "5", "<")) {
// prepare the GLOBAL reference list...
//
if (!isset($GLOBALS[krumo::_marker()])) {
$GLOBALS[krumo::_marker()] = array();
}
if (!is_array($GLOBALS[krumo::_marker()])) {
$GLOBALS[krumo::_marker()] = (array) $GLOBALS[krumo::_marker()];
}
// extract ?
//
if (!empty($GLOBALS[krumo::_marker()])) {
$d = array_shift($GLOBALS[krumo::_marker()]);
if (is_array($d)) {
$data = $d;
}
}
}
return krumo::_array($data, $name);
}
// resource ?
//
if (is_resource($data)) {
return krumo::_resource($data, $name);
}
// scalar ?
//
if (is_string($data)) {
return krumo::_string($data, $name);
}
if (is_float($data)) {
return krumo::_float($data, $name);
}
if (is_integer($data)) {
return krumo::_integer($data, $name);
}
if (is_bool($data)) {
return krumo::_boolean($data, $name);
}
// null ?
//
if (is_null($data)) {
return krumo::_null($name);
}
}
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
/**
* Render a dump for a NULL value
*
* @param string $name
* @return string
* @access private
* @static
*/
static Function _null($name) {
?>
<li class="krumo-child">
<div class="krumo-element"
onMouseOver="krumo.over(this);"
onMouseOut="krumo.out(this);">
<a class="krumo-name"><?php echo $name;?></a>
(<em class="krumo-type krumo-null">NULL</em>)
</div>
</li>
<?php
}
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
/**
* Return the marked used to stain arrays
* and objects in order to detect recursions
*
* @return string
* @access private
* @static
*/
static Function _marker() {
static $_recursion_marker;
if (!isset($_recursion_marker)) {
$_recursion_marker = uniqid('krumo');
}
return $_recursion_marker;
}
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
/**
* Adds a variable to the hive of arrays and objects which
* are tracked for whether they have recursive entries
*
* @param mixed &$bee either array or object, not a scallar vale
* @return array all the bees
*
* @access private
* @static
*/
static Function &_hive(&$bee) {
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
static $_ = array();
// new bee ?
//
if (!is_null($bee)) {
// stain it
//
$_recursion_marker = krumo::_marker();
(is_object($bee))
? @($bee->$_recursion_marker++)
: @($bee[$_recursion_marker]++);
$_[0][] =& $bee;
}
// return all bees
//
return $_[0];
}
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
/**
* Render a dump for the properties of an array or objeect
*
* @param mixed &$data
* @access private
* @static
*/
static Function _vars(&$data) {
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
$_is_object = is_object($data);
// test for references in order to
// prevent endless recursion loops
//
$_recursion_marker = krumo::_marker();
$_r = ($_is_object)
? @$data->$_recursion_marker
: @$data[$_recursion_marker] ;
$_r = (integer) $_r;
// recursion detected
//
if ($_r > 0) {
return krumo::_recursion();
}
// stain it
//
krumo::_hive($data);
// render it
//
?>
<div class="krumo-nest" style="display:none;">
<ul class="krumo-node">
<?php
// keys ?
//
$keys = ($_is_object)
? array_keys(get_object_vars($data))
: array_keys($data);
// itterate
//
foreach($keys as $k) {
// skip marker
//
if ($k === $_recursion_marker) {
continue;
}
// get real value
//
if ($_is_object) {
$v =& $data->$k;
} else {
$v =& $data[$k];
}
// PHP 4.x.x array reference bug...
//
if (is_array($data) && version_compare(PHP_VERSION, "5", "<")) {
$GLOBALS[krumo::_marker()][] =& $v;
}
krumo::_dump($v,$k);
} ?>
</ul>
</div>
<?php
}
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
/**
* Render a block that detected recursion
*
* @access private
* @static
*/
static Function _recursion() {
?>
<div class="krumo-nest" style="display:none;">
<ul class="krumo-node">
<li class="krumo-child">
<div class="krumo-element"
onMouseOver="krumo.over(this);"
onMouseOut="krumo.out(this);">
<a class="krumo-name"><big>∞</big></a>
(<em class="krumo-type">Recursion</em>)
</div>
</li>
</ul>
</div>