openvk/Web/Models/Repositories/CurrentUser.php
Alexander Minkin 6ec54a379d
feat: add linting of code (#1220)
* 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.
2025-01-31 18:20:13 +03:00

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;
}
}