Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Tests
name: tests

on: push

Expand Down
10 changes: 5 additions & 5 deletions src/DataObject/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
final class Connection
{
public function __construct(
public string $connectionType,
public int $autonomousSystemNumber,
public string $autonomousSystemOrganization,
public string $ispName,
public string $organizationName,
public ?string $connectionType,
public ?int $autonomousSystemNumber,
public ?string $autonomousSystemOrganization,
public ?string $ispName,
public ?string $organizationName,
) {
}
}
19 changes: 18 additions & 1 deletion src/Middleware/AbstractIpGeolocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,25 @@ public function handle($request, Closure $next): mixed
(new IpGeolocation($request))->initialize()
);

session()->put('abstract-ip-geolocation', $response);
$this->manageSession($response);

return $next($request);
}

public function manageSession(GeolocationData $geolocation): void
{
$sessionKey = 'abstract-ip-geolocation';

if (session()->exists($sessionKey)) {
/** @var GeolocationData $currentValue */
$currentValue = session()->get($sessionKey);

if ($currentValue->ipAddress !== $geolocation->ipAddress) {
session()->forget($sessionKey);
session()->put($sessionKey, $geolocation);
}
} else {
session()->put($sessionKey, $geolocation);
}
}
}