1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kint; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class KintBootup |
7
|
|
|
* |
8
|
|
|
* @package kint |
9
|
|
|
*/ |
10
|
|
|
class KintBootup |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* init |
14
|
|
|
*/ |
15
|
|
|
public static function init() |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
if (defined('KINT_DIR')) { |
18
|
|
|
return; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
define('KINT_DIR', __DIR__ . '/'); |
22
|
|
|
|
23
|
|
|
require KINT_DIR . 'config.default.php'; |
24
|
|
|
|
25
|
|
|
# init settings |
26
|
|
|
if (!empty($GLOBALS['_kint_settings'])) { |
27
|
|
|
Kint::enabled($GLOBALS['_kint_settings']['enabled']); |
28
|
|
|
|
29
|
|
|
foreach ($GLOBALS['_kint_settings'] as $key => $val) { |
30
|
|
|
/** @noinspection PhpVariableVariableInspection */ |
31
|
|
|
property_exists('Kint', $key) and Kint::$$key = $val; |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
unset($GLOBALS['_kint_settings'], $key, $val); |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public static function initFunctions() |
39
|
|
|
{ |
40
|
|
|
/** |
41
|
|
|
* quick-debug: print the variable $var [exit] [echo || return] |
42
|
|
|
* |
43
|
|
|
* @param mixed $var |
44
|
|
|
* @param boolean $exit exit after debug-output? (only via "echo") |
45
|
|
|
* @param boolean $echo true => use "echo", otherwise use "return" |
46
|
|
|
* @param boolean $plaintext use a simple "print_r()" instead of kind? |
47
|
|
|
* |
48
|
|
|
* @return string |
49
|
|
|
*/ |
50
|
|
|
function dump($var, $exit = true, $echo = true, $plaintext = false) |
51
|
|
|
{ |
52
|
|
|
Kint::enabled(true); |
53
|
|
|
$stash = Kint::settings(); |
54
|
|
|
Kint::$cliDetection = true; |
55
|
|
|
Kint::$delayedMode = true; |
56
|
|
|
Kint::$expandedByDefault = true; |
57
|
|
|
|
58
|
|
|
if ($plaintext === true) { |
59
|
|
|
Kint::enabled(Kint::MODE_WHITESPACE); |
60
|
|
|
$output = Kint::dump($var); |
61
|
|
|
} else { |
62
|
|
|
$output = Kint::dump($var); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
Kint::settings($stash); |
66
|
|
|
Kint::enabled(false); |
67
|
|
|
|
68
|
|
|
if ($echo === true) { |
69
|
|
|
echo $output; |
70
|
|
|
|
71
|
|
|
if ($exit) { |
72
|
|
|
exit(); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return ''; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $output; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Alias of Kint::dump() |
83
|
|
|
* |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
|
|
function d() |
|
|
|
|
87
|
|
|
{ |
88
|
|
|
return call_user_func_array(array('kint\Kint', 'dump'), func_get_args()); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Alias of Kint::dump() |
94
|
|
|
* [!!!] IMPORTANT: execution will halt after call to this function |
95
|
|
|
* |
96
|
|
|
* @return string |
97
|
|
|
* @deprecated |
98
|
|
|
*/ |
99
|
|
|
function dd() |
|
|
|
|
100
|
|
|
{ |
101
|
|
|
if (!Kint::enabled()) { |
102
|
|
|
return ''; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
echo "<pre>Kint: dd() is being deprecated, please use ddd() instead</pre>\n"; |
106
|
|
|
call_user_func_array(array('kint\Kint', 'dump'), func_get_args()); |
107
|
|
|
exit(); |
|
|
|
|
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Alias of Kint::dump() |
112
|
|
|
* [!!!] IMPORTANT: execution will halt after call to this function |
113
|
|
|
* |
114
|
|
|
* @return string |
115
|
|
|
*/ |
116
|
|
|
function ddd() |
|
|
|
|
117
|
|
|
{ |
118
|
|
|
if (!Kint::enabled()) { |
119
|
|
|
return ''; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
call_user_func_array(array('kint\Kint', 'dump'), func_get_args()); |
123
|
|
|
exit(); |
|
|
|
|
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Alias of Kint::dump(), however the output is delayed until the end of the script |
128
|
|
|
* |
129
|
|
|
* @see d(); |
130
|
|
|
* |
131
|
|
|
* @return string |
132
|
|
|
*/ |
133
|
|
|
function de() |
|
|
|
|
134
|
|
|
{ |
135
|
|
|
$stash = Kint::settings(); |
136
|
|
|
Kint::$delayedMode = true; |
137
|
|
|
$out = call_user_func_array(array('kint\Kint', 'dump'), func_get_args()); |
138
|
|
|
Kint::settings($stash); |
139
|
|
|
|
140
|
|
|
return $out; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Alias of Kint::dump(), however the output is in plain html-escaped text and some minor visibility enhancements |
145
|
|
|
* added. If run in CLI mode, output is pure whitespace. |
146
|
|
|
* |
147
|
|
|
* To force rendering mode without auto-detecting anything: |
148
|
|
|
* |
149
|
|
|
* Kint::enabled( Kint::MODE_PLAIN ); |
150
|
|
|
* Kint::dump( $variable ); |
151
|
|
|
* |
152
|
|
|
* [!!!] IMPORTANT: execution will halt after call to this function |
153
|
|
|
* |
154
|
|
|
* @return string |
155
|
|
|
*/ |
156
|
|
|
function s() |
|
|
|
|
157
|
|
|
{ |
158
|
|
|
if (!Kint::enabled()) { |
159
|
|
|
return ''; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
$stash = Kint::settings(); |
163
|
|
|
|
164
|
|
|
if (Kint::enabled() !== Kint::MODE_WHITESPACE) { |
165
|
|
|
Kint::enabled(Kint::MODE_PLAIN); |
166
|
|
|
if (PHP_SAPI === 'cli' && Kint::$cliDetection === true) { |
167
|
|
|
Kint::enabled(Kint::MODE_CLI); |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
$out = call_user_func_array(array('kint\Kint', 'dump'), func_get_args()); |
172
|
|
|
|
173
|
|
|
Kint::settings($stash); |
174
|
|
|
|
175
|
|
|
return $out; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @see s() |
180
|
|
|
* |
181
|
|
|
* [!!!] IMPORTANT: execution will halt after call to this function |
182
|
|
|
* |
183
|
|
|
* @return string |
184
|
|
|
*/ |
185
|
|
|
function sd() |
|
|
|
|
186
|
|
|
{ |
187
|
|
|
if (!Kint::enabled()) { |
188
|
|
|
return ''; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
if (Kint::enabled() !== Kint::MODE_WHITESPACE) { |
192
|
|
|
Kint::enabled(Kint::MODE_PLAIN); |
193
|
|
|
if (PHP_SAPI === 'cli' && Kint::$cliDetection === true) { |
194
|
|
|
Kint::enabled(Kint::MODE_CLI); |
195
|
|
|
} |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
call_user_func_array(array('kint\Kint', 'dump'), func_get_args()); |
199
|
|
|
exit(); |
|
|
|
|
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @see s() |
204
|
|
|
* @see de() |
205
|
|
|
* |
206
|
|
|
* @return string |
207
|
|
|
*/ |
208
|
|
|
function se() |
|
|
|
|
209
|
|
|
{ |
210
|
|
|
if (!Kint::enabled()) { |
211
|
|
|
return ''; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
$stash = Kint::settings(); |
215
|
|
|
|
216
|
|
|
Kint::$delayedMode = true; |
217
|
|
|
|
218
|
|
|
if (Kint::enabled() !== Kint::MODE_WHITESPACE) { |
219
|
|
|
Kint::enabled(Kint::MODE_PLAIN); |
220
|
|
|
if (PHP_SAPI === 'cli' && Kint::$cliDetection === true) { |
221
|
|
|
Kint::enabled(Kint::MODE_CLI); |
222
|
|
|
} |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
$out = call_user_func_array(array('kint\Kint', 'dump'), func_get_args()); |
226
|
|
|
|
227
|
|
|
Kint::settings($stash); |
228
|
|
|
|
229
|
|
|
return $out; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* Alias of Kint::dump(), however the output is dumped to the javascript console and |
234
|
|
|
* added to the global array `kintDump`. If run in CLI mode, output is pure whitespace. |
235
|
|
|
* |
236
|
|
|
* To force rendering mode without autodetecting anything: |
237
|
|
|
* |
238
|
|
|
* Kint::enabled( Kint::MODE_JS ); |
239
|
|
|
* Kint::dump( $variable ); |
240
|
|
|
* |
241
|
|
|
* @return string |
242
|
|
|
*/ |
243
|
|
|
function j() |
|
|
|
|
244
|
|
|
{ |
245
|
|
|
if (!Kint::enabled()) { |
246
|
|
|
return ''; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
$stash = Kint::settings(); |
250
|
|
|
|
251
|
|
|
Kint::enabled( |
252
|
|
|
PHP_SAPI === 'cli' && Kint::$cliDetection === true ? Kint::MODE_CLI : Kint::MODE_JS |
253
|
|
|
); |
254
|
|
|
|
255
|
|
|
$out = call_user_func_array(array('kint\Kint', 'dump'), func_get_args()); |
256
|
|
|
|
257
|
|
|
Kint::settings($stash); |
258
|
|
|
|
259
|
|
|
return $out; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* @see j() |
264
|
|
|
* |
265
|
|
|
* [!!!] IMPORTANT: execution will halt after call to this function |
266
|
|
|
* |
267
|
|
|
* @return string |
268
|
|
|
*/ |
269
|
|
|
function jd() |
|
|
|
|
270
|
|
|
{ |
271
|
|
|
if (!Kint::enabled()) { |
272
|
|
|
return ''; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
Kint::enabled( |
276
|
|
|
PHP_SAPI === 'cli' && Kint::$cliDetection === true ? Kint::MODE_CLI : Kint::MODE_JS |
277
|
|
|
); |
278
|
|
|
|
279
|
|
|
call_user_func_array(array('kint\Kint', 'dump'), func_get_args()); |
280
|
|
|
|
281
|
|
|
exit(); |
|
|
|
|
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* @see j() |
286
|
|
|
* @see de() |
287
|
|
|
* |
288
|
|
|
* @return string |
289
|
|
|
*/ |
290
|
|
|
function je() |
|
|
|
|
291
|
|
|
{ |
292
|
|
|
if (!Kint::enabled()) { |
293
|
|
|
return ''; |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
$stash = Kint::settings(); |
297
|
|
|
|
298
|
|
|
Kint::$delayedMode = true; |
299
|
|
|
|
300
|
|
|
Kint::enabled( |
301
|
|
|
PHP_SAPI === 'cli' && Kint::$cliDetection === true ? Kint::MODE_CLI : Kint::MODE_JS |
302
|
|
|
); |
303
|
|
|
|
304
|
|
|
$out = call_user_func_array(array('kint\Kint', 'dump'), func_get_args()); |
305
|
|
|
|
306
|
|
|
Kint::settings($stash); |
307
|
|
|
|
308
|
|
|
return $out; |
309
|
|
|
} |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
} |
313
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: