. * * @copyright (c) Visman * @license The MIT License (MIT) */ declare(strict_types=1); namespace ForkBB\Models\BBCodeList; use ForkBB\Core\Container; use ForkBB\Models\Model; use RuntimeException; class BBCodeList extends Model { /** * Ключ модели для контейнера * @var string */ protected $cKey = 'BBCodeList'; public function __construct(string $file, Container $container) { parent::__construct($container); $this->fileDefault = "{$container->DIR_CONFIG}/{$file}"; $this->fileCache = "{$container->DIR_CACHE}/generated_bbcode.php"; } /** * Загружает массив сгенерированных bbcode */ public function init(): BBCodeList { if (! \is_file($this->fileCache)) { $this->generate(); } $this->list = include $this->fileCache; return $this; } /** * Очищает кеш сгенерированных bbcode */ public function reset(): BBCodeList { if (\is_file($this->fileCache)) { if (\unlink($this->fileCache)) { return $this->invalidate(); } else { throw new RuntimeException('The generated bbcode file cannot be deleted'); } } else { return $this; } } /** * Очищает opcache/apc от закэшированного файла */ public function invalidate(): BBCodeList { if (\function_exists('\\opcache_invalidate')) { \opcache_invalidate($this->fileCache, true); } elseif (\function_exists('\\apc_delete_file')) { \apc_delete_file($this->fileCache); } return $this; } }