Skip to content

Commit efcd216

Browse files
author
Mohammed Karim
committed
Added symfony/var-dumper to aid with debugging.
Added app/Helpers/enhanced_dump_helper.php to aid with debugging.
1 parent b5c5a94 commit efcd216

3 files changed

Lines changed: 88 additions & 1 deletion

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"ext-json": "*",
1212
"kint-php/kint": "^2.1",
1313
"psr/log": "^1.1",
14-
"zendframework/zend-escaper": "^2.5"
14+
"zendframework/zend-escaper": "^2.5",
15+
"symfony/var-dumper": "^4.3"
1516
},
1617
"require-dev": {
1718
"codeigniter4/codeigniter4-standard": "^1.0",

public/index.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
// Location of the framework bootstrap file.
3636
$app = require rtrim($paths->systemDirectory, '/ ') . '/bootstrap.php';
3737

38+
// allow ddd() to be used throughout application if not production
39+
if (ENVIRONMENT !== 'production')
40+
{
41+
helper('enhanced_dump');
42+
}
43+
3844
/*
3945
*---------------------------------------------------------------
4046
* LAUNCH THE APPLICATION

0 commit comments

Comments
 (0)