Update Users manager
This commit is contained in:
parent
d2e0f4e31d
commit
e109869e85
1 changed files with 40 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue