| | |
| | | <?php |
| | | namespace JVBase\blocks; |
| | | |
| | | use JVBase\managers\CacheManager; |
| | | use JVBase\managers\Cache; |
| | | use JVBase\forms\TaxonomySelector; |
| | | use WP_Block; |
| | | |
| | |
| | | |
| | | class SummaryBlock |
| | | { |
| | | protected CacheManager $cache; |
| | | protected Cache $cache; |
| | | protected string $config; |
| | | protected string $type; |
| | | protected string $path = JVB_DIR . '/build/summary'; |
| | |
| | | |
| | | public function __construct() |
| | | { |
| | | $this->cache = CacheManager::for('summary_block', WEEK_IN_SECONDS); |
| | | $this->cache = Cache::for('summary_block', WEEK_IN_SECONDS); |
| | | add_action('init', [ $this, 'registerBlock' ]); |
| | | if (JVB_TESTING) { |
| | | $this->cache->flush(); |
| | | } |
| | | } |
| | | |
| | | public function registerBlock() |
| | |
| | | $this->config = $this->getConfig(); |
| | | $key = $this->generateKey(); |
| | | $cache = $this->cache->get($key); |
| | | $cache = false; |
| | | |
| | | if ($cache) { |
| | | return $cache; |
| | | } |
| | |
| | | if (empty($this->type)) { |
| | | $this->type = match (true) { |
| | | is_tax() => jvbNoBase(get_queried_object()->taxonomy), |
| | | is_post_type_archive() => jvbNoBase(get_post_type()), |
| | | is_post_type_archive() => jvbNoBase(get_queried_object()->name), |
| | | default => jvbNoBase(get_queried_object()->post_type), |
| | | }; |
| | | } |