3
3
namespace Pravodev \Laramoud \Providers ;
4
4
5
5
use Illuminate \Support \ServiceProvider ;
6
- use Pravodev \Laramoud \Utils \Cache ;
7
6
use Pravodev \Laramoud \Contracts \Resource ;
7
+ use Pravodev \Laramoud \Utils \Cache ;
8
8
9
9
abstract class ModuleServiceProvider extends ServiceProvider
10
10
{
11
11
use Resource;
12
-
12
+
13
13
protected $ cache ;
14
-
14
+
15
15
public function __construct ($ app )
16
16
{
17
17
parent ::__construct ($ app );
18
18
19
- $ this ->cache = new Cache ;
19
+ $ this ->cache = new Cache () ;
20
20
}
21
-
22
- public function boot (){}
23
21
24
- public function register (){}
22
+ public function boot ()
23
+ {
24
+ }
25
+
26
+ public function register ()
27
+ {
28
+ }
25
29
26
-
27
- /**
28
- *
29
- */
30
30
public function isAutoloadNamespaces ()
31
31
{
32
32
return $ this ->getConfig ('spl_autoload ' );
33
33
}
34
34
35
-
36
35
/**
37
- *
38
- *
39
36
* @return void
40
37
*/
41
38
public function autoloadNamespaces ()
42
39
{
43
40
$ module_path = $ this ->getConfig ('module_path ' );
44
-
45
- spl_autoload_register (function ($ className )use ($ module_path ){
46
- include_once $ module_path . '/ ' . $ className . '.php ' ;
41
+
42
+ spl_autoload_register (function ($ className ) use ($ module_path ) {
43
+ include_once $ module_path. '/ ' . $ className. '.php ' ;
47
44
});
48
45
}
49
46
50
47
/**
51
- * Load View Routes Migration & OBservers of Module
52
- *
48
+ * Load View Routes Migration & OBservers of Module.
49
+ *
53
50
* @return void
54
51
*/
55
52
public function loadModules ()
56
53
{
57
- foreach ($ this ->getListOfModules () as $ module ){
54
+ foreach ($ this ->getListOfModules () as $ module ) {
58
55
$ this ->loadViews ($ module );
59
56
$ this ->loadRoutes ($ module );
60
57
$ this ->loadMigrations ($ module );
@@ -63,24 +60,26 @@ public function loadModules()
63
60
}
64
61
65
62
/**
66
- * List Directory Modules
67
- *
63
+ * List Directory Modules.
64
+ *
68
65
* @return array
69
66
*/
70
67
public function getListOfModules ()
71
68
{
72
- if ($ modules = $ this ->cache ->get ('laramoud ' , 'modules ' )){
69
+ if ($ modules = $ this ->cache ->get ('laramoud ' , 'modules ' )) {
73
70
return $ modules ;
74
71
}
75
72
76
73
$ module_path = $ this ->getModulePath ();
77
-
78
- if (file_exists ($ module_path ) == false ) return [];
74
+
75
+ if (file_exists ($ module_path ) == false ) {
76
+ return [];
77
+ }
79
78
80
79
$ modules = array_values (
81
80
array_diff (
82
81
scandir ($ this ->getModulePath (), 1 ),
83
- array ( '.. ' , '. ' )
82
+ [ '.. ' , '. ' ]
84
83
)
85
84
);
86
85
@@ -89,43 +88,44 @@ public function getListOfModules()
89
88
return $ modules ;
90
89
}
91
90
92
- public function getModulePath ($ name = "" )
91
+ public function getModulePath ($ name = '' )
93
92
{
94
- if ($ config = $ this ->getConfig ('module_path ' , 'composer ' )){
95
- return base_path ($ config . $ name );
93
+ if ($ config = $ this ->getConfig ('module_path ' , 'composer ' )) {
94
+ return base_path ($ config. $ name );
96
95
}
97
-
98
- return base_path (" modules/ " . $ name );
96
+
97
+ return base_path (' modules/ ' . $ name );
99
98
}
100
-
99
+
101
100
/**
102
- * Get Laramoud Config
103
- *
101
+ * Get Laramoud Config.
102
+ *
104
103
* @return any
105
104
*/
106
105
public function getConfig ($ key = null , $ source = null )
107
106
{
108
- if ($ source == 'composer ' ){
107
+ if ($ source == 'composer ' ) {
109
108
$ config = $ this ->getComposer ();
109
+
110
110
return $ config ['extra ' ]['laramoud ' ][$ key ] ?? null ;
111
111
}
112
-
113
- if (empty ($ key )){
112
+
113
+ if (empty ($ key )) {
114
114
return config ('laramoud ' );
115
115
}
116
116
117
- return config ('laramoud. ' . $ key );
117
+ return config ('laramoud. ' . $ key );
118
118
}
119
119
120
120
public function getComposer ()
121
121
{
122
-
123
- if ($ composer = $ this ->cache ->get ('composer ' )){
122
+ if ($ composer = $ this ->cache ->get ('composer ' )) {
124
123
return $ composer ;
125
124
}
126
125
// dd(as);
127
126
$ composer = json_decode (file_get_contents (base_path ('composer.json ' )), true );
128
127
$ this ->cache ->set ('composer ' , $ composer );
128
+
129
129
return $ composer ;
130
130
}
131
- }
131
+ }
0 commit comments