Repository navigation
Expand file tree
/
Copy pathModule.php
More file actions
125 lines (114 loc) · 2.39 KB
/
Copy pathModule.php
File metadata and controls
125 lines (114 loc) · 2.39 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* @author : JIHAD SINNAOUR
* @package : FloatPHP
* @subpackage: Kernel Component
* @version : 1.0.0
* @category : PHP framework
* @copyright : (c) 2017 - 2021 JIHAD SINNAOUR <mail@jihadsinnaour.com>
* @link : https://www.floatphp.com
* @license : MIT License
*
* This file if a part of FloatPHP Framework
*/
namespace FloatPHP\Kernel;
use FloatPHP\Classes\Storage\Json;
class Module extends BaseController
{
/**
* @access protected
* string $dir modules directory
*/
protected static $dir;
/**
* @access private
* string $url Asset url
*/
private $url;
/**
* Load modules
* @param void
* @param void
*/
public function __construct()
{
self::$dir = $this->getModuleDir();
$this->autoload();
}
/**
* Autoload modules
* @param void
* @param array
*/
protected function getModuleDir()
{
return glob('App/Modules/*', 1073741824);
}
/**
* Autoload modules
* @param void
* @param void
*/
private function autoload()
{
// load module list
foreach ( self::$dir as $name )
{
$json = new Json("{$name}/module.json"); // module.json
$config = $json->parse();
var_dump($config);die();
$module = "\App\Modules\\{$config->namespace}\\{$config->namespace}Module";
new $module;
}
}
/**
* Set router
* @param void
* @param void
*/
public static function setRouter()
{
// load module router list
$wrapper = [];
if (self::$dir)
{
foreach ( self::$dir as $key => $name )
{
$json = new Json("{$name}/module"); // module.json
$config = $json->parse();
foreach ($config['router'] as $route) {
$wrapper[] = $route;
}
}
}
return $wrapper;
}
protected function addJS($url)
{
self::hook('action', 'add-js', function() use ($url) {
parent::render(['src' => $url],'system/script');
});
}
protected function addCSS($url)
{
self::hook('action', 'add-css', function() use ($url) {
parent::render(['href' => $url],'system/style');
});
}
/**
* Get view path
*
* @access protected
* @param string $template
* @return string
*/
protected function getPath($template)
{
// Set overriding path
$override = "{$this->getThemeDir()}/{$this->getNameSpace()}/";
if ( file_exists("{$override}{$template}{$this->getViewExtension()}") ) {
return $override;
}
return $this->getViewPath();
}
}