1 <?php
2
3 use Symfony\Component\VarDumper\Cloner\VarCloner;
4 use Symfony\Component\VarDumper\Dumper\CliDumper;
5 use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
6 use Symfony\Component\VarDumper\Dumper\HtmlDumper;
7 use Symfony\Component\VarDumper\VarDumper;
8
9 10 11
12 abstract class rex_var_dumper
13 {
14
15 private static $cloner;
16
17
18 private static $dumper;
19
20 public static function register()
21 {
22 VarDumper::setHandler(function ($var) {
23 if (rex::isDebugMode() || ($user = rex_backend_login::createUser()) && $user->isAdmin()) {
24 VarDumper::setHandler([self::class, 'dump']);
25 self::dump($var);
26
27 return;
28 }
29
30
31 VarDumper::setHandler(function ($var) {
32
33 });
34 });
35 }
36
37 public static function dump($var)
38 {
39 if (!self::$cloner) {
40 self::$cloner = new VarCloner();
41 if ('cli' === PHP_SAPI) {
42 self::$dumper = new CliDumper();
43 } else {
44 $styleAll = 'font-family: "Fira Code", Menlo, Monaco, Consolas, monospace; font-size: 14px; line-height: 1.4 !important;';
45 self::$dumper = new HtmlDumper();
46 self::$dumper->setDumpBoundaries('<pre class="rex-var-dumper sf-dump" id="%s" data-indent-pad="%s"><div class="sf-dump-rex-container">', '</div></pre><script>Sfdump(%s)</script>');
47 self::$dumper->setIndentPad(' ');
48 self::$dumper->setStyles([
49 'rex-container' => $styleAll . '
50 position: relative;
51 z-index: 99999;
52 padding: 10px;
53 background-color: #263238;
54 border: 0;
55 color: #eeffff;
56 white-space: pre-wrap;
57 word-break: normal;
58 word-wrap: break-word;
59 ',
60 'default' => $styleAll . '
61 background-color: transparent;
62 color: #eeffff;
63 ',
64 'const' => $styleAll . 'color: #F78C6C; font-weight: 700;',
65 'ellipsis' => $styleAll . 'color: #eeffff;',
66 'index' => $styleAll . 'color: #C3E88D;',
67 'key' => $styleAll . 'color: #C3E88D;',
68 'meta' => $styleAll . 'color: #89DDFF;',
69 'note' => $styleAll . 'color: #FFB62C;',
70 'num' => $styleAll . 'color: #F78C6C;',
71 'protected' => $styleAll . 'color: #C792EA;',
72 'private' => $styleAll . 'color: #C792EA;',
73 'public' => $styleAll . 'color: #C792EA;',
74 'ref' => $styleAll . 'color: #eeffff;',
75 'str' => $styleAll . 'color: #FF5370;',
76 ]);
77 }
78 }
79
80 self::$dumper->dump(self::$cloner->cloneVar($var));
81 }
82 }
83