Skip to content

Commit

Permalink
Add Visit::toArray() method
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya committed Dec 12, 2024
1 parent 88c2839 commit d8087c2
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions module/Core/src/Visit/Entity/Visit.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ public function getType(): VisitType
}

public function jsonSerialize(): array
{
return $this->toArray();
}

/**
* @phpstan-type VisitedShortUrl array{shortCode: string, domain: string|null, shortUrl: string}
* @param (callable(ShortUrl $shortUrl): VisitedShortUrl)|null $visitedShortUrlToArray
*/
public function toArray(callable|null $visitedShortUrlToArray = null): array
{
$base = [
'referer' => $this->referer,
Expand All @@ -160,8 +169,11 @@ public function jsonSerialize(): array
'visitedUrl' => $this->visitedUrl,
'redirectUrl' => $this->redirectUrl,
];
if (! $this->isOrphan()) {
return $base;
if ($this->shortUrl !== null) {
return $visitedShortUrlToArray === null ? $base : [
...$base,
'visitedShortUrl' => $visitedShortUrlToArray($this->shortUrl),
];
}

return [
Expand Down

0 comments on commit d8087c2

Please sign in to comment.