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
|
<?php
namespace Studip\Debug;
use DebugBar\DataCollector\DataCollector;
use DebugBar\DataCollector\Renderable;
use Studip\VueApp;
final class VueCollector extends DataCollector implements Renderable
{
public function __construct(
private readonly VueApp $app
) {
$this->useHtmlVarDumper(false);
}
public function collect()
{
$data = [];
$props = $this->app->getProps();
if (count($props) > 0) {
ksort($props);
$data['== DATA =='] = count($props) . ' items';
foreach ($props as $key => $value) {
$data[$key] = $this->dumpVar($value);
}
}
$this->addStores(
$data,
'PINIA STORES',
$this->app->getStores(),
$this->app->getStoreData()
);
$this->addStores(
$data,
'VUEX STORES',
$this->app->getVuexStores(),
$this->app->getVuexStoreData()
);
$slots = $this->app->getSlots();
if (count($slots) > 0) {
ksort($slots);
$data['== SLOTS =='] = count($slots) . ' items';
foreach ($slots as $key => $value) {
$data[$key] = $this->dumpVar($value);
}
}
return $data;
}
public function getName()
{
return '[Vue]' . basename($this->app->getAppPath());
}
/**
* @return array
*/
public function getAssets()
{
return $this->isHtmlVarDumperUsed() ? $this->getVarDumper()->getAssets() : [];
}
/**
* @return array[]
*/
public function getWidgets()
{
$name = $this->getName();
$widget = $this->isHtmlVarDumperUsed()
? 'PhpDebugBar.Widgets.HtmlVariableListWidget'
: 'PhpDebugBar.Widgets.VariableListWidget';
return [
$name => [
'icon' => 'code',
'widget' => $widget,
'map' => $name,
'default' => '{}'
],
];
}
private function dumpVar(mixed $variable): string
{
if ($this->isHtmlVarDumperUsed()) {
return $this->getVarDumper()->renderVar($variable);
}
if (!is_string($variable)) {
return $this->getDataFormatter()->formatVar($variable);
}
return $variable;
}
private function addStores(
array &$data,
string $index,
array $stores,
array $storeData
): void {
if (count($stores) > 0) {
ksort($stores);
$data["== {$index} =="] = '';
foreach ($stores as $index => $store) {
$data[$index] = $store === $index ? '' : "({$store})";
$tmp = $storeData[$index] ?? [];
ksort($tmp);
foreach ($tmp as $key => $value) {
$data["- {$key}"] = $this->dumpVar($value);
}
}
}
}
}
|