|
1
|
|
|
<?php namespace XoopsModules\Pedigree; |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* You may not change or alter any portion of this comment or credits |
|
5
|
|
|
* of supporting developers from this source code or any supporting source code |
|
6
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
|
7
|
|
|
* |
|
8
|
|
|
* This program is distributed in the hope that it will be useful, |
|
9
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @copyright XOOPS Project https://xoops.org/ |
|
15
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
|
16
|
|
|
* @package |
|
17
|
|
|
* @since |
|
18
|
|
|
* @author XOOPS Development Team |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class Helper |
|
25
|
|
|
*/ |
|
26
|
|
|
class Helper extends \Xmf\Module\Helper |
|
27
|
|
|
{ |
|
28
|
|
|
public $debug; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* |
|
32
|
|
|
* @param bool $debug |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct($debug = false) |
|
35
|
|
|
{ |
|
36
|
|
|
if (null === $dirname) { |
|
|
|
|
|
|
37
|
|
|
$dirname = basename(dirname(__DIR__)); |
|
38
|
|
|
$this->dirname = $dirname; |
|
39
|
|
|
} |
|
40
|
|
|
parent::__construct($moduleDirName); |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param bool $debug |
|
45
|
|
|
* |
|
46
|
|
|
* @return \XoopsModules\Pedigree\Helper |
|
47
|
|
|
*/ |
|
48
|
|
|
public static function getInstance($debug = false) |
|
49
|
|
|
{ |
|
50
|
|
|
static $instance; |
|
51
|
|
|
if (null === $instance) { |
|
52
|
|
|
$instance = new static($debug); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return $instance; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return string |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getDirname() |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->dirname; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Get an Object Handler |
|
68
|
|
|
* |
|
69
|
|
|
* @param string $name name of handler to load |
|
70
|
|
|
* |
|
71
|
|
|
* @return bool|\XoopsObjectHandler|\XoopsPersistableObjectHandler |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getHandler($name) |
|
74
|
|
|
{ |
|
75
|
|
|
$ret = false; |
|
|
|
|
|
|
76
|
|
|
$db = \XoopsDatabaseFactory::getDatabaseConnection(); |
|
77
|
|
|
$class = __NAMESPACE__ . '\\' . ucfirst($name) . 'Handler'; |
|
78
|
|
|
return new $class($db); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.