Skip to content

Commit 447c962

Browse files
authored
Map tooltips (barryvdh#1732)
1 parent d55f4a8 commit 447c962

File tree

3 files changed

+38
-34
lines changed

3 files changed

+38
-34
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
],
1919
"require": {
2020
"php": "^8.1",
21-
"php-debugbar/php-debugbar": "2.1.x",
21+
"php-debugbar/php-debugbar": "~2.1.1",
2222
"illuminate/routing": "^10|^11|^12",
2323
"illuminate/session": "^10|^11|^12",
2424
"illuminate/support": "^10|^11|^12",

src/DataCollector/LaravelCollector.php

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,18 @@ public function collect()
2424
{
2525
return [
2626
"version" => Str::of($this->laravel->version())->explode('.')->first() . '.x',
27+
'tooltip' => [
28+
'Laravel Version' => $this->laravel->version(),
29+
'PHP Version' => phpversion(),
30+
'Environment' => $this->laravel->environment(),
31+
'Debug Mode' => config('app.debug') ? 'Enabled' : 'Disabled',
32+
'URL' => Str::of(config('app.url'))->replace(['http://', 'https://'], ''),
33+
'Timezone' => config('app.timezone'),
34+
'Locale' => config('app.locale'),
35+
]
2736
];
2837
}
2938

30-
/**
31-
* {@inheritDoc}
32-
*/
33-
public function gatherData()
34-
{
35-
return [
36-
'Laravel Version' => $this->laravel->version(),
37-
'PHP Version' => phpversion(),
38-
'Environment' => $this->laravel->environment(),
39-
'Debug Mode' => config('app.debug') ? 'Enabled' : 'Disabled',
40-
'URL' => Str::of(config('app.url'))->replace(['http://', 'https://'], ''),
41-
'Timezone' => config('app.timezone'),
42-
'Locale' => config('app.locale'),
43-
];
44-
}
4539

4640
/**
4741
* {@inheritDoc}
@@ -59,10 +53,13 @@ public function getWidgets()
5953
return [
6054
"version" => [
6155
"icon" => "laravel phpdebugbar-fab",
62-
"tooltip" => $this->gatherData(),
6356
"map" => "laravel.version",
6457
"default" => ""
6558
],
59+
"version:tooltip" => [
60+
"map" => "laravel.tooltip",
61+
"default" => "{}"
62+
],
6663
];
6764
}
6865
}

src/DataCollector/RequestCollector.php

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,22 @@ public function getWidgets()
7070
"request" => [
7171
"icon" => "tags",
7272
"widget" => "PhpDebugBar.Widgets.HtmlVariableListWidget",
73-
"map" => "request",
73+
"map" => "request.data",
7474
"default" => "{}"
7575
]
7676
];
7777

7878
if (Config::get('debugbar.options.request.label', true)) {
7979
$widgets['currentrequest'] = [
8080
"icon" => "share",
81-
"tooltip" => [
82-
'status' => $this->response->getStatusCode()
83-
],
84-
"map" => "request.uri",
81+
"map" => "request.data.uri",
8582
"link" => "request",
8683
"default" => ""
8784
];
88-
if ($this->request instanceof Request) {
89-
$widgets['currentrequest']['tooltip'] += [
90-
'action_name' => optional($this->request->route())->getName(),
91-
'controller_action' => optional($this->request->route())->getActionName(),
92-
];
93-
}
85+
$widgets['currentrequest:tooltip'] = [
86+
"map" => "request.tooltip",
87+
"default" => "{}"
88+
];
9489
}
9590

9691
return $widgets;
@@ -130,7 +125,7 @@ public function collect()
130125
'status' => $statusCode . ' ' . (isset(Response::$statusTexts[$statusCode]) ? Response::$statusTexts[$statusCode] : ''),
131126
'duration' => $startTime ? $this->formatDuration(microtime(true) - $startTime) : null,
132127
'peak_memory' => $this->formatBytes(memory_get_peak_usage(true), 1),
133-
];
128+
];
134129

135130
if ($request instanceof Request) {
136131

@@ -191,7 +186,19 @@ public function collect()
191186
$htmlData['telescope'] = '<a href="' . $url . '" target="_blank">View in Telescope</a>';
192187
}
193188

194-
return $htmlData + $data;
189+
$tooltip = Arr::only($data, ['status', 'full_url']);
190+
191+
if ($this->request instanceof Request) {
192+
$tooltip += [
193+
'action_name' => optional($this->request->route())->getName(),
194+
'controller_action' => optional($this->request->route())->getActionName(),
195+
];
196+
}
197+
198+
return [
199+
'data' => $htmlData + $data,
200+
'tooltip' => array_filter($tooltip)
201+
];
195202
}
196203

197204
protected function getRouteInformation($route)
@@ -288,10 +295,10 @@ private function getCookieHeader($name, $value, $expires, $path, $domain, $secur
288295
}
289296

290297
$cookie .= '; expires=' . substr(
291-
\DateTime::createFromFormat('U', $expires, new \DateTimeZone('UTC'))->format('D, d-M-Y H:i:s T'),
292-
0,
293-
-5
294-
);
298+
\DateTime::createFromFormat('U', $expires, new \DateTimeZone('UTC'))->format('D, d-M-Y H:i:s T'),
299+
0,
300+
-5
301+
);
295302
}
296303

297304
if ($domain) {

0 commit comments

Comments
 (0)