-
Notifications
You must be signed in to change notification settings - Fork 0
/
shortcuts.php
212 lines (187 loc) · 5.1 KB
/
shortcuts.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
/**
* This file is part of the Dogma library (https://github.com/paranoiq/dogma)
*
* Copyright (c) 2012 Vlasta Neubauer (@paranoiq)
*
* For the full copyright and license information read the file 'license.md', distributed with this source code
*/
error_reporting(E_ALL);
ini_set('display_errors', 'on');
// phpcs:disable PSR2.Files.EndFileNewline.NoneFound
// phpcs:disable Squiz.Arrays.ArrayDeclaration.ValueNoNewline
use Dogma\Debug\Ansi;
use Dogma\Debug\Callstack;
use Dogma\Debug\Debugger;
use Dogma\Debug\Diff;
use Dogma\Debug\Dumper;
use Dogma\Debug\Message;
if (!function_exists('rd')) {
/**
* Remote dump implemented with native var_dump() + some colors
*
* @template T
* @param T $value
* @return T
*/
function lvd($value, bool $colors = true)
{
Debugger::print(Dumper::varDump($value, $colors));
return $value;
}
/**
* Local dump
*
* @template T
* @param T $value
* @return T
*/
function ld($value, ?int $maxDepth = null, ?int $traceLength = null)
{
Debugger::print(Dumper::dump($value, $maxDepth, $traceLength));
return $value;
}
/**
* Remote dump implemented with native var_dump() + some colors
*
* @template T
* @param T $value
* @return T
*/
function rvd($value, bool $colors = true)
{
return Debugger::varDump($value, $colors);
}
/**
* Remote dump
*
* @template T
* @param T $value
* @return T
*/
function rd($value, ?int $maxDepth = null, ?int $traceLength = null, ?string $name = null)
{
return Debugger::dump($value, $maxDepth, $traceLength, $name);
}
/**
* Remote dump all (turn off limit on array length)
*
* @template T
* @param T $value
* @return T
*/
function rda($value, ?int $maxDepth = null, ?int $traceLength = null, ?string $name = null)
{
$prev = Dumper::$arrayMaxLength;
Dumper::$arrayMaxLength = 1000000000;
$result = Debugger::dump($value, $maxDepth, $traceLength, $name);
Dumper::$arrayMaxLength = $prev;
return $result;
}
/**
* Remote dump table
*
* @template T
* @param T $value
* @return T
*/
function rdt($value, ?int $traceLength = null, ?string $name = null)
{
return Debugger::dumpTable($value, $traceLength, $name);
}
/**
* Remote dump exception (formatted same way as when thrown)
*
* @template T of Throwable
* @param T $exception
* @return T
*/
function re(Throwable $exception): Throwable
{
return Debugger::dumpException($exception);
}
/**
* Remote diff dump
*/
function rdf(string $a, string $b): void
{
$message = Ansi::white('diff:') . ' ' . Diff::cliDiff($a, $b);
Debugger::send(Message::DUMP, $message);
}
/**
* Remote capture dump
*/
function rc(callable $callback, ?int $maxDepth = null, ?int $traceLength = null): string
{
return Debugger::capture($callback, $maxDepth, $traceLength);
}
/**
* Remotely print function/method name
*/
function rf(bool $withLocation = true, bool $withDepth = false, ?string $function = null): void
{
Debugger::function($withLocation, $withDepth, $function);
}
/**
* Remote backtrace dump
* @phpstan-import-type PhpBacktraceItem from Callstack
* @param Callstack|PhpBacktraceItem[]|null $callstack
*/
function rb(?int $length = null, ?int $argsDepth = null, ?int $codeLines = null, ?int $codeDepth = null, $callstack = null): void
{
Debugger::callstack($length, $argsDepth, $codeLines, $codeDepth, $callstack);
}
/**
* Remote label print
*
* @param string|int|float|bool|object|null $label
* @return string|int|float|bool|object|null
*/
function rl($label, ?string $name = null, ?string $color = null)
{
return Debugger::label($label, $name, $color);
}
/**
* Remote timer. Shows time since previous event or from start of the request
*
* @param string|int $group
* @param string|int $name
*/
function rt($group = '', $name = ''): void
{
Debugger::timer($group, $name);
}
/**
* Remote memory report. Shows memory consumed/freed from previous event or total
*
* @param string|int|null $name
*/
function rm($name = ''): void
{
Debugger::memory($name);
}
/**
* Remote write. Write raw formatted string to debug output
*/
function rw(string $data): void
{
Debugger::raw($data);
}
/**
* Extract private property from an object
*
* @param object $object
* @return mixed
*/
function xp($object, string $property, ?string $class = null)
{
$prop = new ReflectionProperty($class ?? get_class($object), $property);
if (PHP_VERSION_ID <= 80000) {
$prop->setAccessible(true);
}
return $prop->getValue($object);
}
}
if (!require_once __DIR__ . '/client.php') {
return;
}