class.krumo.php 27 KB

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