AdminList.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * This file is part of the ForkBB <https://github.com/forkbb>.
  4. *
  5. * @copyright (c) Visman <mio.visman@yandex.ru, https://github.com/MioVisman>
  6. * @license The MIT License (MIT)
  7. */
  8. declare(strict_types=1);
  9. namespace ForkBB\Models\AdminList;
  10. use ForkBB\Models\Model;
  11. use RuntimeException;
  12. class AdminList extends Model
  13. {
  14. /**
  15. * Ключ модели для контейнера
  16. * @var string
  17. */
  18. protected $cKey = 'AdminList';
  19. /**
  20. * Загружает список id админов из кеша/БД
  21. * Создает кеш
  22. */
  23. public function init(): AdminList
  24. {
  25. $this->list = $this->c->Cache->get('admins');
  26. if (! \is_array($this->list)) {
  27. $this->list = \array_flip($this->c->users->adminsIds());
  28. if (true !== $this->c->Cache->set('admins', $this->list)) {
  29. throw new RuntimeException('Unable to write value to cache - admins');
  30. }
  31. }
  32. return $this;
  33. }
  34. /**
  35. * Сбрасывает кеш списка id админов
  36. */
  37. public function reset(): AdminList
  38. {
  39. if (true !== $this->c->Cache->delete('admins')) {
  40. throw new RuntimeException('Unable to remove key from cache - admins');
  41. }
  42. return $this;
  43. }
  44. }