Skip to content

Commit 61fdd68

Browse files
Lucas MarquantTZK-
authored andcommitted
Add api collector and formatDuration for LaravelDebugbar
1 parent d0afb95 commit 61fdd68

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Cristal\ApiWrapper\Bridges\BarryvdhLaravelDebugbar;
4+
5+
use DebugBar\DataCollector\MessagesCollector;
6+
7+
class ApiCollector extends MessagesCollector
8+
{
9+
/**
10+
* @param string $name
11+
*/
12+
public function __construct($name = 'api')
13+
{
14+
parent::__construct($name);
15+
}
16+
17+
/**
18+
* @return array
19+
*/
20+
public function getWidgets()
21+
{
22+
$name = $this->getName();
23+
24+
return [
25+
$name => [
26+
'icon' => 'star icon',
27+
'widget' => 'PhpDebugBar.Widgets.MessagesWidget',
28+
'map' => "$name.messages",
29+
'default' => '[]',
30+
'title' => 'API',
31+
],
32+
"$name:badge" => [
33+
'map' => "$name.count",
34+
'default' => 'null',
35+
],
36+
];
37+
}
38+
}

src/Bridges/BarryvdhLaravelDebugbar/DebugbarTransportDecorator.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,23 @@ private function stopMesure($start, $endpoint, $response = null, array $data = [
166166
'[%s] %s[%s]',
167167
$method,
168168
$endpoint,
169-
formatDuration(microtime(true) - $start)
169+
$this->formatDuration(microtime(true) - $start)
170170
)
171171
);
172172

173173
return $this;
174174
}
175+
176+
public static function formatDuration($seconds)
177+
{
178+
if ($seconds < 0.001) {
179+
return round($seconds * 1000000) . 'μs';
180+
}
181+
182+
if ($seconds < 1) {
183+
return round($seconds * 1000, 2) . 'ms';
184+
}
185+
186+
return round($seconds, 2) . 's';
187+
}
175188
}

0 commit comments

Comments
 (0)