|
public function addMessage(string $message): void |
I also have a problem here, if I want to send debugbar('queries')->addMessage($my_collection->count()) i get TypeError
it's because $message expects a string, and count is a integer
Some clean way to handle int, float, maybe bool,
What about arrays, Stringable?
of course and I'm now doing a cast debugbar('queries')->addMessage((string) $my_collection->count()), but it's annoying to do it in every message.
maybe (ChatGPT suggestion)
public function addMessage(mixed $message) {
///...
'sql' => $this->normalizeToString($message),
///...
}
private function normalizeToString(mixed $value): string
{
if ($value === null) {
return 'null';
}
if (is_scalar($value)) {
return (string) $value;
}
if (is_object($value) && method_exists($value, '__toString')) {
return (string) $value;
}
if (is_array($value) || is_object($value)) {
$json = json_encode($value, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
return $json !== false ? $json : '[json encode error]';
}
// fallback (resources, etc.)
return '[unstringable value]';
}
maybe a formatter already exists for this and can be reused, any ideas?
laravel-debugbar/src/DataCollector/QueryCollector.php
Line 357 in 29bbf4e
I also have a problem here, if I want to send
debugbar('queries')->addMessage($my_collection->count())i getTypeErrorit's because
$messageexpects astring, and count is a integerSome clean way to handle int, float, maybe bool,
What about arrays, Stringable?
of course and I'm now doing a cast
debugbar('queries')->addMessage((string) $my_collection->count()), but it's annoying to do it in every message.maybe (ChatGPT suggestion)
maybe a formatter already exists for this and can be reused, any ideas?