1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: namespace Xmf\Module;
13:
14: use Xmf\Module\Helper\GenericHelper;
15:
16: /**
17: * Helper gets an instance of module helper for the specified module.
18: * The helper is defined by the Xoops 2.6 Xoops\Module\Helper\HelperAbstract
19: * and in pre 2.6 systems we mimic that definition with using an
20: * instance of Xmf\Module\GenericHelper.
21: *
22: * @category Xmf\Module\Helper
23: * @package Xmf
24: * @author trabis <lusopoemas@gmail.com>
25: * @author Richard Griffith <richard@geekwright.com>
26: * @copyright 2011-2023 XOOPS Project (https://xoops.org)
27: * @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
28: * @link https://xoops.org
29: */
30: class Helper extends GenericHelper
31: {
32: /**
33: * Get an instance of a module helper for the module identified by $dirname
34: *
35: * @param string $dirname module directory
36: *
37: * @return \Xmf\Module\Helper|\Xoops\Module\Helper|false a Helper object of false on error
38: */
39: public static function getHelper($dirname = 'system')
40: {
41: static $instance = array();
42:
43: if (!isset($instance[$dirname])) {
44: $instance[$dirname] = false;
45:
46: // if this is a 2.6 system turn everything over to the core
47: if (class_exists('Xoops', false)) {
48: $instance[$dirname] = \Xoops\Module\Helper::getHelper($dirname);
49: } else {
50: // otherwise, get a GenericHelper instance for dirname
51: if (xoops_isActiveModule($dirname)) {
52: $instance[$dirname] = new static($dirname);
53: }
54: }
55: }
56:
57: return $instance[$dirname];
58: }
59: }
60: