Passed
Push — master ( 81ba93...c6c854 )
by Michael
03:30
created

class/Helper.php (1 issue)

Severity
1
<?php
2
3
namespace XoopsModules\Smartfaq;
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
/**
16
 * @copyright    XOOPS Project https://xoops.org/
17
 * @license      GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
18
 * @package
19
 * @since
20
 * @author       XOOPS Development Team
21
 */
22
23
//defined('XOOPS_ROOT_PATH') || die('Restricted access');
24
25
/**
26
 * Class Helper
27
 */
28
class Helper extends \Xmf\Module\Helper
29
{
30
    public $debug;
31
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\Smartfaq\Helper
46
     */
47
    public static function getInstance($debug = false)
48
    {
49
        static $instance;
50
        if (null === $instance) {
51
            $instance = new static($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;
0 ignored issues
show
The assignment to $ret is dead and can be removed.
Loading history...
75
76
        $class = '\\XoopsModules\\' . ucfirst(mb_strtolower(basename(dirname(__DIR__)))) . '\\' . $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
        return $ret;
86
    }
87
}
88