Repository navigation
Expand file tree
/
Copy pathToolbarData.php
More file actions
204 lines (193 loc) · 6.55 KB
/
Copy pathToolbarData.php
File metadata and controls
204 lines (193 loc) · 6.55 KB
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
<?php
declare(strict_types=1);
namespace PHPForge\Debug\Toolbar;
use JsonSerializable;
use function array_map;
/**
* Represents the framework-neutral payload loaded by the debug toolbar runtime.
*/
final readonly class ToolbarData implements JsonSerializable
{
/**
* @param string $tag Captured request tag.
* @param string $title Toolbar brand title.
* @param string $indexUrl Debug history URL.
* @param string $configUrl Framework configuration URL.
* @param list<ToolbarPanel> $items Toolbar panels.
* @param string $position Initial toolbar position.
* @param int $defaultHeight Initial drawer height percentage.
* @param string $iconBaseUrl Base URL for optional SVG icons.
* @param string|null $logo Primary logo URL or `null` to use the fallback.
* @param string|null $logoFallback Fallback logo URL or `null` to render the built-in mark.
* @param string|null $phpInfoUrl PHP information URL or `null` when unavailable.
* @param string|null $phpVersion PHP version label or `null` when omitted.
* @param string|null $yiiVersion Yii version label or `null` when omitted.
*/
private function __construct(
public string $tag,
public string $title,
public string $indexUrl,
public string $configUrl,
public array $items,
public string $position = 'bottom',
public int $defaultHeight = 50,
public string $iconBaseUrl = '',
public string|null $logo = null,
public string|null $logoFallback = null,
public string|null $phpInfoUrl = null,
public string|null $phpVersion = null,
public string|null $yiiVersion = null,
) {}
/**
* Creates a minimal toolbar payload ready for immutable enrichment.
*/
public static function create(string $tag, string $title): self
{
return new self(tag: $tag, title: $title, indexUrl: '', configUrl: '', items: []);
}
/**
* Returns the complete payload consumed by the toolbar runtime.
*
* @return array{
* configUrl: string,
* defaultHeight: int,
* iconBaseUrl: string,
* indexUrl: string,
* items: list<array{
* id: string,
* title: string,
* items: list<array{
* value: string,
* status: string,
* label?: string,
* icon?: string,
* title?: string,
* url?: string,
* id?: string,
* }>,
* url?: string,
* icon?: string,
* extension?: true,
* }>,
* logo: string|null,
* logoFallback: string|null,
* phpInfoUrl: string|null,
* phpVersion: string|null,
* position: string,
* tag: string,
* title: string,
* yiiVersion: string|null,
* } Serialized toolbar payload.
*/
public function jsonSerialize(): array
{
return [
'configUrl' => $this->configUrl,
'defaultHeight' => $this->defaultHeight,
'iconBaseUrl' => $this->iconBaseUrl,
'indexUrl' => $this->indexUrl,
'items' => array_map(
static fn(ToolbarPanel $panel): array => $panel->jsonSerialize(),
$this->items,
),
'logo' => $this->logo,
'logoFallback' => $this->logoFallback,
'phpInfoUrl' => $this->phpInfoUrl,
'phpVersion' => $this->phpVersion,
'position' => $this->position,
'tag' => $this->tag,
'title' => $this->title,
'yiiVersion' => $this->yiiVersion,
];
}
/**
* Returns a copy with brand assets and version labels.
*/
public function withBranding(
string|null $logo,
string|null $logoFallback,
string|null $phpVersion,
string|null $yiiVersion,
): self {
return new self(
tag: $this->tag,
title: $this->title,
indexUrl: $this->indexUrl,
configUrl: $this->configUrl,
items: $this->items,
position: $this->position,
defaultHeight: $this->defaultHeight,
iconBaseUrl: $this->iconBaseUrl,
logo: $logo,
logoFallback: $logoFallback,
phpInfoUrl: $this->phpInfoUrl,
phpVersion: $phpVersion,
yiiVersion: $yiiVersion,
);
}
/**
* Returns a copy with debugger navigation URLs.
*/
public function withNavigation(string $indexUrl, string $configUrl, string|null $phpInfoUrl): self
{
return new self(
tag: $this->tag,
title: $this->title,
indexUrl: $indexUrl,
configUrl: $configUrl,
items: $this->items,
position: $this->position,
defaultHeight: $this->defaultHeight,
iconBaseUrl: $this->iconBaseUrl,
logo: $this->logo,
logoFallback: $this->logoFallback,
phpInfoUrl: $phpInfoUrl,
phpVersion: $this->phpVersion,
yiiVersion: $this->yiiVersion,
);
}
/**
* Returns a copy with toolbar panels.
*
* @param list<ToolbarPanel> $items
*/
public function withPanels(array $items): self
{
return new self(
tag: $this->tag,
title: $this->title,
indexUrl: $this->indexUrl,
configUrl: $this->configUrl,
items: $items,
position: $this->position,
defaultHeight: $this->defaultHeight,
iconBaseUrl: $this->iconBaseUrl,
logo: $this->logo,
logoFallback: $this->logoFallback,
phpInfoUrl: $this->phpInfoUrl,
phpVersion: $this->phpVersion,
yiiVersion: $this->yiiVersion,
);
}
/**
* Returns a copy with drawer presentation settings.
*/
public function withPresentation(string $position, int $defaultHeight, string $iconBaseUrl = ''): self
{
return new self(
tag: $this->tag,
title: $this->title,
indexUrl: $this->indexUrl,
configUrl: $this->configUrl,
items: $this->items,
position: $position,
defaultHeight: $defaultHeight,
iconBaseUrl: $iconBaseUrl,
logo: $this->logo,
logoFallback: $this->logoFallback,
phpInfoUrl: $this->phpInfoUrl,
phpVersion: $this->phpVersion,
yiiVersion: $this->yiiVersion,
);
}
}