mirror of
https://github.com/openvk/openvk
synced 2025-02-02 21:15:42 +03:00
Alexander Minkin
6ec54a379d
* feat(lint): add php-cs-fixer for linting Removing previous CODE_STYLE as it was not enforced anyway and using PER-CS 2.0. This is not the reformatting commit. * style: format code according to PER-CS 2.0 with php-cs-fixer * ci(actions): add lint action Resolves #1132.
58 lines
1.1 KiB
PHP
58 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace openvk\Web\Models\Repositories;
|
|
|
|
use openvk\Web\Models\Entities\User;
|
|
|
|
class CurrentUser
|
|
{
|
|
private static $instance = null;
|
|
private $user;
|
|
private $ip;
|
|
private $useragent;
|
|
|
|
public function __construct(?User $user = null, ?string $ip = null, ?string $useragent = null)
|
|
{
|
|
if ($user) {
|
|
$this->user = $user;
|
|
}
|
|
|
|
if ($ip) {
|
|
$this->ip = $ip;
|
|
}
|
|
|
|
if ($useragent) {
|
|
$this->useragent = $useragent;
|
|
}
|
|
}
|
|
|
|
public static function get($user, $ip, $useragent)
|
|
{
|
|
if (self::$instance === null) {
|
|
self::$instance = new self($user, $ip, $useragent);
|
|
}
|
|
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;
|
|
}
|
|
}
|