-
Notifications
You must be signed in to change notification settings - Fork 3
/
is_favoriteproducts.php
107 lines (90 loc) · 2.75 KB
/
is_favoriteproducts.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
<?php
declare(strict_types=1);
if (!defined('_PS_VERSION_')) {
exit;
}
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\IsFavoriteProducts\Hook\HookInterface;
use Oksydan\IsFavoriteProducts\Installer\ModuleInstaller;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
class Is_favoriteproducts extends Module
{
public $multistoreCompatibility = self::MULTISTORE_COMPATIBILITY_YES;
public function __construct()
{
$this->name = 'is_favoriteproducts';
$this->author = 'Igor Stępień';
$this->version = '1.0.1';
$this->need_instance = 0;
$this->controllers = ['favorite'];
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->trans('Favorite products module', [], 'Modules.Isfavoriteproducts.Admin');
$this->description = $this->trans('Falcon theme favorite products module', [], 'Modules.Isfavoriteproducts.Admin');
$this->ps_versions_compliancy = ['min' => '8.0.0', 'max' => _PS_VERSION_];
}
public function isUsingNewTranslationSystem(): bool
{
return true;
}
private function getModuleInstaller(): ModuleInstaller
{
return new ModuleInstaller($this);
}
/**
* @return bool
*/
public function install(): bool
{
return parent::install() && $this->getModuleInstaller()->install();
}
/**
* @return bool
*/
public function uninstall(): bool
{
return parent::uninstall() && $this->getModuleInstaller()->uninstall();
}
/**
* @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;
}
}
/** @param string $methodName */
public function __call($methodName, array $arguments)
{
if (str_starts_with($methodName, 'hook') && $hook = $this->getHookObject($methodName)) {
return $hook->execute(...$arguments);
} else {
return null;
}
}
/**
* @param string $methodName
*
* @return HookInterface|null
*/
private function getHookObject($methodName)
{
$serviceName = sprintf(
'Oksydan\IsFavoriteProducts\Hook\%s',
ucwords(str_replace('hook', '', $methodName))
);
$hook = $this->getService($serviceName);
return $hook instanceof HookInterface ? $hook : null;
}
}