Skip to content

Commit 5201842

Browse files
committed
Fixes
1 parent 76c128c commit 5201842

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

src/DataCollector/CacheCollector.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class CacheCollector extends TimeDataCollector
2525

2626
public function __construct($requestStartTime, $collectValues)
2727
{
28-
parent::__construct();
28+
parent::__construct($requestStartTime);
2929

3030
$this->collectValues = $collectValues;
3131
}
@@ -38,8 +38,22 @@ public function onCacheEvent(CacheEvent $event)
3838
$label = $this->classMap[$class];
3939

4040
if (isset($params['value'])) {
41+
if (is_string($params['value'])) {
42+
$params['size'] = strlen($params['value']);
43+
} else {
44+
$params['size'] = strlen(serialize($params['value']));
45+
}
46+
47+
if (isset($params['size'])) {
48+
$params['size'] = $this->getDataFormatter()->formatBytes($params['size'] * 8);
49+
}
50+
4151
if ($this->collectValues) {
42-
$params['value'] = htmlspecialchars($this->getDataFormatter()->formatVar($event->value));
52+
if (is_string($params['value'])) {
53+
$params['value'] = @unserialize($params['value']) ?: $params['value'];
54+
}
55+
56+
$params['value'] = htmlspecialchars($this->getDataFormatter()->formatVar($params['value']));
4357
} else {
4458
unset($params['value']);
4559
}
@@ -60,7 +74,7 @@ public function onCacheEvent(CacheEvent $event)
6074

6175
public function subscribe(Dispatcher $dispatcher)
6276
{
63-
foreach ($this->classMap as $eventClass => $type) {
77+
foreach (array_keys($this->classMap) as $eventClass) {
6478
$dispatcher->listen($eventClass, [$this, 'onCacheEvent']);
6579
}
6680
}

src/LaravelDebugbar.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,7 @@ public function modifyResponse(Request $request, Response $response)
863863
&& !$this->isJsonRequest($request, $response)
864864
&& $response->getContent() !== false
865865
&& in_array($request->getRequestFormat(), [null, 'html'], true)
866+
&& !$this->isJsonResponse($response)
866867
) {
867868
try {
868869
$this->injectDebugbar($response);
@@ -936,6 +937,30 @@ protected function isJsonRequest(Request $request, Response $response)
936937
return false;
937938
}
938939

940+
/**
941+
* @param \Symfony\Component\HttpFoundation\Response $response
942+
* @return bool
943+
*/
944+
protected function isJsonResponse(Response $response)
945+
{
946+
if ($response->headers->get('Content-Type') == 'application/json') {
947+
return true;
948+
}
949+
950+
$content = $response->getContent();
951+
952+
if (function_exists('json_validate')) {
953+
return json_validate($content);
954+
} else if (is_string($content)) {
955+
// PHP <= 8.2 check
956+
json_decode($content, true);
957+
958+
return json_last_error() === JSON_ERROR_NONE;
959+
}
960+
961+
return false;
962+
}
963+
939964
/**
940965
* Collects the data from the collectors
941966
*

0 commit comments

Comments
 (0)