-
Notifications
You must be signed in to change notification settings - Fork 14
/
is_imageslider.php
158 lines (133 loc) · 4.27 KB
/
is_imageslider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
declare(strict_types=1);
if (!defined('_PS_VERSION_')) {
exit;
}
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
require_once __DIR__ . '/vendor/autoload.php';
}
use Oksydan\IsImageslider\Hook\HookInterface;
use Oksydan\IsImageslider\Installer\ImageSliderInstaller;
use PrestaShop\PrestaShop\Adapter\SymfonyContainer;
use PrestaShop\PrestaShop\Core\Module\WidgetInterface;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
class Is_imageslider extends Module implements WidgetInterface
{
public $multistoreCompatibility = self::MULTISTORE_COMPATIBILITY_YES;
public function __construct()
{
$this->name = 'is_imageslider';
/*
* SPECIAL THANKS TO WAYNET TEAM
* YOU ARE HUGE INSPIRATION TO ME
* https://www.waynet.pl/
*/
$this->author = 'Igor Stępień';
$this->version = '2.3.2';
$this->need_instance = 0;
$this->bootstrap = true;
parent::__construct();
$this->displayName = 'Home slider module';
$this->description = 'Home slider module';
$this->ps_versions_compliancy = ['min' => '8.0.0', 'max' => _PS_VERSION_];
}
public function isUsingNewTranslationSystem(): bool
{
return true;
}
/**
* @return bool
*/
public function install(): bool
{
return
parent::install()
&& $this->registerHook('displayHeader')
&& $this->registerHook('displayHome')
&& $this->getInstaller()->createTables();
}
/**
* @return bool
*/
public function uninstall(): bool
{
return $this->getInstaller()->dropTables() && parent::uninstall();
}
public function getContent(): void
{
\Tools::redirectAdmin(SymfonyContainer::getInstance()->get('router')->generate('is_imageslider_controller'));
}
/**
* @template T
*
* @param class-string<T>|string $serviceName
*
* @return T|object|null
*/
public function getService($serviceName)
{
try {
return $this->get($serviceName);
} catch (ServiceNotFoundException $exception) {
return null;
}
}
/**
* @return ImageSliderInstaller
*/
private function getInstaller(): ImageSliderInstaller
{
try {
$installer = $this->getService('oksydan.is_imageslider.image_slider_installer');
} catch (Error $error) {
$installer = null;
}
if (null === $installer) {
$installer = new Oksydan\IsImageslider\Installer\ImageSliderInstaller(
$this->getService('doctrine.dbal.default_connection'),
new Oksydan\IsImageslider\Installer\DatabaseYamlParser(
new Oksydan\IsImageslider\Installer\Provider\DatabaseYamlProvider($this)
),
$this->context
);
}
return $installer;
}
/** @param string $methodName */
public function __call($methodName, array $arguments)
{
if (str_starts_with($methodName, 'hook')) {
if ($hook = $this->getHookObject($methodName)) {
return $hook->execute(...$arguments);
}
} elseif (method_exists($this, $methodName)) {
return $this->{$methodName}(...$arguments);
} else {
return null;
}
}
/**
* @param string $methodName
*
* @return HookInterface|null
*/
private function getHookObject($methodName)
{
$serviceName = sprintf(
'oksydan.is_imageslider.hook.%s',
\Tools::toUnderscoreCase(str_replace('hook', '', $methodName))
);
$hook = $this->getService($serviceName);
return $hook instanceof HookInterface ? $hook : null;
}
public function renderWidget($hookName, array $configuration)
{
$widgetCapability = $this->get('oksydan.is_imageslider.hook.widget_capability');
return $widgetCapability->renderWidget($configuration);
}
public function getWidgetVariables($hookName, array $configuration)
{
$widgetCapability = $this->get('oksydan.is_imageslider.hook.widget_capability');
return $widgetCapability->getWidgetVariables($configuration);
}
}