Config.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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\Config;
  10. use ForkBB\Models\DataModel;
  11. use RuntimeException;
  12. class Config extends DataModel
  13. {
  14. /**
  15. * Ключ модели для контейнера
  16. * @var string
  17. */
  18. protected $cKey = 'Config';
  19. /**
  20. * Заполняет модель данными из кеша/БД
  21. * Создает кеш
  22. */
  23. public function init(): Config
  24. {
  25. $config = $this->c->Cache->get('config');
  26. if (! \is_array($config)) {
  27. $config = $this->load();
  28. if (true !== $this->c->Cache->set('config', $config)) {
  29. throw new RuntimeException('Unable to write value to cache - config');
  30. }
  31. }
  32. $this->setAttrs($config);
  33. return $this;
  34. }
  35. /**
  36. * Сбрасывает кеш конфига
  37. */
  38. public function reset(): Config
  39. {
  40. if (true !== $this->c->Cache->delete('config')) {
  41. throw new RuntimeException('Unable to remove key from cache - config');
  42. }
  43. return $this;
  44. }
  45. }