Model.php 956 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace ForkBB\Models\AdminList;
  3. use ForkBB\Models\Model as ParentModel;
  4. use RuntimeException;
  5. class Model extends ParentModel
  6. {
  7. /**
  8. * Загружает список id админов из кеша/БД
  9. */
  10. public function init(): Model
  11. {
  12. $this->list = $this->c->Cache->get('admins');
  13. if (! \is_array($this->list)) {
  14. $this->list = \array_flip($this->c->users->adminsIds());
  15. if (true !== $this->c->Cache->set('admins', $this->list)) {
  16. throw new RuntimeException('Unable to write value to cache - admins');
  17. }
  18. }
  19. return $this;
  20. }
  21. /**
  22. * Сбрасывает кеш списка id админов
  23. */
  24. public function reset(): Model
  25. {
  26. if (true !== $this->c->Cache->delete('admins')) {
  27. throw new RuntimeException('Unable to remove key from cache - admins');
  28. }
  29. return $this;
  30. }
  31. }