6
6
{
7
7
use Slam \Debug \R as DebugR ;
8
8
9
- function r ($ var , bool $ exit = true , int $ level = 0 , bool $ fullstack = false ): void
9
+ function r ($ var , bool $ exit = true , int $ level = 0 , bool $ fullstack = false , string $ stripFromFullstack = null ): void
10
10
{
11
11
DebugR::$ db = \debug_backtrace ();
12
- DebugR::debug ($ var , $ exit , $ level , $ fullstack );
12
+ DebugR::debug ($ var , $ exit , $ level , $ fullstack, $ stripFromFullstack );
13
13
}
14
14
15
- function rq (string $ query , array $ params , bool $ exit = true , int $ level = 0 , bool $ fullstack = false ): void
15
+ function rq (string $ query , array $ params , bool $ exit = true , int $ level = 0 , bool $ fullstack = false , string $ stripFromFullstack = null ): void
16
16
{
17
17
\uksort ($ params , function (string $ key1 , string $ key2 ) {
18
18
return \strlen ($ key2 ) <=> \strlen ($ key1 );
@@ -27,50 +27,56 @@ function rq(string $query, array $params, bool $exit = true, int $level = 0, boo
27
27
}
28
28
29
29
DebugR::$ db = \debug_backtrace ();
30
- DebugR::debug ($ query , $ exit , $ level , $ fullstack );
30
+ DebugR::debug ($ query , $ exit , $ level , $ fullstack, $ stripFromFullstack );
31
31
}
32
32
}
33
33
34
34
namespace Slam \Debug
35
35
{
36
36
final class R
37
37
{
38
+ /**
39
+ * @var array
40
+ */
38
41
public static $ db = [];
39
42
40
43
private function __construct ()
41
44
{
42
45
}
43
46
44
- public static function debug ($ var , bool $ exit = true , int $ level = 0 , bool $ fullstack = false ): void
47
+ public static function debug ($ var , bool $ exit = true , int $ level = 0 , bool $ fullstack = false , string $ stripFromFullstack = null ): void
45
48
{
46
49
if (null === $ var || \is_scalar ($ var )) {
47
50
\ob_start ();
48
51
\var_dump ($ var );
49
- $ output = \trim (\ob_get_clean ());
52
+ $ output = \trim (( string ) \ob_get_clean ());
50
53
} elseif ($ level > 0 ) {
51
54
$ output = \print_r (Doctrine \Debug::export ($ var , $ level ), true );
52
55
} else {
53
56
$ output = \print_r ($ var , true );
54
57
}
55
58
56
59
if (\PHP_SAPI === 'cli ' ) {
57
- \fwrite (\STDERR , \PHP_EOL . self ::formatDb ($ fullstack ) . $ output . \PHP_EOL );
60
+ \fwrite (\STDERR , \PHP_EOL . self ::formatDb ($ fullstack, $ stripFromFullstack ) . $ output . \PHP_EOL );
58
61
} else {
59
- echo '<pre><strong> ' . self ::formatDb ($ fullstack ) . '</strong><br /> ' . \htmlspecialchars ($ output ) . '</pre> ' ;
62
+ echo '<pre><strong> ' . self ::formatDb ($ fullstack, $ stripFromFullstack ) . '</strong><br /> ' . \htmlspecialchars ($ output ) . '</pre> ' ;
60
63
}
61
64
62
65
if ($ exit ) {
63
66
exit (253 );
64
67
}
65
68
}
66
69
67
- private static function formatDb (bool $ fullstack ): string
70
+ private static function formatDb (bool $ fullstack, string $ stripFromFullstack = null ): string
68
71
{
69
72
$ output = '' ;
70
73
71
74
foreach (self ::$ db as $ point ) {
72
75
if (isset ($ point ['file ' ])) {
73
- $ output .= $ point ['file ' ] . '( ' . $ point ['line ' ] . '): ' ;
76
+ if (null !== $ stripFromFullstack && false !== \strpos ($ point ['file ' ], $ stripFromFullstack )) {
77
+ continue ;
78
+ }
79
+ $ output .= $ point ['file ' ] . ': ' . $ point ['line ' ] . ' > ' ;
74
80
}
75
81
76
82
$ output .= (isset ($ point ['class ' ]) ? $ point ['class ' ] . '-> ' : '' ) . $ point ['function ' ];
@@ -145,7 +151,7 @@ private function __construct()
145
151
*
146
152
* @return string
147
153
*/
148
- public static function dump ($ var , $ maxDepth = 2 , $ stripTags = true , $ echo = true )
154
+ public static function dump ($ var , int $ maxDepth = 2 , bool $ stripTags = true , bool $ echo = true )
149
155
{
150
156
if (\extension_loaded ('xdebug ' )) {
151
157
\ini_set ('xdebug.var_display_max_depth ' , (string ) $ maxDepth );
@@ -156,7 +162,7 @@ public static function dump($var, $maxDepth = 2, $stripTags = true, $echo = true
156
162
\ob_start ();
157
163
\var_dump ($ var );
158
164
159
- $ dump = \ob_get_contents ();
165
+ $ dump = ( string ) \ob_get_contents ();
160
166
161
167
\ob_end_clean ();
162
168
@@ -171,11 +177,10 @@ public static function dump($var, $maxDepth = 2, $stripTags = true, $echo = true
171
177
172
178
/**
173
179
* @param mixed $var
174
- * @param int $maxDepth
175
180
*
176
181
* @return mixed
177
182
*/
178
- public static function export ($ var , $ maxDepth )
183
+ public static function export ($ var , int $ maxDepth )
179
184
{
180
185
$ return = null ;
181
186
$ isObj = \is_object ($ var );
@@ -203,7 +208,7 @@ public static function export($var, $maxDepth)
203
208
return $ var ;
204
209
}
205
210
206
- $ return = new \stdclass ();
211
+ $ return = new \stdClass ();
207
212
if ($ var instanceof \DateTimeInterface) {
208
213
$ return ->__CLASS__ = \get_class ($ var );
209
214
$ return ->date = $ var ->format ('c ' );
@@ -230,13 +235,9 @@ public static function export($var, $maxDepth)
230
235
* Fill the $return variable with class attributes
231
236
* Based on obj2array function from {@see https://secure.php.net/manual/en/function.get-object-vars.php#47075}.
232
237
*
233
- * @param object $var
234
- * @param \stdClass $return
235
- * @param int $maxDepth
236
- *
237
238
* @return mixed
238
239
*/
239
- private static function fillReturnWithClassAttributes ($ var , \stdClass $ return , $ maxDepth )
240
+ private static function fillReturnWithClassAttributes (object $ var , \stdClass $ return , int $ maxDepth )
240
241
{
241
242
$ clone = (array ) $ var ;
242
243
@@ -254,28 +255,20 @@ private static function fillReturnWithClassAttributes($var, \stdClass $return, $
254
255
255
256
/**
256
257
* Gets the real class name of a class name that could be a proxy.
257
- *
258
- * @param string $class
259
- *
260
- * @return string
261
258
*/
262
- private static function getRealClass ($ class )
259
+ private static function getRealClass (string $ class ): string
263
260
{
264
261
if (! \class_exists (Proxy::class) || false === ($ pos = \strrpos ($ class , '\\' . Proxy::MARKER . '\\' ))) {
265
262
return $ class ;
266
263
}
267
264
268
- return \substr ($ class , $ pos + Proxy::MARKER_LENGTH + 2 );
265
+ return \substr ($ class , ( int ) ( $ pos + Proxy::MARKER_LENGTH + 2 ) );
269
266
}
270
267
271
268
/**
272
269
* Gets the real class name of an object (even if its a proxy).
273
- *
274
- * @param object $object
275
- *
276
- * @return string
277
270
*/
278
- private static function getClass ($ object )
271
+ private static function getClass (object $ object ): string
279
272
{
280
273
return self ::getRealClass (\get_class ($ object ));
281
274
}
0 commit comments