openvk/Web/Models/Repositories/CurrentUser.php
n1rwana 8265dc0fc6
Add logging system (#940)
* Логи

* Update DBEntity.updated.php

* Сбор IP и UserAgent + фикс логирования в IPs

* Fixes

* Совместимость с новыми логами

* Update Logs.xml

* Logs i18n

* Update Logs.xml

* Update AdminPresenter.php
2023-08-11 16:43:39 +03:00

49 lines
1,016 B
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;
}
}