Completed
Branch master (254118)
by Alexander
01:40
created

functions.php ➔ ddt()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 19
Code Lines 15

Duplication

Lines 3
Ratio 15.79 %

Importance

Changes 0
Metric Value
cc 4
eloc 15
nc 6
nop 0
dl 3
loc 19
rs 9.2
c 0
b 0
f 0
1
<?php
2
/**
3
  * Global convenience methods
4
  */
5
6
use alkemann\h2l\internals\debug\Debug;
7
8
// Li3 specific code for loading defaults, disable if not used with Li3
9
10
11
/**
12
 * Dump any amount of paramters in a html styled var_dump
13
 * 
14
 * @param mixed any amount
15
 */
16
function d()
17
{
18
    $debug = Debug::get_instance();
19
    $args = func_get_args();
20
    $trace = debug_backtrace();
21
    $split = true;
22
    if (count($args) == 1) {
23
        $split = false;
24
        $args = $args[0];
25
    }
26
    $debug->dump($args, compact('trace', 'split'));
27
};
28
29
/**
30
 * Dump any amount of parameters in a html styled var_dump with trace
31
 *
32
 * @param mixed any amount
33
 */
34
function dt()
35
{
36
    $debug = Debug::get_instance();
37
    $args = func_get_args();
38
    $trace = debug_backtrace();
39
    $split = true;
40
41
    @ob_end_clean();
42
    $debug_trace = $debug->trace();
43
    foreach ($debug_trace as $t) {
44
        @$traced[] = (empty($t['class'])?$t['file']:$t['class']).'::'.$t['function'].'::'.$t['line'];
45
    }
46
    $args[] = $traced;
47
    $debug->dump($args, compact('trace', 'split'));
48
};
49
50
// Debug dump any amount of variables and then die()
51
function dd()
52
{
53
    $debug = Debug::get_instance();
54
    $args = func_get_args();
55
    $trace = debug_backtrace();
56
    $split = true;
57
    if (count($args) == 1) {
58
        $split = false;
59
        $args = $args[0];
60
    }
61
	$echo = true;
62
    @ob_end_clean();
63
    $debug->dump($args, compact('trace', 'split', 'echo'));
64
	if (!empty($debug->output)) {
65
		dout();
66
	}
67
    die('<div style="margin-top: 25px;font-size: 10px;color: #500;">-Debug die-</div>');
68
}
69
70
function ddt()
71
{
72
    $debug = Debug::get_instance();
73
    $args = func_get_args();
74
    $trace = debug_backtrace();
75
    $split = true;
76
    $echo = true;
77
    @ob_end_clean();
78
    $debug_trace = $debug->trace();
79
    foreach ($debug_trace as $t) {
80
        @$traced[] = (empty($t['class'])?$t['file']:$t['class']).'::'.$t['function'].'::'.$t['line'];
81
    }
82
    $args[] = $traced;
83
    $debug->dump($args, compact('trace', 'split', 'echo'));
84
    if (!empty($debug->output)) {
85
        dout();
86
    }
87
    die('<div style="margin-top: 25px;font-size: 10px;color: #500;">-Debug die-</div>');
88
}
89
90
/**
91
 * Inspect an object for it's properties and methods
92
 *
93
 * @param object $classOrObject
94
 */
95
function dapi($classOrObject)
96
{
97
    $debug = Debug::get_instance();
98
    dd($debug->api($classOrObject));
99
}
100
/**
101
 * Convenient way of adding / setting a Debug setting
102
 * 
103
 * @param string $setting Name/Key of Debug config/setting to set
104
 * @param mixed $value Value
105
 */
106
function ds($setting, $value)
107
{
108
    Debug::$defaults[$setting] = $value;
109
}
110
111
/**
112
 * Conventience method for adding to blacklist
113
 * If an array it will overwrite the category with the supplied array
114
 * 
115
 * @param mixed $value Value add to specified blacklist category or array to set the entire category
116
 * @param string $category Name of category of blacklist that is being modified, 'property' by default
117
 */
118
function dsb($value, $category = 'property')
119
{
120
    if (is_array($value)) {
121
        Debug::$defaults['blacklist'][$category] = $value;
122
        return;
123
    }
124
    Debug::$defaults['blacklist'][$category][] = $value;
125
}
126
127
/**
128
 * Extra short way of adding a blacklisted array key
129
 *
130
 * @param mixed $value Name of array key to black list, or array of
131
 */
132
function dbk($value)
133
{
134
    $category = 'key';
135
    dsb($value, $category);
136
}
137
138
/**
139
 * Extra short way of adding a blacklisted object property
140
 * 
141
 * @param mixed $value Name of object property to blacklist, or array of
142
 */
143
function dbp($value)
144
{
145
    $category = 'property';
146
    dsb($value, $category);
147
}
148
149
/**
150
 * Extra short way of blacklisting classes
151
 *
152
 * @param mixed $value Name of class, of which objects will be blacklisted, or array of
153
 */
154
function dbc($value)
155
{
156
    $category = 'class';
157
    dsb($value, $category);
158
}
159
160
/**
161
 * Convenient wrapper for other \util\Debug methods
162
 * 
163
 * @param string $method Name of method to call on the Debug obect
164
 * @param boolean $echo True will echo, false will return result
165
 */
166
function dw($method)
167
{
168
    $args = func_get_args();
169
    $trace = debug_backtrace();
170
    $split = true;
171
    if (count($args) == 1) {
172
        $split = false;
173
        $args = $args[0];
174
    }
175
    $debug = Debug::get_instance();
176
    $result = $debug->$method();
177
    $debug->dump($result, compact('trace', 'split'));
178
}
179
180
/**
181
 * Output any stored up debugging from using the echo false option
182
 *
183
 * @param int $key array key of the output to put out
184
 */
185
function dout($key = null, $incStyle = true)
186
{
187
    $debug = Debug::get_instance();
188
	if ($key && $incStyle) {
189
		$debug->out(0);
190
	}
191
	$debug->out($key);
192
}
193
194
/**
195
 * Returns array of output without the leading style html tag
196
 *
197
 * Place in media handler for json as part of the container
198
 *
199
 * @param string $key
200
 * @return string
201
 */
202
function daout($key = null)
203
{
204
    $debug = Debug::get_instance();
205
	return $debug->array_out($key);
206
}
207