Skip to content

Commit

Permalink
feat(var-dump): support new frontend feature: programing language hig…
Browse files Browse the repository at this point in the history
…hlighting; fix events field `project`
  • Loading branch information
roxblnfk committed Jun 7, 2024
1 parent 90852f7 commit 04e41b2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/Sender/Frontend/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(
public readonly string $type,
public readonly array $payload,
public readonly float $timestamp,
public readonly ?string $projectId = null,
public readonly ?string $project = null,
public readonly ?\ArrayAccess $assets = null,
) {}

Expand All @@ -32,7 +32,7 @@ public function jsonSerialize(): array
'type' => $this->type,
'payload' => $this->payload,
'timestamp' => $this->timestamp,
'project_id' => $this->projectId,
'project' => $this->project,
];
}
}
32 changes: 24 additions & 8 deletions src/Sender/Frontend/Mapper/VarDump.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,34 @@ final class VarDump
{
public function map(VarDumperFrame $frame): Event
{
$payload = $this->parse($frame->dump);
$parsed = $this->parse($frame->dump);

$dataContext = $parsed[0]->getContext();

$payload = [
'type' => $parsed[0]->getType(),
'value' => $this->convertToPrimitive($parsed[0]),
'label' => $dataContext['label'] ?? null,
];

if (\array_key_exists('language', $dataContext) && \is_string($dataContext['language'])) {
$payload['type'] = 'code';
$payload['language'] = $dataContext['language'];
}

$project = \array_key_exists('project', $dataContext) && \is_scalar($dataContext['project'])
? (string) $dataContext['project']
: null;

return new Event(
uuid: Uuid::generate(),
type: 'var-dump',
payload: [
'payload' => [
'type' => $payload[0]->getType(),
'value' => $this->convertToPrimitive($payload[0]),
],
'context' => $payload[1],
'payload' => $payload,
'context' => $parsed[1],
],
timestamp: (float) $frame->time->format('U.u'),
project: $project,
);
}

Expand All @@ -38,7 +54,7 @@ public function map(VarDumperFrame $frame): Event
*/
private function parse(string $message): array
{
$payload = @\unserialize(\base64_decode($message), ['allowed_classes' => [Data::class, Stub::class]]);
$payload = @\unserialize(\base64_decode($message, true), ['allowed_classes' => [Data::class, Stub::class]]);

// Impossible to decode the message, give up.
if ($payload === false) {
Expand All @@ -59,7 +75,7 @@ private function parse(string $message): array

private function convertToPrimitive(Data $data): string|null
{
if (\in_array($data->getType(), ['string', 'boolean'])) {
if (\in_array($data->getType(), ['string', 'boolean'], true)) {
/** @psalm-suppress PossiblyInvalidCast */
return (string) $data->getValue();
}
Expand Down

0 comments on commit 04e41b2

Please sign in to comment.