Skip to content

Commit

Permalink
Map tooltips (#1732)
Browse files Browse the repository at this point in the history
  • Loading branch information
barryvdh authored Feb 13, 2025
1 parent d55f4a8 commit 447c962
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 34 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"require": {
"php": "^8.1",
"php-debugbar/php-debugbar": "2.1.x",
"php-debugbar/php-debugbar": "~2.1.1",
"illuminate/routing": "^10|^11|^12",
"illuminate/session": "^10|^11|^12",
"illuminate/support": "^10|^11|^12",
Expand Down
29 changes: 13 additions & 16 deletions src/DataCollector/LaravelCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,18 @@ public function collect()
{
return [
"version" => Str::of($this->laravel->version())->explode('.')->first() . '.x',
'tooltip' => [
'Laravel Version' => $this->laravel->version(),
'PHP Version' => phpversion(),
'Environment' => $this->laravel->environment(),
'Debug Mode' => config('app.debug') ? 'Enabled' : 'Disabled',
'URL' => Str::of(config('app.url'))->replace(['http://', 'https://'], ''),
'Timezone' => config('app.timezone'),
'Locale' => config('app.locale'),
]
];
}

/**
* {@inheritDoc}
*/
public function gatherData()
{
return [
'Laravel Version' => $this->laravel->version(),
'PHP Version' => phpversion(),
'Environment' => $this->laravel->environment(),
'Debug Mode' => config('app.debug') ? 'Enabled' : 'Disabled',
'URL' => Str::of(config('app.url'))->replace(['http://', 'https://'], ''),
'Timezone' => config('app.timezone'),
'Locale' => config('app.locale'),
];
}

/**
* {@inheritDoc}
Expand All @@ -59,10 +53,13 @@ public function getWidgets()
return [
"version" => [
"icon" => "laravel phpdebugbar-fab",
"tooltip" => $this->gatherData(),
"map" => "laravel.version",
"default" => ""
],
"version:tooltip" => [
"map" => "laravel.tooltip",
"default" => "{}"
],
];
}
}
41 changes: 24 additions & 17 deletions src/DataCollector/RequestCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,22 @@ public function getWidgets()
"request" => [
"icon" => "tags",
"widget" => "PhpDebugBar.Widgets.HtmlVariableListWidget",
"map" => "request",
"map" => "request.data",
"default" => "{}"
]
];

if (Config::get('debugbar.options.request.label', true)) {
$widgets['currentrequest'] = [
"icon" => "share",
"tooltip" => [
'status' => $this->response->getStatusCode()
],
"map" => "request.uri",
"map" => "request.data.uri",
"link" => "request",
"default" => ""
];
if ($this->request instanceof Request) {
$widgets['currentrequest']['tooltip'] += [
'action_name' => optional($this->request->route())->getName(),
'controller_action' => optional($this->request->route())->getActionName(),
];
}
$widgets['currentrequest:tooltip'] = [
"map" => "request.tooltip",
"default" => "{}"
];
}

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

if ($request instanceof Request) {

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

return $htmlData + $data;
$tooltip = Arr::only($data, ['status', 'full_url']);

if ($this->request instanceof Request) {
$tooltip += [
'action_name' => optional($this->request->route())->getName(),
'controller_action' => optional($this->request->route())->getActionName(),
];
}

return [
'data' => $htmlData + $data,
'tooltip' => array_filter($tooltip)
];
}

protected function getRouteInformation($route)
Expand Down Expand Up @@ -288,10 +295,10 @@ private function getCookieHeader($name, $value, $expires, $path, $domain, $secur
}

$cookie .= '; expires=' . substr(
\DateTime::createFromFormat('U', $expires, new \DateTimeZone('UTC'))->format('D, d-M-Y H:i:s T'),
0,
-5
);
\DateTime::createFromFormat('U', $expires, new \DateTimeZone('UTC'))->format('D, d-M-Y H:i:s T'),
0,
-5
);
}

if ($domain) {
Expand Down

0 comments on commit 447c962

Please sign in to comment.