. */ namespace SP\Repositories\Track; use SP\Core\Exceptions\InvalidArgumentException; use SP\Http\Address; /** * Class TrackRequest * * @package SP\Repositories\Track */ final class TrackRequest { public int $time; public string $source; public ?int $userId = null; private ?string $ipv6 = null; private ?string $ipv4 = null; /** * @param int $time * @param string $source * @param int|null $userId */ public function __construct(int $time, string $source, ?int $userId = null) { $this->time = $time; $this->source = $source; $this->userId = $userId; } /** * @param string $address * * @throws InvalidArgumentException */ public function setTrackIp(string $address): void { $binary = Address::toBinary($address); $length = strlen($binary); if ($length === 4) { $this->ipv4 = $binary; } else { $this->ipv6 = $binary; } } /** * @return string */ public function getIpv6(): ?string { return $this->ipv6; } /** * @return string */ public function getIpv4(): ?string { return $this->ipv4; } }