1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Moduleinstaller; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* You may not change or alter any portion of this comment or credits |
7
|
|
|
* of supporting developers from this source code or any supporting source code |
8
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
9
|
|
|
* |
10
|
|
|
* This program is distributed in the hope that it will be useful, |
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
use RuntimeException; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
19
|
|
|
* @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
20
|
|
|
* @author XOOPS Development Team |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class Helper |
25
|
|
|
*/ |
26
|
|
|
class Helper extends \Xmf\Module\Helper |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var bool |
30
|
|
|
*/ |
31
|
|
|
public $debug = false; |
32
|
|
|
/** |
33
|
|
|
* @param bool $debug |
34
|
|
|
*/ |
35
|
|
|
public function __construct($debug = false) |
36
|
|
|
{ |
37
|
|
|
$this->debug = $debug; |
38
|
|
|
$moduleDirName = \basename(\dirname(__DIR__)); |
39
|
|
|
parent::__construct($moduleDirName); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param bool $debug |
44
|
|
|
* |
45
|
|
|
* @return \XoopsModules\Moduleinstaller\Helper |
46
|
|
|
*/ |
47
|
|
|
public static function getInstance(bool $debug = false): self |
48
|
|
|
{ |
49
|
|
|
static $instance; |
50
|
|
|
if (null === $instance) { |
51
|
|
|
$instance = new self($debug); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $instance; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
public function getDirname() |
61
|
|
|
{ |
62
|
|
|
return $this->dirname; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get an Object Handler |
67
|
|
|
* |
68
|
|
|
* @param string $name name of handler to load |
69
|
|
|
* |
70
|
|
|
* @return bool|\XoopsObjectHandler|\XoopsPersistableObjectHandler |
71
|
|
|
*/ |
72
|
|
|
public function getHandler($name) |
73
|
|
|
{ |
74
|
|
|
$ret = false; |
|
|
|
|
75
|
|
|
|
76
|
|
|
$class = __NAMESPACE__ . '\\' . \ucfirst($name) . 'Handler'; |
77
|
|
|
if (!\class_exists($class)) { |
78
|
|
|
throw new RuntimeException("Class '$class' not found"); |
79
|
|
|
} |
80
|
|
|
/** @var \XoopsMySQLDatabase $db */ |
81
|
|
|
$db = \XoopsDatabaseFactory::getDatabaseConnection(); |
82
|
|
|
$helper = self::getInstance(); |
83
|
|
|
$ret = new $class($db, $helper); |
84
|
|
|
$this->addLog("Getting handler '$name'"); |
85
|
|
|
|
86
|
|
|
return $ret; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|