Skip to content

Commit

Permalink
clear cache and hooks refactorization
Browse files Browse the repository at this point in the history
  • Loading branch information
Oksydan committed Jan 5, 2024
1 parent 64df23b commit ec52b52
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
18 changes: 14 additions & 4 deletions is_imageslider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand All @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions src/Cache/TemplateCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/Hook/AbstractCacheableDisplayHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/Hook/AbstractDisplayHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ abstract class AbstractDisplayHook extends AbstractHook
protected $sliderConfiguration;

public function __construct(
\Module $module,
\Is_imageslider $module,
\Context $context,
SliderConfiguration $sliderConfiguration
) {
Expand Down
6 changes: 3 additions & 3 deletions src/Hook/AbstractHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ec52b52

Please sign in to comment.