2025-01-31 18:20:13 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2023-08-11 16:43:39 +03:00
|
|
|
namespace openvk\Web\Models\Repositories;
|
2025-01-31 18:20:13 +03:00
|
|
|
|
2023-08-11 16:43:39 +03:00
|
|
|
use openvk\Web\Models\Entities\User;
|
|
|
|
|
|
|
|
class CurrentUser
|
|
|
|
{
|
|
|
|
private static $instance = null;
|
|
|
|
private $user;
|
|
|
|
private $ip;
|
|
|
|
private $useragent;
|
|
|
|
|
2025-01-31 18:20:13 +03:00
|
|
|
public function __construct(?User $user = null, ?string $ip = null, ?string $useragent = null)
|
2023-08-11 16:43:39 +03:00
|
|
|
{
|
2025-01-31 18:20:13 +03:00
|
|
|
if ($user) {
|
2023-08-11 16:43:39 +03:00
|
|
|
$this->user = $user;
|
2025-01-31 18:20:13 +03:00
|
|
|
}
|
2023-08-11 16:43:39 +03:00
|
|
|
|
2025-01-31 18:20:13 +03:00
|
|
|
if ($ip) {
|
2023-08-11 16:43:39 +03:00
|
|
|
$this->ip = $ip;
|
2025-01-31 18:20:13 +03:00
|
|
|
}
|
2023-08-11 16:43:39 +03:00
|
|
|
|
2025-01-31 18:20:13 +03:00
|
|
|
if ($useragent) {
|
2023-08-11 16:43:39 +03:00
|
|
|
$this->useragent = $useragent;
|
2025-01-31 18:20:13 +03:00
|
|
|
}
|
2023-08-11 16:43:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function get($user, $ip, $useragent)
|
|
|
|
{
|
2025-01-31 18:20:13 +03:00
|
|
|
if (self::$instance === null) {
|
|
|
|
self::$instance = new self($user, $ip, $useragent);
|
|
|
|
}
|
2023-08-11 16:43:39 +03:00
|
|
|
return self::$instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getUser(): User
|
|
|
|
{
|
|
|
|
return $this->user;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getIP(): string
|
|
|
|
{
|
|
|
|
return $this->ip;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getUserAgent(): string
|
|
|
|
{
|
|
|
|
return $this->useragent;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function i()
|
|
|
|
{
|
|
|
|
return self::$instance;
|
|
|
|
}
|
|
|
|
}
|