Created named constructors for Visit entity and added tracking of the visited URL

This commit is contained in:
Alejandro Celaya
2021-02-07 21:31:12 +01:00
parent f5666c9451
commit 12b07bb0ac
19 changed files with 101 additions and 60 deletions

View File

@@ -18,12 +18,14 @@ final class Visitor
private string $userAgent;
private string $referer;
private string $visitedUrl;
private ?string $remoteAddress;
public function __construct(string $userAgent, string $referer, ?string $remoteAddress)
public function __construct(string $userAgent, string $referer, ?string $remoteAddress, string $visitedUrl)
{
$this->userAgent = $this->cropToLength($userAgent, self::USER_AGENT_MAX_LENGTH);
$this->referer = $this->cropToLength($referer, self::REFERER_MAX_LENGTH);
$this->visitedUrl = $this->cropToLength($visitedUrl, self::VISITED_URL_MAX_LENGTH);
$this->remoteAddress = $this->cropToLength($remoteAddress, self::REMOTE_ADDRESS_MAX_LENGTH);
}
@@ -38,12 +40,13 @@ final class Visitor
$request->getHeaderLine('User-Agent'),
$request->getHeaderLine('Referer'),
$request->getAttribute(IpAddressMiddlewareFactory::REQUEST_ATTR),
$request->getUri()->__toString(),
);
}
public static function emptyInstance(): self
{
return new self('', '', null);
return new self('', '', null, '');
}
public function getUserAgent(): string
@@ -60,4 +63,9 @@ final class Visitor
{
return $this->remoteAddress;
}
public function getVisitedUrl(): string
{
return $this->visitedUrl;
}
}