Update Users manager

This commit is contained in:
Visman 2021-12-04 18:24:12 +07:00
parent d2e0f4e31d
commit e109869e85

View file

@ -12,9 +12,12 @@ namespace ForkBB\Models\User;
use ForkBB\Models\Manager;
use ForkBB\Models\User\User;
use RuntimeException;
class Users extends Manager
{
const CACHE_NAME = 'guest';
/**
* Ключ модели для контейнера
* @var string
@ -129,4 +132,41 @@ class Users extends Manager
return $id;
}
/**
* Создает гостя
*/
public function guest(array $attrs = []): User
{
$cache = $this->c->Cache->get(CACHE_NAME);
if (! \is_array($cache)) {
$cache = $this->c->groups->get(FORK_GROUP_GUEST)->getAttrs();
if (true !== $this->c->Cache->set(CACHE_NAME, $cache)) {
throw new RuntimeException('Unable to write value to cache - ' . CACHE_NAME);
}
}
return $this->create(
[
'id' => 0,
'group_id' => FORK_GROUP_GUEST,
]
+ $attrs
+ $cache
);
}
/**
* Сбрасывает кеш гостя
*/
public function resetGuest(): Users
{
if (true !== $this->c->Cache->delete(CACHE_NAME)) {
throw new RuntimeException('Unable to remove key from cache - ' . CACHE_NAME);
}
return $this;
}
}