/
ZincModule.php
121 lines (103 loc) · 2.51 KB
/
ZincModule.php
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
112
113
114
115
116
117
118
119
120
121
<?php
abstract class ZincModule
{
private $name, $lib;
private $depends = array(), $includes = array(), $classes = array();
protected $hasConfig = false;
public $path;
final function __construct($path, $lib)
{
// assign in the paramamters
$this->path = $path;
$this->lib = $lib;
$this->name = strtolower(str_replace('Module', '', get_class($this)));
// second stage (module specific) construction
$this->init();
$classname = get_class($this);
// load any dependant modules
if($this->getDepends())
foreach($this->getDepends() as $thisDepends)
$this->lib->loadMod($thisDepends);
// include any normal files that need to be included
if($this->getIncludes())
{
foreach($this->getIncludes() as $thisInclude)
{
if($thisInclude[0] == '/')
require($thisInclude);
else
require($this->path . '/' . $thisInclude);
}
}
// register any class files
if($classes = $this->getClasses())
foreach($classes as $thisClass)
ZoopLoader::addClass($thisClass, $this->path . '/' . $thisClass . '.php');
if($this->hasConfig)
$this->loadConfig();
// handle configuration
$this->configure();
}
protected function init() {}
protected function configure() {}
/**
* Figures out the name of the module by removing the word "Module" from
* the class name and returning the result
*
* @return string
*/
function createName()
{
return strtolower(str_replace('Module', '', get_class($this)));
}
function getConfigPath()
{
return $this->name;
}
private function loadConfig()
{
Config::suggest($this->path . '/' . 'config.yaml', 'zinc.' . $this->getConfigPath());
}
/**
* Returns the configuration options using the Config class.
* Returns config options from "zinc.<modulename>.<path>"
* Path is optional and may be omitted.
*
* @param string $path
* @return array of configuration options
*/
function getConfig($path = '')
{
$config = Config::get('zinc.' . $this->getConfigPath() . $path);
return $config;
}
/**
* stuff about this function
*
* @return array(list of files to include) or false;
*/
protected function addClass($className)
{
$this->classes[] = $className;
}
protected function getClasses()
{
return $this->classes;
}
protected function addInclude($include)
{
$this->includes[] = $include;
}
protected function getIncludes()
{
return $this->includes;
}
protected function depend($module)
{
$this->depends[] = $module;
}
private function getDepends()
{
return $this->depends;
}
}