AbstractModule.php
2.6 KB
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
108
109
110
111
<?php
/**
* @package AllediaFramework
* @contact www.alledia.com, hello@alledia.com
* @copyright 2016 Alledia.com, All rights reserved
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/
namespace Alledia\Framework\Joomla\Extension;
defined('_JEXEC') or die();
use Alledia\Framework\Factory;
use Joomla\Registry\Registry;
use JModuleHelper;
/**
* @deprecated 1.4.1 Use AbstractFlexibleModule instead. This module doesn't
* work with multiple modules in the same page because of the Singleton pattern.
*
*/
abstract class AbstractModule extends Licensed
{
// @TODO: convert to protected and remove from the subclasses?
private static $instance;
public $id;
public $title;
public $module;
public $position;
public $content;
public $showtitle;
public $params;
public $menuid;
public $name;
public $style;
/**
* Class constructor that instantiate the free and pro library, if installed
*/
public function __construct($namespace)
{
parent::__construct($namespace, 'module');
$this->loadLibrary();
}
/**
* Returns the instance of child classes
*
* @param string $namespace
* @param object $module
*
* @return Object
*/
public static function getInstance($namespace = null, $module = null)
{
if (empty(static::$instance)) {
$instance = new static($namespace);
if (is_object($module)) {
$instance->id = $module->id;
$instance->title = $module->title;
$instance->module = $module->module;
$instance->position = $module->position;
$instance->content = $module->content;
$instance->showtitle = $module->showtitle;
$instance->menuid = $module->menuid;
$instance->name = $module->name;
$instance->style = $module->style;
$instance->params = new Registry($module->params);
} else {
// @TODO: Raise warning/Error
}
$instance->loadLanguage();
static::$instance = $instance;
}
return static::$instance;
}
public function init()
{
require JModuleHelper::getLayoutPath('mod_' . $this->element, $this->params->get('layout', 'default'));
}
/**
* Method to load the language files
*
* @return void
*/
public function loadLanguage()
{
$language = Factory::getLanguage();
$language->load($this->module, JPATH_SITE);
}
}