class.krumo.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317
  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. // skip closures set as properties
  532. if (is_object($bee) && !($bee instanceof Closure)) {
  533. unset($hive[$i]->$_recursion_marker);
  534. // DEVEL: changed 'else' to 'elseif' below
  535. } elseif (is_array($bee)) {
  536. unset($hive[$i][$_recursion_marker]);
  537. }
  538. }
  539. }
  540. // PHP 4.x.x array reference bug...
  541. //
  542. if (is_array($data) && version_compare(PHP_VERSION, "5", "<")) {
  543. unset($GLOBALS[krumo::_marker()]);
  544. }
  545. }
  546. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  547. /**
  548. * Returns values from Krumo's configuration
  549. *
  550. * @param string $group
  551. * @param string $name
  552. * @param mixed $fallback
  553. * @return mixed
  554. *
  555. * @access private
  556. * @static
  557. */
  558. Private Static Function _config($group, $name, $fallback=null) {
  559. static $_config = array();
  560. // not loaded ?
  561. //
  562. if (empty($_config)) {
  563. $_config = (array) @parse_ini_file(
  564. KRUMO_DIR . 'krumo.ini',
  565. true);
  566. }
  567. // exists ?
  568. //
  569. return (isset($_config[$group][$name]))
  570. ? $_config[$group][$name]
  571. : $fallback;
  572. }
  573. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  574. /**
  575. * Print the skin (CSS)
  576. *
  577. * @return boolean
  578. * @access private
  579. * @static
  580. */
  581. Private Static Function _css() {
  582. static $_css = false;
  583. // already set ?
  584. //
  585. if ($_css) {
  586. return true;
  587. }
  588. $css = '';
  589. // DEVEL: changed for Drupal variables system
  590. $skin = variable_get('devel_krumo_skin', 'orange');
  591. // custom selected skin ?
  592. //
  593. $_ = KRUMO_DIR . "skins/{$skin}/skin.css";
  594. if ($fp = @fopen($_, 'r', 1)) {
  595. $css = fread($fp, filesize($_));
  596. fclose($fp);
  597. }
  598. // defautl skin ?
  599. //
  600. if (!$css && ($skin != 'default')) {
  601. $skin = 'default';
  602. $_ = KRUMO_DIR . "skins/default/skin.css";
  603. $css = join('', @file($_));
  604. }
  605. // print ?
  606. //
  607. if ($_css = $css != '') {
  608. // fix the urls
  609. //
  610. // DEVEL: changed for Drupal path system.
  611. $css_url = file_create_url(drupal_get_path('module', 'devel') . "/krumo/skins/{$skin}/");
  612. $css = preg_replace('~%url%~Uis', $css_url, $css);
  613. // the CSS
  614. //
  615. ?>
  616. <!-- Using Krumo Skin: <?php echo preg_replace('~^' . preg_quote(realpath(KRUMO_DIR) . DIRECTORY_SEPARATOR) . '~Uis', '', realpath($_));?> -->
  617. <style type="text/css">
  618. <!--/**/
  619. <?php echo $css?>
  620. /**/-->
  621. </style>
  622. <?php
  623. // the JS
  624. //
  625. ?>
  626. <script type="text/javascript">
  627. <!--//
  628. <?php echo join(file(KRUMO_DIR . "krumo.js"));?>
  629. //-->
  630. </script>
  631. <?php
  632. }
  633. return $_css;
  634. }
  635. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  636. /**
  637. * Enable Krumo
  638. *
  639. * @return boolean
  640. * @access public
  641. * @static
  642. */
  643. Public Static Function enable() {
  644. return true === krumo::_debug(true);
  645. }
  646. /**
  647. * Disable Krumo
  648. *
  649. * @return boolean
  650. * @access public
  651. * @static
  652. */
  653. Public Static Function disable() {
  654. return false === krumo::_debug(false);
  655. }
  656. /**
  657. * Get\Set Krumo state: whether it is enabled or disabled
  658. *
  659. * @param boolean $state
  660. * @return boolean
  661. * @access private
  662. * @static
  663. */
  664. Private Static Function _debug($state=null) {
  665. static $_ = true;
  666. // set
  667. //
  668. if (isset($state)) {
  669. $_ = (boolean) $state;
  670. }
  671. // get
  672. //
  673. return $_;
  674. }
  675. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  676. /**
  677. * Dump information about a variable
  678. *
  679. * @param mixed $data
  680. * @param string $name
  681. * @access private
  682. * @static
  683. */
  684. Private Static Function _dump(&$data, $name='...') {
  685. // object ?
  686. //
  687. if (is_object($data)) {
  688. return krumo::_object($data, $name);
  689. }
  690. // array ?
  691. //
  692. if (is_array($data)) {
  693. // PHP 4.x.x array reference bug...
  694. //
  695. if (version_compare(PHP_VERSION, "5", "<")) {
  696. // prepare the GLOBAL reference list...
  697. //
  698. if (!isset($GLOBALS[krumo::_marker()])) {
  699. $GLOBALS[krumo::_marker()] = array();
  700. }
  701. if (!is_array($GLOBALS[krumo::_marker()])) {
  702. $GLOBALS[krumo::_marker()] = (array) $GLOBALS[krumo::_marker()];
  703. }
  704. // extract ?
  705. //
  706. if (!empty($GLOBALS[krumo::_marker()])) {
  707. $d = array_shift($GLOBALS[krumo::_marker()]);
  708. if (is_array($d)) {
  709. $data = $d;
  710. }
  711. }
  712. }
  713. return krumo::_array($data, $name);
  714. }
  715. // resource ?
  716. //
  717. if (is_resource($data)) {
  718. return krumo::_resource($data, $name);
  719. }
  720. // scalar ?
  721. //
  722. if (is_string($data)) {
  723. return krumo::_string($data, $name);
  724. }
  725. if (is_float($data)) {
  726. return krumo::_float($data, $name);
  727. }
  728. if (is_integer($data)) {
  729. return krumo::_integer($data, $name);
  730. }
  731. if (is_bool($data)) {
  732. return krumo::_boolean($data, $name);
  733. }
  734. // null ?
  735. //
  736. if (is_null($data)) {
  737. return krumo::_null($name);
  738. }
  739. }
  740. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  741. /**
  742. * Render a dump for a NULL value
  743. *
  744. * @param string $name
  745. * @return string
  746. * @access private
  747. * @static
  748. */
  749. Private Static Function _null($name) {
  750. ?>
  751. <li class="krumo-child">
  752. <div class="krumo-element"
  753. onMouseOver="krumo.over(this);"
  754. onMouseOut="krumo.out(this);">
  755. <?php /* DEVEL: added htmlSpecialChars */ ?>
  756. <a class="krumo-name"><?php echo htmlSpecialChars($name);?></a>
  757. (<em class="krumo-type krumo-null">NULL</em>)
  758. </div>
  759. </li>
  760. <?php
  761. }
  762. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  763. /**
  764. * Return the marked used to stain arrays
  765. * and objects in order to detect recursions
  766. *
  767. * @return string
  768. * @access private
  769. * @static
  770. */
  771. Private Static Function _marker() {
  772. static $_recursion_marker;
  773. if (!isset($_recursion_marker)) {
  774. $_recursion_marker = uniqid('krumo');
  775. }
  776. return $_recursion_marker;
  777. }
  778. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  779. /**
  780. * Adds a variable to the hive of arrays and objects which
  781. * are tracked for whether they have recursive entries
  782. *
  783. * @param mixed &$bee either array or object, not a scallar vale
  784. * @return array all the bees
  785. *
  786. * @access private
  787. * @static
  788. */
  789. Private Static Function &_hive(&$bee) {
  790. static $_ = array();
  791. // new bee ?
  792. //
  793. if (!is_null($bee)) {
  794. // stain it
  795. //
  796. $_recursion_marker = krumo::_marker();
  797. (is_object($bee))
  798. ? @($bee->$_recursion_marker++)
  799. : @($bee[$_recursion_marker]++);
  800. $_[0][] =& $bee;
  801. }
  802. // return all bees
  803. //
  804. return $_[0];
  805. }
  806. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  807. /**
  808. * Render a dump for the properties of an array or objeect
  809. *
  810. * @param mixed &$data
  811. * @access private
  812. * @static
  813. */
  814. Private Static Function _vars(&$data) {
  815. $_is_object = is_object($data);
  816. // test for references in order to
  817. // prevent endless recursion loops
  818. //
  819. $_recursion_marker = krumo::_marker();
  820. $_r = ($_is_object)
  821. ? @$data->$_recursion_marker
  822. : @$data[$_recursion_marker] ;
  823. $_r = (integer) $_r;
  824. // recursion detected
  825. //
  826. if ($_r > 0) {
  827. return krumo::_recursion();
  828. }
  829. // stain it
  830. //
  831. krumo::_hive($data);
  832. // render it
  833. //
  834. ?>
  835. <div class="krumo-nest" style="display:none;">
  836. <ul class="krumo-node">
  837. <?php
  838. // keys ?
  839. //
  840. $keys = ($_is_object)
  841. ? array_keys(get_object_vars($data))
  842. : array_keys($data);
  843. // itterate
  844. //
  845. foreach($keys as $k) {
  846. // skip marker
  847. //
  848. if ($k === $_recursion_marker) {
  849. continue;
  850. }
  851. // get real value
  852. //
  853. if ($_is_object) {
  854. $v =& $data->$k;
  855. } else {
  856. $v =& $data[$k];
  857. }
  858. krumo::_dump($v,$k);
  859. } ?>
  860. </ul>
  861. </div>
  862. <?php
  863. }
  864. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  865. /**
  866. * Render a block that detected recursion
  867. *
  868. * @access private
  869. * @static
  870. */
  871. Private Static Function _recursion() {
  872. ?>
  873. <div class="krumo-nest" style="display:none;">
  874. <ul class="krumo-node">
  875. <li class="krumo-child">
  876. <div class="krumo-element"
  877. onMouseOver="krumo.over(this);"
  878. onMouseOut="krumo.out(this);">
  879. <a class="krumo-name"><big>&#8734;</big></a>
  880. (<em class="krumo-type">Recursion</em>)
  881. </div>
  882. </li>
  883. </ul>
  884. </div>
  885. <?php
  886. }
  887. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  888. /**
  889. * Render a dump for an array
  890. *
  891. * @param mixed $data
  892. * @param string $name
  893. * @access private
  894. * @static
  895. */
  896. Private Static Function _array(&$data, $name) {
  897. ?>
  898. <li class="krumo-child">
  899. <div class="krumo-element<?php echo count($data) > 0 ? ' krumo-expand' : '';?>"
  900. <?php if (count($data) > 0) {?> onClick="krumo.toggle(this);"<?php } ?>
  901. onMouseOver="krumo.over(this);"
  902. onMouseOut="krumo.out(this);">
  903. <?php /* DEVEL: added htmlSpecialChars */ ?>
  904. <a class="krumo-name"><?php echo htmlSpecialChars($name);?></a>
  905. (<em class="krumo-type">Array, <strong class="krumo-array-length"><?php echo
  906. (count($data)==1)
  907. ?("1 element")
  908. :(count($data)." elements");
  909. ?></strong></em>)
  910. <?php
  911. // callback ?
  912. //
  913. if (is_callable($data)) {
  914. $_ = array_values($data);
  915. ?>
  916. <span class="krumo-callback"> |
  917. (<em class="krumo-type">Callback</em>)
  918. <strong class="krumo-string"><?php
  919. echo htmlSpecialChars($_[0]);?>::<?php
  920. echo htmlSpecialChars($_[1]);?>();</strong></span>
  921. <?php
  922. }
  923. ?>
  924. </div>
  925. <?php if (count($data)) {
  926. krumo::_vars($data);
  927. } ?>
  928. </li>
  929. <?php
  930. }
  931. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  932. /**
  933. * Render a dump for an object
  934. *
  935. * @param mixed $data
  936. * @param string $name
  937. * @access private
  938. * @static
  939. */
  940. Private Static Function _object(&$data, $name) {
  941. ?>
  942. <li class="krumo-child">
  943. <div class="krumo-element<?php echo count($data) > 0 ? ' krumo-expand' : '';?>"
  944. <?php if (count($data) > 0) {?> onClick="krumo.toggle(this);"<?php } ?>
  945. onMouseOver="krumo.over(this);"
  946. onMouseOut="krumo.out(this);">
  947. <?php /* DEVEL: added htmlSpecialChars */ ?>
  948. <a class="krumo-name"><?php echo htmlSpecialChars($name);?></a>
  949. (<em class="krumo-type">Object</em>)
  950. <strong class="krumo-class"><?php echo get_class($data);?></strong>
  951. </div>
  952. <?php if (count($data)) {
  953. krumo::_vars($data);
  954. } ?>
  955. </li>
  956. <?php
  957. }
  958. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  959. /**
  960. * Render a dump for a resource
  961. *
  962. * @param mixed $data
  963. * @param string $name
  964. * @access private
  965. * @static
  966. */
  967. Private Static Function _resource($data, $name) {
  968. ?>
  969. <li class="krumo-child">
  970. <div class="krumo-element"
  971. onMouseOver="krumo.over(this);"
  972. onMouseOut="krumo.out(this);">
  973. <?php /* DEVEL: added htmlSpecialChars */ ?>
  974. <a class="krumo-name"><?php echo htmlSpecialChars($name);?></a>
  975. (<em class="krumo-type">Resource</em>)
  976. <strong class="krumo-resource"><?php echo get_resource_type($data);?></strong>
  977. </div>
  978. </li>
  979. <?php
  980. }
  981. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  982. /**
  983. * Render a dump for a boolean value
  984. *
  985. * @param mixed $data
  986. * @param string $name
  987. * @access private
  988. * @static
  989. */
  990. Private Static Function _boolean($data, $name) {
  991. ?>
  992. <li class="krumo-child">
  993. <div class="krumo-element"
  994. onMouseOver="krumo.over(this);"
  995. onMouseOut="krumo.out(this);">
  996. <?php /* DEVEL: added htmlSpecialChars */ ?>
  997. <a class="krumo-name"><?php echo htmlSpecialChars($name);?></a>
  998. (<em class="krumo-type">Boolean</em>)
  999. <strong class="krumo-boolean"><?php echo $data?'TRUE':'FALSE'?></strong>
  1000. </div>
  1001. </li>
  1002. <?php
  1003. }
  1004. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  1005. /**
  1006. * Render a dump for a integer value
  1007. *
  1008. * @param mixed $data
  1009. * @param string $name
  1010. * @access private
  1011. * @static
  1012. */
  1013. Private Static Function _integer($data, $name) {
  1014. ?>
  1015. <li class="krumo-child">
  1016. <div class="krumo-element"
  1017. onMouseOver="krumo.over(this);"
  1018. onMouseOut="krumo.out(this);">
  1019. <?php /* DEVEL: added htmlSpecialChars */ ?>
  1020. <a class="krumo-name"><?php echo htmlSpecialChars($name);?></a>
  1021. (<em class="krumo-type">Integer</em>)
  1022. <strong class="krumo-integer"><?php echo $data;?></strong>
  1023. </div>
  1024. </li>
  1025. <?php
  1026. }
  1027. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  1028. /**
  1029. * Render a dump for a float value
  1030. *
  1031. * @param mixed $data
  1032. * @param string $name
  1033. * @access private
  1034. * @static
  1035. */
  1036. Private Static Function _float($data, $name) {
  1037. ?>
  1038. <li class="krumo-child">
  1039. <div class="krumo-element"
  1040. onMouseOver="krumo.over(this);"
  1041. onMouseOut="krumo.out(this);">
  1042. <?php /* DEVEL: added htmlSpecialChars */ ?>
  1043. <a class="krumo-name"><?php echo htmlSpecialChars($name);?></a>
  1044. (<em class="krumo-type">Float</em>)
  1045. <strong class="krumo-float"><?php echo $data;?></strong>
  1046. </div>
  1047. </li>
  1048. <?php
  1049. }
  1050. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  1051. /**
  1052. * Render a dump for a string value
  1053. *
  1054. * @param mixed $data
  1055. * @param string $name
  1056. * @access private
  1057. * @static
  1058. */
  1059. Private Static Function _string($data, $name) {
  1060. // extra ?
  1061. //
  1062. $_extra = false;
  1063. $_ = $data;
  1064. if (strLen($data) > KRUMO_TRUNCATE_LENGTH) {
  1065. $_ = substr($data, 0, KRUMO_TRUNCATE_LENGTH - 3) . '...';
  1066. $_extra = true;
  1067. }
  1068. ?>
  1069. <li class="krumo-child">
  1070. <div class="krumo-element<?php echo $_extra ? ' krumo-expand' : '';?>"
  1071. <?php if ($_extra) {?> onClick="krumo.toggle(this);"<?php } ?>
  1072. onMouseOver="krumo.over(this);"
  1073. onMouseOut="krumo.out(this);">
  1074. <?php /* DEVEL: added htmlSpecialChars */ ?>
  1075. <a class="krumo-name"><?php echo htmlSpecialChars($name);?></a>
  1076. (<em class="krumo-type">String,
  1077. <strong class="krumo-string-length"><?php
  1078. echo strlen($data) ?> characters</strong> </em>)
  1079. <strong class="krumo-string"><?php echo htmlSpecialChars($_);?></strong>
  1080. <?php
  1081. // callback ?
  1082. //
  1083. if (is_callable($data)) {
  1084. ?>
  1085. <span class="krumo-callback"> |
  1086. (<em class="krumo-type">Callback</em>)
  1087. <strong class="krumo-string"><?php echo htmlSpecialChars($_);?>();</strong></span>
  1088. <?php
  1089. }
  1090. ?>
  1091. </div>
  1092. <?php if ($_extra) { ?>
  1093. <div class="krumo-nest" style="display:none;">
  1094. <ul class="krumo-node">
  1095. <li class="krumo-child">
  1096. <div class="krumo-preview"><?php echo htmlSpecialChars($data);?></div>
  1097. </li>
  1098. </ul>
  1099. </div>
  1100. <?php } ?>
  1101. </li>
  1102. <?php
  1103. }
  1104. // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  1105. //--end-of-class--
  1106. }
  1107. //////////////////////////////////////////////////////////////////////////////
  1108. /**
  1109. * Alias of {@link krumo::dump()}
  1110. *
  1111. * @param mixed $data,...
  1112. *
  1113. * @see krumo::dump()
  1114. */
  1115. Function krumo() {
  1116. $_ = func_get_args();
  1117. return call_user_func_array(
  1118. array('krumo', 'dump'), $_
  1119. );
  1120. }
  1121. //////////////////////////////////////////////////////////////////////////////
  1122. ?>