-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModules.php
121 lines (103 loc) · 2.48 KB
/
Modules.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
class Modules
{
protected $f3;
protected $module;
private static $path;
public function __construct($module = null)
{
$this->f3 = Base::instance();
$this->module = $module?:$this->name;
}
public function loadConfigFrom($pathOrFile, $global = false)
{
if(is_dir($pathOrFile)) {
foreach(glob($pathOrFile.'/*') as $file) {
if(extension($file) === 'php') {
$conf = include($file);
$this->f3->mset($global?[$this->module => $conf]:$conf);
}else if(extension($file) === 'ini') {
$this->f3->config($file);
}
}
}else if(is_file($pathOrFile)) {
if(extension($pathOrFile) === 'php') {
$conf = include($pathOrFile);
$this->f3->mset($global?[$this->module => $conf]:$conf);
}else if(extension($pathOrFile) === 'ini') {
$this->f3->config($pathOrFile);
}
}
}
public function loadRoutesFrom($pathOrFile)
{
$app = $this->f3;
if(is_dir($pathOrFile)) {
foreach(glob($pathOrFile.'/*') as $file) {
if(extension($file) === 'php') {
include($file);
}else if(extension($file) === 'ini') {
$this->f3->config($file);
}
}
}else if(is_file($pathOrFile)) {
if(extension($pathOrFile) === 'php') {
include($pathOrFile);
}else if(extension($pathOrFile) === 'ini') {
$this->f3->config($pathOrFile);
}
}
}
public function loadResources($path)
{
if(is_dir($path.'/lang')){
$this->loadLangFrom($path.'/lang');
}
if(is_dir($path.'/views')){
$this->loadViewsFrom($path.'/views');
}
if(is_dir($path.'/assets')){
$this->loadAssetsFrom($path.'/assets');
}
}
public function loadViewsFrom($path)
{
$this->f3->set('UI', $this->f3->get('UI').';'.$path.'/');
}
public function loadAssetsFrom($path)
{}
public function loadLangFrom($path)
{
$this->f3->set('LOCALES', $this->f3->get('LOCALES').';'.$path.'/');
}
public function middlewares($class)
{
if(is_array($class)) {
}else{
}
}
//abstract public function init();
static public function run()
{
self::$path = $path = root_path('modules').'/';
spl_autoload_register(array(
__CLASS__,
'autoload',
));
foreach(glob($path.'*') as $module) {
$file = $module.'/Module.php';
if(file_exists($file)) {
require $file;
$class = ucfirst(str_ireplace($path, '', $module)).'\Module';
if(class_exists($class)) {
(new $class())->init();
}
}
}
}
static public function autoload($class)
{
$file = self::$path . str_replace('\\', '/', $class) . '.php';
if(file_exists($file)) { require $file; }
}
}