class.krumo.php 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315
  1. <?php
  2. /**
  3. * Krumo: Structured information display solution
  4. *
  5. * Krumo is a debugging tool (PHP5 only), which displays structured information
  6. * about any PHP variable. It is a nice replacement for print_r() or var_dump()
  7. * which are used by a lot of PHP developers.
  8. *
  9. * @author Kaloyan K. Tsvetkov <kaloyan@kaloyan.info>
  10. * @license http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License Version 2.1
  11. *
  12. * @package Krumo
  13. */
  14. //////////////////////////////////////////////////////////////////////////////
  15. /**
  16. * backward compatibility: the DIR_SEP constant isn't used anymore
  17. */
  18. if(!defined('DIR_SEP')) {
  19. define('DIR_SEP', DIRECTORY_SEPARATOR);
  20. }
  21. /**
  22. * backward compatibility: the PATH_SEPARATOR constant is availble since 4.3.0RC2
  23. */
  24. if (!defined('PATH_SEPARATOR')) {
  25. define('PATH_SEPARATOR', OS_WINDOWS ? ';' : ':');
  26. }
  27. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  28. /**
  29. * Set the KRUMO_DIR constant up with the absolute path to Krumo files. If it is
  30. * not defined, include_path will be used. Set KRUMO_DIR only if any other module
  31. * or application has not already set it up.
  32. */
  33. if (!defined('KRUMO_DIR')) {
  34. define('KRUMO_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);
  35. }
  36. /**
  37. * This constant sets the maximum strings of strings that will be shown
  38. * as they are. Longer strings will be truncated with this length, and
  39. * their `full form` will be shown in a child node.
  40. */
  41. if (!defined('KRUMO_TRUNCATE_LENGTH')) {
  42. define('KRUMO_TRUNCATE_LENGTH', 50);
  43. }
  44. //////////////////////////////////////////////////////////////////////////////
  45. /**
  46. * Krumo API
  47. *
  48. * This class stores the Krumo API for rendering and
  49. * displaying the structured information it is reporting
  50. *
  51. * @package Krumo
  52. */
  53. Class krumo {
  54. /**
  55. * Return Krumo version
  56. *
  57. * @return string
  58. * @access public
  59. * @static
  60. */
  61. Public Static Function version() {
  62. return '0.2.1a';
  63. }
  64. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  65. /**
  66. * Prints a debug backtrace
  67. *
  68. * @access public
  69. * @static
  70. */
  71. Public Static Function backtrace() {
  72. // disabled ?
  73. //
  74. if (!krumo::_debug()) {
  75. return false;
  76. }
  77. // render it
  78. //
  79. return krumo::dump(debug_backtrace());
  80. }
  81. /**
  82. * Prints a list of all currently declared classes.
  83. *
  84. * @access public
  85. * @static
  86. */
  87. Public Static Function classes() {
  88. // disabled ?
  89. //
  90. if (!krumo::_debug()) {
  91. return false;
  92. }
  93. // render it
  94. //
  95. ?>
  96. <div class="krumo-title">
  97. This is a list of all currently declared classes.
  98. </div>
  99. <?php
  100. return krumo::dump(get_declared_classes());
  101. }
  102. /**
  103. * Prints a list of all currently declared interfaces (PHP5 only).
  104. *
  105. * @access public
  106. * @static
  107. */
  108. Public Static Function interfaces() {
  109. // disabled ?
  110. //
  111. if (!krumo::_debug()) {
  112. return false;
  113. }
  114. // render it
  115. //
  116. ?>
  117. <div class="krumo-title">
  118. This is a list of all currently declared interfaces.
  119. </div>
  120. <?php
  121. return krumo::dump(get_declared_interfaces());
  122. }
  123. /**
  124. * Prints a list of all currently included (or required) files.
  125. *
  126. * @access public
  127. * @static
  128. */
  129. Public Static Function includes() {
  130. // disabled ?
  131. //
  132. if (!krumo::_debug()) {
  133. return false;
  134. }
  135. // render it
  136. //
  137. ?>
  138. <div class="krumo-title">
  139. This is a list of all currently included (or required) files.
  140. </div>
  141. <?php
  142. return krumo::dump(get_included_files());
  143. }
  144. /**
  145. * Prints a list of all currently declared functions.
  146. *
  147. * @access public
  148. * @static
  149. */
  150. Public Static Function functions() {
  151. // disabled ?
  152. //
  153. if (!krumo::_debug()) {
  154. return false;
  155. }
  156. // render it
  157. //
  158. ?>
  159. <div class="krumo-title">
  160. This is a list of all currently declared functions.
  161. </div>
  162. <?php
  163. return krumo::dump(get_defined_functions());
  164. }
  165. /**
  166. * Prints a list of all currently declared constants.
  167. *
  168. * @access public
  169. * @static
  170. */
  171. Public Static Function defines() {
  172. // disabled ?
  173. //
  174. if (!krumo::_debug()) {
  175. return false;
  176. }
  177. // render it
  178. //
  179. ?>
  180. <div class="krumo-title">
  181. This is a list of all currently declared constants (defines).
  182. </div>
  183. <?php
  184. return krumo::dump(get_defined_constants());
  185. }
  186. /**
  187. * Prints a list of all currently loaded PHP extensions.
  188. *
  189. * @access public
  190. * @static
  191. */
  192. Public Static Function extensions() {
  193. // disabled ?
  194. //
  195. if (!krumo::_debug()) {
  196. return false;
  197. }
  198. // render it
  199. //
  200. ?>
  201. <div class="krumo-title">
  202. This is a list of all currently loaded PHP extensions.
  203. </div>
  204. <?php
  205. return krumo::dump(get_loaded_extensions());
  206. }
  207. /**
  208. * Prints a list of all HTTP request headers.
  209. *
  210. * @access public
  211. * @static
  212. */
  213. Public Static Function headers() {
  214. // disabled ?
  215. //
  216. if (!krumo::_debug()) {
  217. return false;
  218. }
  219. // render it
  220. //
  221. ?>
  222. <div class="krumo-title">
  223. This is a list of all HTTP request headers.
  224. </div>
  225. <?php
  226. return krumo::dump(getAllHeaders());
  227. }
  228. /**
  229. * Prints a list of the configuration settings read from <i>php.ini</i>
  230. *
  231. * @access public
  232. * @static
  233. */
  234. Public Static Function phpini() {
  235. // disabled ?
  236. //
  237. if (!krumo::_debug()) {
  238. return false;
  239. }
  240. if (!readable(get_cfg_var('cfg_file_path'))) {
  241. return false;
  242. }
  243. // render it
  244. //
  245. ?>
  246. <div class="krumo-title">
  247. This is a list of the configuration settings read from <code><b><?php echo get_cfg_var('cfg_file_path');?></b></code>.
  248. </div>
  249. <?php
  250. return krumo::dump(parse_ini_file(get_cfg_var('cfg_file_path'), true));
  251. }
  252. /**
  253. * Prints a list of all your configuration settings.
  254. *
  255. * @access public
  256. * @static
  257. */
  258. Public Static Function conf() {
  259. // disabled ?
  260. //
  261. if (!krumo::_debug()) {
  262. return false;
  263. }
  264. // render it
  265. //
  266. ?>
  267. <div class="krumo-title">
  268. This is a list of all your configuration settings.
  269. </div>
  270. <?php
  271. return krumo::dump(ini_get_all());
  272. }
  273. /**
  274. * Prints a list of the specified directories under your <i>include_path</i> option.
  275. *
  276. * @access public
  277. * @static
  278. */
  279. Public Static Function path() {
  280. // disabled ?
  281. //
  282. if (!krumo::_debug()) {
  283. return false;
  284. }
  285. // render it
  286. //
  287. ?>
  288. <div class="krumo-title">
  289. This is a list of the specified directories under your <code><b>include_path</b></code> option.
  290. </div>
  291. <?php
  292. return krumo::dump(explode(PATH_SEPARATOR, ini_get('include_path')));
  293. }
  294. /**
  295. * Prints a list of all the values from the <i>$_REQUEST</i> array.
  296. *
  297. * @access public
  298. * @static
  299. */
  300. Public Static Function request() {
  301. // disabled ?
  302. //
  303. if (!krumo::_debug()) {
  304. return false;
  305. }
  306. // render it
  307. //
  308. ?>
  309. <div class="krumo-title">
  310. This is a list of all the values from the <code><b>$_REQUEST</b></code> array.
  311. </div>
  312. <?php
  313. return krumo::dump($_REQUEST);
  314. }
  315. /**
  316. * Prints a list of all the values from the <i>$_GET</i> array.
  317. *
  318. * @access public
  319. * @static
  320. */
  321. Public Static Function get() {
  322. // disabled ?
  323. //
  324. if (!krumo::_debug()) {
  325. return false;
  326. }
  327. // render it
  328. //
  329. ?>
  330. <div class="krumo-title">
  331. This is a list of all the values from the <code><b>$_GET</b></code> array.
  332. </div>
  333. <?php
  334. return krumo::dump($_GET);
  335. }
  336. /**
  337. * Prints a list of all the values from the <i>$_POST</i> array.
  338. *
  339. * @access public
  340. * @static
  341. */
  342. Public Static Function post() {
  343. // disabled ?
  344. //
  345. if (!krumo::_debug()) {
  346. return false;
  347. }
  348. // render it
  349. //
  350. ?>
  351. <div class="krumo-title">
  352. This is a list of all the values from the <code><b>$_POST</b></code> array.
  353. </div>
  354. <?php
  355. return krumo::dump($_POST);
  356. }
  357. /**
  358. * Prints a list of all the values from the <i>$_SERVER</i> array.
  359. *
  360. * @access public
  361. * @static
  362. */
  363. Public Static Function server() {
  364. // disabled ?
  365. //
  366. if (!krumo::_debug()) {
  367. return false;
  368. }
  369. // render it
  370. //
  371. ?>
  372. <div class="krumo-title">
  373. This is a list of all the values from the <code><b>$_SERVER</b></code> array.
  374. </div>
  375. <?php
  376. return krumo::dump($_SERVER);
  377. }
  378. /**
  379. * Prints a list of all the values from the <i>$_COOKIE</i> array.
  380. *
  381. * @access public
  382. * @static
  383. */
  384. Public Static Function cookie() {
  385. // disabled ?
  386. //
  387. if (!krumo::_debug()) {
  388. return false;
  389. }
  390. // render it
  391. //
  392. ?>
  393. <div class="krumo-title">
  394. This is a list of all the values from the <code><b>$_COOKIE</b></code> array.
  395. </div>
  396. <?php
  397. return krumo::dump($_COOKIE);
  398. }
  399. /**
  400. * Prints a list of all the values from the <i>$_ENV</i> array.
  401. *
  402. * @access public
  403. * @static
  404. */
  405. Public Static Function env() {
  406. // disabled ?
  407. //
  408. if (!krumo::_debug()) {
  409. return false;
  410. }
  411. // render it
  412. //
  413. ?>
  414. <div class="krumo-title">
  415. This is a list of all the values from the <code><b>$_ENV</b></code> array.
  416. </div>
  417. <?php
  418. return krumo::dump($_ENV);
  419. }
  420. /**
  421. * Prints a list of all the values from the <i>$_SESSION</i> array.
  422. *
  423. * @access public
  424. * @static
  425. */
  426. Public Static Function session() {
  427. // disabled ?
  428. //
  429. if (!krumo::_debug()) {
  430. return false;
  431. }
  432. // render it
  433. //
  434. ?>
  435. <div class="krumo-title">
  436. This is a list of all the values from the <code><b>$_SESSION</b></code> array.
  437. </div>
  438. <?php
  439. return krumo::dump($_SESSION);
  440. }
  441. /**
  442. * Prints a list of all the values from an INI file.
  443. *
  444. * @param string $ini_file
  445. *
  446. * @access public
  447. * @static
  448. */
  449. Public Static Function ini($ini_file) {
  450. // disabled ?
  451. //
  452. if (!krumo::_debug()) {
  453. return false;
  454. }
  455. // read it
  456. //
  457. if (!$_ = @parse_ini_file($ini_file, 1)) {
  458. return false;
  459. }
  460. // render it
  461. //
  462. ?>
  463. <div class="krumo-title">
  464. 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.
  465. </div>
  466. <?php
  467. return krumo::dump($_);
  468. }
  469. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  470. /**
  471. * Dump information about a variable
  472. *
  473. * @param mixed $data,...
  474. * @access public
  475. * @static
  476. */
  477. Public Static Function dump($data) {
  478. // disabled ?
  479. //
  480. if (!krumo::_debug()) {
  481. return false;
  482. }
  483. // more arguments ?
  484. //
  485. if (func_num_args() > 1) {
  486. $_ = func_get_args();
  487. foreach($_ as $d) {
  488. krumo::dump($d);
  489. }
  490. return;
  491. }
  492. // the css ?
  493. //
  494. krumo::_css();
  495. // find caller
  496. // DEVEL: we added array_reverse() so the proper file+line number is found.
  497. $_ = array_reverse(debug_backtrace());
  498. while($d = array_pop($_)) {
  499. // DEVEL: changed if() condition below
  500. if ((strpos(@$d['file'], 'devel') === FALSE) && (strpos(@$d['file'], 'krumo') === FALSE) && @$d['class'] != 'krumo') {
  501. break;
  502. }
  503. }
  504. // the content
  505. // DEVEL: we add an ltr here.
  506. ?>
  507. <div class="krumo-root" dir="ltr">
  508. <ul class="krumo-node krumo-first">
  509. <?php echo krumo::_dump($data);?>
  510. <li class="krumo-footnote">
  511. <div class="krumo-version" style="white-space:nowrap;">
  512. <h6>Krumo version <?php echo krumo::version();?></h6> | <a
  513. href="http://krumo.sourceforge.net"
  514. target="_blank">http://krumo.sourceforge.net</a>
  515. </div>
  516. <?php if (@$d['file']) { ?>
  517. <span class="krumo-call" style="white-space:nowrap;">
  518. Called from <code><?php echo $d['file']?></code>,
  519. line <code><?php echo $d['line']?></code></span>
  520. <?php } ?>
  521. &nbsp;
  522. </li>
  523. </ul>
  524. </div>
  525. <?php
  526. // flee the hive
  527. //
  528. $_recursion_marker = krumo::_marker();
  529. if ($hive =& krumo::_hive($dummy)) {
  530. foreach($hive as $i=>$bee){
  531. if (is_object($bee)) {
  532. unset($hive[$i]->$_recursion_marker);
  533. } else {
  534. unset($hive[$i][$_recursion_marker]);
  535. }
  536. }
  537. }
  538. // PHP 4.x.x array reference bug...
  539. //
  540. if (is_array($data) && version_compare(PHP_VERSION, "5", "<")) {
  541. unset($GLOBALS[krumo::_marker()]);
  542. }
  543. }
  544. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  545. /**
  546. * Returns values from Krumo's configuration
  547. *
  548. * @param string $group
  549. * @param string $name
  550. * @param mixed $fallback
  551. * @return mixed
  552. *
  553. * @access private
  554. * @static
  555. */
  556. Private Static Function _config($group, $name, $fallback=null) {
  557. static $_config = array();
  558. // not loaded ?
  559. //
  560. if (empty($_config)) {
  561. $_config = (array) @parse_ini_file(
  562. KRUMO_DIR . 'krumo.ini',
  563. true);
  564. }
  565. // exists ?
  566. //
  567. return (isset($_config[$group][$name]))
  568. ? $_config[$group][$name]
  569. : $fallback;
  570. }
  571. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  572. /**
  573. * Print the skin (CSS)
  574. *
  575. * @return boolean
  576. * @access private
  577. * @static
  578. */
  579. Private Static Function _css() {
  580. static $_css = false;
  581. // already set ?
  582. //
  583. if ($_css) {
  584. return true;
  585. }
  586. $css = '';
  587. // DEVEL: changed for Drupal variables system
  588. $skin = variable_get('devel_krumo_skin', 'orange');
  589. // custom selected skin ?
  590. //
  591. $_ = KRUMO_DIR . "skins/{$skin}/skin.css";
  592. if ($fp = @fopen($_, 'r', 1)) {
  593. $css = fread($fp, filesize($_));
  594. fclose($fp);
  595. }
  596. // defautl skin ?
  597. //
  598. if (!$css && ($skin != 'default')) {
  599. $skin = 'default';
  600. $_ = KRUMO_DIR . "skins/default/skin.css";
  601. $css = join('', @file($_));
  602. }
  603. // print ?
  604. //
  605. if ($_css = $css != '') {
  606. // fix the urls
  607. //
  608. // DEVEL: changed for Drupal path system.
  609. $css_url = file_create_url(drupal_get_path('module', 'devel') . "/krumo/skins/{$skin}/");
  610. $css = preg_replace('~%url%~Uis', $css_url, $css);
  611. // the CSS
  612. //
  613. ?>
  614. <!-- Using Krumo Skin: <?php echo preg_replace('~^' . preg_quote(realpath(KRUMO_DIR) . DIRECTORY_SEPARATOR) . '~Uis', '', realpath($_));?> -->
  615. <style type="text/css">
  616. <!--/**/
  617. <?php echo $css?>
  618. /**/-->
  619. </style>
  620. <?php
  621. // the JS
  622. //
  623. ?>
  624. <script type="text/javascript">
  625. <!--//
  626. <?php echo join(file(KRUMO_DIR . "krumo.js"));?>
  627. //-->
  628. </script>
  629. <?php
  630. }
  631. return $_css;
  632. }
  633. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  634. /**
  635. * Enable Krumo
  636. *
  637. * @return boolean
  638. * @access public
  639. * @static
  640. */
  641. Public Static Function enable() {
  642. return true === krumo::_debug(true);
  643. }
  644. /**
  645. * Disable Krumo
  646. *
  647. * @return boolean
  648. * @access public
  649. * @static
  650. */
  651. Public Static Function disable() {
  652. return false === krumo::_debug(false);
  653. }
  654. /**
  655. * Get\Set Krumo state: whether it is enabled or disabled
  656. *
  657. * @param boolean $state
  658. * @return boolean
  659. * @access private
  660. * @static
  661. */
  662. Private Static Function _debug($state=null) {
  663. static $_ = true;
  664. // set
  665. //
  666. if (isset($state)) {
  667. $_ = (boolean) $state;
  668. }
  669. // get
  670. //
  671. return $_;
  672. }
  673. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  674. /**
  675. * Dump information about a variable
  676. *
  677. * @param mixed $data
  678. * @param string $name
  679. * @access private
  680. * @static
  681. */
  682. Private Static Function _dump(&$data, $name='...') {
  683. // object ?
  684. //
  685. if (is_object($data)) {
  686. return krumo::_object($data, $name);
  687. }
  688. // array ?
  689. //
  690. if (is_array($data)) {
  691. // PHP 4.x.x array reference bug...
  692. //
  693. if (version_compare(PHP_VERSION, "5", "<")) {
  694. // prepare the GLOBAL reference list...
  695. //
  696. if (!isset($GLOBALS[krumo::_marker()])) {
  697. $GLOBALS[krumo::_marker()] = array();
  698. }
  699. if (!is_array($GLOBALS[krumo::_marker()])) {
  700. $GLOBALS[krumo::_marker()] = (array) $GLOBALS[krumo::_marker()];
  701. }
  702. // extract ?
  703. //
  704. if (!empty($GLOBALS[krumo::_marker()])) {
  705. $d = array_shift($GLOBALS[krumo::_marker()]);
  706. if (is_array($d)) {
  707. $data = $d;
  708. }
  709. }
  710. }
  711. return krumo::_array($data, $name);
  712. }
  713. // resource ?
  714. //
  715. if (is_resource($data)) {
  716. return krumo::_resource($data, $name);
  717. }
  718. // scalar ?
  719. //
  720. if (is_string($data)) {
  721. return krumo::_string($data, $name);
  722. }
  723. if (is_float($data)) {
  724. return krumo::_float($data, $name);
  725. }
  726. if (is_integer($data)) {
  727. return krumo::_integer($data, $name);
  728. }
  729. if (is_bool($data)) {
  730. return krumo::_boolean($data, $name);
  731. }
  732. // null ?
  733. //
  734. if (is_null($data)) {
  735. return krumo::_null($name);
  736. }
  737. }
  738. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  739. /**
  740. * Render a dump for a NULL value
  741. *
  742. * @param string $name
  743. * @return string
  744. * @access private
  745. * @static
  746. */
  747. Private Static Function _null($name) {
  748. ?>
  749. <li class="krumo-child">
  750. <div class="krumo-element"
  751. onMouseOver="krumo.over(this);"
  752. onMouseOut="krumo.out(this);">
  753. <?php /* DEVEL: added htmlSpecialChars */ ?>
  754. <a class="krumo-name"><?php echo htmlSpecialChars($name);?></a>
  755. (<em class="krumo-type krumo-null">NULL</em>)
  756. </div>
  757. </li>
  758. <?php
  759. }
  760. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  761. /**
  762. * Return the marked used to stain arrays
  763. * and objects in order to detect recursions
  764. *
  765. * @return string
  766. * @access private
  767. * @static
  768. */
  769. Private Static Function _marker() {
  770. static $_recursion_marker;
  771. if (!isset($_recursion_marker)) {
  772. $_recursion_marker = uniqid('krumo');
  773. }
  774. return $_recursion_marker;
  775. }
  776. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  777. /**
  778. * Adds a variable to the hive of arrays and objects which
  779. * are tracked for whether they have recursive entries
  780. *
  781. * @param mixed &$bee either array or object, not a scallar vale
  782. * @return array all the bees
  783. *
  784. * @access private
  785. * @static
  786. */
  787. Private Static Function &_hive(&$bee) {
  788. static $_ = array();
  789. // new bee ?
  790. //
  791. if (!is_null($bee)) {
  792. // stain it
  793. //
  794. $_recursion_marker = krumo::_marker();
  795. (is_object($bee))
  796. ? @($bee->$_recursion_marker++)
  797. : @($bee[$_recursion_marker]++);
  798. $_[0][] =& $bee;
  799. }
  800. // return all bees
  801. //
  802. return $_[0];
  803. }
  804. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  805. /**
  806. * Render a dump for the properties of an array or objeect
  807. *
  808. * @param mixed &$data
  809. * @access private
  810. * @static
  811. */
  812. Private Static Function _vars(&$data) {
  813. $_is_object = is_object($data);
  814. // test for references in order to
  815. // prevent endless recursion loops
  816. //
  817. $_recursion_marker = krumo::_marker();
  818. $_r = ($_is_object)
  819. ? @$data->$_recursion_marker
  820. : @$data[$_recursion_marker] ;
  821. $_r = (integer) $_r;
  822. // recursion detected
  823. //
  824. if ($_r > 0) {
  825. return krumo::_recursion();
  826. }
  827. // stain it
  828. //
  829. krumo::_hive($data);
  830. // render it
  831. //
  832. ?>
  833. <div class="krumo-nest" style="display:none;">
  834. <ul class="krumo-node">
  835. <?php
  836. // keys ?
  837. //
  838. $keys = ($_is_object)
  839. ? array_keys(get_object_vars($data))
  840. : array_keys($data);
  841. // itterate
  842. //
  843. foreach($keys as $k) {
  844. // skip marker
  845. //
  846. if ($k === $_recursion_marker) {
  847. continue;
  848. }
  849. // get real value
  850. //
  851. if ($_is_object) {
  852. $v =& $data->$k;
  853. } else {
  854. $v =& $data[$k];
  855. }
  856. krumo::_dump($v,$k);
  857. } ?>
  858. </ul>
  859. </div>
  860. <?php
  861. }
  862. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  863. /**
  864. * Render a block that detected recursion
  865. *
  866. * @access private
  867. * @static
  868. */
  869. Private Static Function _recursion() {
  870. ?>
  871. <div class="krumo-nest" style="display:none;">
  872. <ul class="krumo-node">
  873. <li class="krumo-child">
  874. <div class="krumo-element"
  875. onMouseOver="krumo.over(this);"
  876. onMouseOut="krumo.out(this);">
  877. <a class="krumo-name"><big>&#8734;</big></a>
  878. (<em class="krumo-type">Recursion</em>)
  879. </div>
  880. </li>
  881. </ul>
  882. </div>
  883. <?php
  884. }
  885. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  886. /**
  887. * Render a dump for an array
  888. *
  889. * @param mixed $data
  890. * @param string $name
  891. * @access private
  892. * @static
  893. */
  894. Private Static Function _array(&$data, $name) {
  895. ?>
  896. <li class="krumo-child">
  897. <div class="krumo-element<?php echo count($data) > 0 ? ' krumo-expand' : '';?>"
  898. <?php if (count($data) > 0) {?> onClick="krumo.toggle(this);"<?php } ?>
  899. onMouseOver="krumo.over(this);"
  900. onMouseOut="krumo.out(this);">
  901. <?php /* DEVEL: added htmlSpecialChars */ ?>
  902. <a class="krumo-name"><?php echo htmlSpecialChars($name);?></a>
  903. (<em class="krumo-type">Array, <strong class="krumo-array-length"><?php echo
  904. (count($data)==1)
  905. ?("1 element")
  906. :(count($data)." elements");
  907. ?></strong></em>)
  908. <?php
  909. // callback ?
  910. //
  911. if (is_callable($data)) {
  912. $_ = array_values($data);
  913. ?>
  914. <span class="krumo-callback"> |
  915. (<em class="krumo-type">Callback</em>)
  916. <strong class="krumo-string"><?php
  917. echo htmlSpecialChars($_[0]);?>::<?php
  918. echo htmlSpecialChars($_[1]);?>();</strong></span>
  919. <?php
  920. }
  921. ?>
  922. </div>
  923. <?php if (count($data)) {
  924. krumo::_vars($data);
  925. } ?>
  926. </li>
  927. <?php
  928. }
  929. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  930. /**
  931. * Render a dump for an object
  932. *
  933. * @param mixed $data
  934. * @param string $name
  935. * @access private
  936. * @static
  937. */
  938. Private Static Function _object(&$data, $name) {
  939. ?>
  940. <li class="krumo-child">
  941. <div class="krumo-element<?php echo count($data) > 0 ? ' krumo-expand' : '';?>"
  942. <?php if (count($data) > 0) {?> onClick="krumo.toggle(this);"<?php } ?>
  943. onMouseOver="krumo.over(this);"
  944. onMouseOut="krumo.out(this);">
  945. <?php /* DEVEL: added htmlSpecialChars */ ?>
  946. <a class="krumo-name"><?php echo htmlSpecialChars($name);?></a>
  947. (<em class="krumo-type">Object</em>)
  948. <strong class="krumo-class"><?php echo get_class($data);?></strong>
  949. </div>
  950. <?php if (count($data)) {
  951. krumo::_vars($data);
  952. } ?>
  953. </li>
  954. <?php
  955. }
  956. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  957. /**
  958. * Render a dump for a resource
  959. *
  960. * @param mixed $data
  961. * @param string $name
  962. * @access private
  963. * @static
  964. */
  965. Private Static Function _resource($data, $name) {
  966. ?>
  967. <li class="krumo-child">
  968. <div class="krumo-element"
  969. onMouseOver="krumo.over(this);"
  970. onMouseOut="krumo.out(this);">
  971. <?php /* DEVEL: added htmlSpecialChars */ ?>
  972. <a class="krumo-name"><?php echo htmlSpecialChars($name);?></a>
  973. (<em class="krumo-type">Resource</em>)
  974. <strong class="krumo-resource"><?php echo get_resource_type($data);?></strong>
  975. </div>
  976. </li>
  977. <?php
  978. }
  979. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  980. /**
  981. * Render a dump for a boolean value
  982. *
  983. * @param mixed $data
  984. * @param string $name
  985. * @access private
  986. * @static
  987. */
  988. Private Static Function _boolean($data, $name) {
  989. ?>
  990. <li class="krumo-child">
  991. <div class="krumo-element"
  992. onMouseOver="krumo.over(this);"
  993. onMouseOut="krumo.out(this);">
  994. <?php /* DEVEL: added htmlSpecialChars */ ?>
  995. <a class="krumo-name"><?php echo htmlSpecialChars($name);?></a>
  996. (<em class="krumo-type">Boolean</em>)
  997. <strong class="krumo-boolean"><?php echo $data?'TRUE':'FALSE'?></strong>
  998. </div>
  999. </li>
  1000. <?php
  1001. }
  1002. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  1003. /**
  1004. * Render a dump for a integer value
  1005. *
  1006. * @param mixed $data
  1007. * @param string $name
  1008. * @access private
  1009. * @static
  1010. */
  1011. Private Static Function _integer($data, $name) {
  1012. ?>
  1013. <li class="krumo-child">
  1014. <div class="krumo-element"
  1015. onMouseOver="krumo.over(this);"
  1016. onMouseOut="krumo.out(this);">
  1017. <?php /* DEVEL: added htmlSpecialChars */ ?>
  1018. <a class="krumo-name"><?php echo htmlSpecialChars($name);?></a>
  1019. (<em class="krumo-type">Integer</em>)
  1020. <strong class="krumo-integer"><?php echo $data;?></strong>
  1021. </div>
  1022. </li>
  1023. <?php
  1024. }
  1025. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  1026. /**
  1027. * Render a dump for a float value
  1028. *
  1029. * @param mixed $data
  1030. * @param string $name
  1031. * @access private
  1032. * @static
  1033. */
  1034. Private Static Function _float($data, $name) {
  1035. ?>
  1036. <li class="krumo-child">
  1037. <div class="krumo-element"
  1038. onMouseOver="krumo.over(this);"
  1039. onMouseOut="krumo.out(this);">
  1040. <?php /* DEVEL: added htmlSpecialChars */ ?>
  1041. <a class="krumo-name"><?php echo htmlSpecialChars($name);?></a>
  1042. (<em class="krumo-type">Float</em>)
  1043. <strong class="krumo-float"><?php echo $data;?></strong>
  1044. </div>
  1045. </li>
  1046. <?php
  1047. }
  1048. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  1049. /**
  1050. * Render a dump for a string value
  1051. *
  1052. * @param mixed $data
  1053. * @param string $name
  1054. * @access private
  1055. * @static
  1056. */
  1057. Private Static Function _string($data, $name) {
  1058. // extra ?
  1059. //
  1060. $_extra = false;
  1061. $_ = $data;
  1062. if (strLen($data) > KRUMO_TRUNCATE_LENGTH) {
  1063. $_ = substr($data, 0, KRUMO_TRUNCATE_LENGTH - 3) . '...';
  1064. $_extra = true;
  1065. }
  1066. ?>
  1067. <li class="krumo-child">
  1068. <div class="krumo-element<?php echo $_extra ? ' krumo-expand' : '';?>"
  1069. <?php if ($_extra) {?> onClick="krumo.toggle(this);"<?php } ?>
  1070. onMouseOver="krumo.over(this);"
  1071. onMouseOut="krumo.out(this);">
  1072. <?php /* DEVEL: added htmlSpecialChars */ ?>
  1073. <a class="krumo-name"><?php echo htmlSpecialChars($name);?></a>
  1074. (<em class="krumo-type">String,
  1075. <strong class="krumo-string-length"><?php
  1076. echo strlen($data) ?> characters</strong> </em>)
  1077. <strong class="krumo-string"><?php echo htmlSpecialChars($_);?></strong>
  1078. <?php
  1079. // callback ?
  1080. //
  1081. if (is_callable($data)) {
  1082. ?>
  1083. <span class="krumo-callback"> |
  1084. (<em class="krumo-type">Callback</em>)
  1085. <strong class="krumo-string"><?php echo htmlSpecialChars($_);?>();</strong></span>
  1086. <?php
  1087. }
  1088. ?>
  1089. </div>
  1090. <?php if ($_extra) { ?>
  1091. <div class="krumo-nest" style="display:none;">
  1092. <ul class="krumo-node">
  1093. <li class="krumo-child">
  1094. <div class="krumo-preview"><?php echo htmlSpecialChars($data);?></div>
  1095. </li>
  1096. </ul>
  1097. </div>
  1098. <?php } ?>
  1099. </li>
  1100. <?php
  1101. }
  1102. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  1103. //--end-of-class--
  1104. }
  1105. //////////////////////////////////////////////////////////////////////////////
  1106. /**
  1107. * Alias of {@link krumo::dump()}
  1108. *
  1109. * @param mixed $data,...
  1110. *
  1111. * @see krumo::dump()
  1112. */
  1113. Function krumo() {
  1114. $_ = func_get_args();
  1115. return call_user_func_array(
  1116. array('krumo', 'dump'), $_
  1117. );
  1118. }
  1119. //////////////////////////////////////////////////////////////////////////////
  1120. ?>