|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Functionality used to help display data to screen in a nicer format than var_dump() |
| 5 | + * |
| 6 | + * ddd() is a quicker way o call pretty_dump(), they both do pretty much the same thing |
| 7 | + */ |
| 8 | + |
| 9 | +if (! function_exists('ddd')) |
| 10 | +{ |
| 11 | + /** |
| 12 | + * alias for pretty_dump |
| 13 | + * |
| 14 | + * @param variable $object |
| 15 | + * @param boolean $die set to false if you don't want function to die |
| 16 | + * @param boolean $full_trace set to true if you want a full trace in the dump |
| 17 | + */ |
| 18 | + function ddd($object, $die = true, $full_trace = false) |
| 19 | + { |
| 20 | + pretty_dump($object, $die, $full_trace, true); |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +if (! function_exists('pretty_dump')) |
| 25 | +{ |
| 26 | + /** |
| 27 | + * dumps variables to screen and optionally die, and a full trace |
| 28 | + * |
| 29 | + * @param variable $object |
| 30 | + * @param boolean $die set to false if you don't want function to die |
| 31 | + * @param boolean $full_trace set to true if you want a full trace in the dump |
| 32 | + * @param boolean $ddd did we get to this function from ddd? |
| 33 | + * @param integer $trace_line set to numeric if we want only a certain line traced back |
| 34 | + */ |
| 35 | + function pretty_dump($object, $die = true, $full_trace = false, $ddd = false, $trace_line = null) |
| 36 | + { |
| 37 | + $fileinfo = 'no_file_info'; |
| 38 | + $backtrace = debug_backtrace(); |
| 39 | + |
| 40 | + //if we want a full trace of whats happend |
| 41 | + if ($full_trace) |
| 42 | + { |
| 43 | + $backtrace_data_i_want = []; |
| 44 | + |
| 45 | + if (! empty($backtrace)) |
| 46 | + { |
| 47 | + foreach ($backtrace as $back) |
| 48 | + { |
| 49 | + $backtrace_data_i_want[] = $back['file'] . ' - Line: ' . $back['line']; |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + if ($trace_line !== null) |
| 54 | + { |
| 55 | + dump($backtrace_data_i_want[$trace_line], $object); |
| 56 | + } |
| 57 | + else |
| 58 | + { |
| 59 | + dump($backtrace_data_i_want, $object); |
| 60 | + } |
| 61 | + |
| 62 | + //otherwise we only want the last trace data |
| 63 | + } |
| 64 | + else |
| 65 | + { |
| 66 | + $depth = $ddd === false ? 0 : 1; |
| 67 | + if (! empty($backtrace[$depth]) && is_array($backtrace[$depth])) |
| 68 | + { |
| 69 | + $fileinfo = $backtrace[$depth]['file'] . ' - Line: ' . $backtrace[$depth]['line']; |
| 70 | + } |
| 71 | + dump($fileinfo, $object); |
| 72 | + } |
| 73 | + |
| 74 | + //should we die? |
| 75 | + if ($die) |
| 76 | + { |
| 77 | + die(); |
| 78 | + } |
| 79 | + } |
| 80 | +} |
0 commit comments