Model.php 907 B

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