class.krumo.php 27 KB

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