From ec52b529bb5f363e1e16b38c9003758013b70909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Ste=CC=A8pien=CC=81?= Date: Sat, 6 Jan 2024 00:34:54 +0100 Subject: [PATCH] clear cache and hooks refactorization --- is_imageslider.php | 18 ++++++++++++++---- src/Cache/TemplateCache.php | 12 ++++++------ src/Hook/AbstractCacheableDisplayHook.php | 2 +- src/Hook/AbstractDisplayHook.php | 2 +- src/Hook/AbstractHook.php | 6 +++--- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/is_imageslider.php b/is_imageslider.php index dc9234d..80a4e46 100644 --- a/is_imageslider.php +++ b/is_imageslider.php @@ -8,6 +8,8 @@ if (file_exists(__DIR__ . '/vendor/autoload.php')) { require_once __DIR__ . '/vendor/autoload.php'; +} else { + throw new \Exception('You must run "composer install --no-dev" command in module directory'); } use Oksydan\IsImageslider\Hook\HookInterface; @@ -118,13 +120,21 @@ public function __call($methodName, array $arguments) if ($hook = $this->getHookObject($methodName)) { return $hook->execute(...$arguments); } - } elseif (method_exists($this, $methodName)) { - return $this->{$methodName}(...$arguments); } else { return null; } } + public function getCacheId($name = null) + { + return parent::getCacheId($name); + } + + public function _clearCache($template, $cache_id = null, $compile_id = null) + { + return parent::_clearCache($template, $cache_id, $compile_id); + } + /** * @param string $methodName * @@ -133,8 +143,8 @@ public function __call($methodName, array $arguments) private function getHookObject($methodName) { $serviceName = sprintf( - 'oksydan.is_imageslider.hook.%s', - \Tools::toUnderscoreCase(str_replace('hook', '', $methodName)) + 'Oksydan\IsImageslider\Hook\%s', + ucwords(str_replace('hook', '', $methodName)) ); $hook = $this->getService($serviceName); diff --git a/src/Cache/TemplateCache.php b/src/Cache/TemplateCache.php index 0520b03..b8d512a 100644 --- a/src/Cache/TemplateCache.php +++ b/src/Cache/TemplateCache.php @@ -12,30 +12,30 @@ class TemplateCache { - protected $module; - protected $context; + protected \Is_imageslider $module; + protected \Context $context; /** * @var HookModuleRepository */ - protected $hookModuleRepository; + protected HookModuleRepository $hookModuleRepository; /** * @var Configuration */ - protected $configuration; + protected Configuration $configuration; /** * @var ImageSliderRepository */ - protected $slideRepository; + protected ImageSliderRepository $slideRepository; public const IS_SLIDER_DATE_CACHE_KEY = 'IS_SLIDER_DATE_CACHE_KEY'; private const DATE_TIME_FORMAT = 'Y-m-d H:i:s'; public function __construct( - \Module $module, + \Is_imageslider $module, \Context $context, HookModuleRepository $hookModuleRepository, Configuration $configuration, diff --git a/src/Hook/AbstractCacheableDisplayHook.php b/src/Hook/AbstractCacheableDisplayHook.php index f680ebe..c6fdeab 100644 --- a/src/Hook/AbstractCacheableDisplayHook.php +++ b/src/Hook/AbstractCacheableDisplayHook.php @@ -27,7 +27,7 @@ abstract class AbstractCacheableDisplayHook extends AbstractDisplayHook protected $templateCache; public function __construct( - \Module $module, + \Is_imageslider $module, \Context $context, SliderConfiguration $sliderConfiguration, ImageSliderRepository $slideRepository, diff --git a/src/Hook/AbstractDisplayHook.php b/src/Hook/AbstractDisplayHook.php index dad81fa..c4bd1a8 100644 --- a/src/Hook/AbstractDisplayHook.php +++ b/src/Hook/AbstractDisplayHook.php @@ -11,7 +11,7 @@ abstract class AbstractDisplayHook extends AbstractHook protected $sliderConfiguration; public function __construct( - \Module $module, + \Is_imageslider $module, \Context $context, SliderConfiguration $sliderConfiguration ) { diff --git a/src/Hook/AbstractHook.php b/src/Hook/AbstractHook.php index 093bf76..ceaa486 100644 --- a/src/Hook/AbstractHook.php +++ b/src/Hook/AbstractHook.php @@ -6,10 +6,10 @@ abstract class AbstractHook implements HookInterface { - protected $module; - protected $context; + protected \Is_imageslider $module; + protected \Context $context; - public function __construct(\Module $module, \Context $context) + public function __construct(\Is_imageslider $module, \Context $context) { $this->module = $module; $this->context = $context;