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