@@ -53,7 +53,7 @@ public function handle()
53
53
}
54
54
55
55
// this is your Modules path.
56
- $ this ->appPath = base_path ("Modules / " . $ this ->appName );
56
+ $ this ->appPath = base_path ("modules / " . $ this ->appName );
57
57
58
58
59
59
if (file_exists ($ this ->appPath )) {
@@ -63,7 +63,10 @@ public function handle()
63
63
// make App Dir
64
64
(new Filesystem ())->ensureDirectoryExists ($ this ->appPath );
65
65
66
- // provider...
66
+ // module provider...
67
+ $ this ->createModuleProvider ();
68
+
69
+ // app provider...
67
70
$ this ->createProvider ();
68
71
69
72
// Routes..
@@ -87,17 +90,49 @@ public function handle()
87
90
88
91
$ this ->info ('** Everything is ready Build Something Amazing ** ' );
89
92
$ this ->alert (self ::ALERT_MESSAGE );
93
+ $ this ->info ('** test url: ' . 'http://127.0.0.1:8000/ ' . strtolower ($ this ->appName ) . '/test ' . ' ** ' );
94
+
90
95
$ bar ->finish ();
91
96
$ this ->newLine ();
92
97
}
93
98
99
+ private function createModuleProvider ()
100
+ {
101
+ $ moudleServiceProviderPath = base_path ("modules/ModulesProvider " );
102
+ $ moudleServiceProviderFile = $ moudleServiceProviderPath . '/ModuleServiceProvider.php ' ;
103
+
104
+ if (!file_exists ($ moudleServiceProviderFile )) {
105
+ (new Filesystem ())->ensureDirectoryExists ($ moudleServiceProviderPath );
106
+ (new Filesystem ())->copy (__DIR__ . '/../../stubs/ModulesProvider/ModuleServiceProvider.php ' ,
107
+ $ moudleServiceProviderFile );
108
+ (new Filesystem ())->replaceInFile ('Example ' , ucfirst ($ this ->appName ), $ moudleServiceProviderFile );
109
+ } else {
110
+ $ fileContent = (new Filesystem ())->get ($ moudleServiceProviderFile );
111
+
112
+ $ firsStrPosForNameSpace = strrpos ($ fileContent , 'use Modules\{ ' ) + strlen ('use Modules\{ ' );
113
+
114
+ $ appServiceProviderClassNameSpace = ucfirst ($ this ->appName ) . '\Provider \\' . ucfirst ($ this ->appName ) . 'Provider ' ;
115
+
116
+ $ newFileContent = substr ($ fileContent , 0 , $ firsStrPosForNameSpace ) . PHP_EOL . "\t" . $ appServiceProviderClassNameSpace . ', ' . "\t \t" . substr ($ fileContent , $ firsStrPosForNameSpace );
117
+
118
+ $ firsStrPosForRegisterApp = strpos ($ newFileContent , ' $this->app->register( ' );
119
+
120
+ $ appServiceProviderClass = $ this ->appName . 'Provider::class ' ;
121
+
122
+ $ newFileContent = substr ($ newFileContent , 0 , $ firsStrPosForRegisterApp ) . '$this->app->register( ' . $ appServiceProviderClass . '); ' . PHP_EOL . "\t \t" . substr ($ newFileContent , $ firsStrPosForRegisterApp );
123
+
124
+ (new Filesystem ())->put ($ moudleServiceProviderFile , $ newFileContent );
125
+ }
126
+ }
127
+
94
128
private function createProvider ()
95
129
{
96
130
(new Filesystem ())->ensureDirectoryExists ($ this ->appPath . '/Provider ' );
97
131
(new Filesystem ())->copy (__DIR__ . '/../../stubs/app/Provider/ExampleProvider.php ' ,
98
- $ this ->appPath . '/Provider/ ' . ucfirst ($ this ->appName ) . 'Provider.php ' );
99
- (new Filesystem ())->replaceInFile ('Example ' , ucfirst ($ this ->appName ), $ this ->appPath . '/Provider/ ' . ucfirst ($ this ->appName ) . 'Provider.php ' );
100
- (new Filesystem ())->replaceInFile ('AppPath ' , 'Modules/ ' . ucfirst ($ this ->appName ), $ this ->appPath . '/Provider/ ' . ucfirst ($ this ->appName ) . 'Provider.php ' );
132
+ $ this ->appPath . '/Provider/ ' . ucfirst ($ this ->appName ) . 'Provider.php ' );
133
+ (new Filesystem ())->replaceInFile ('Example ' , ucfirst ($ this ->appName ), $ this ->appPath . '/Provider/ ' . ucfirst ($ this ->appName ) . 'Provider.php ' );
134
+ (new Filesystem ())->replaceInFile ('ROUTE-NAME ' , strtolower ($ this ->appName ), $ this ->appPath . '/Provider/ ' . ucfirst ($ this ->appName ) . 'Provider.php ' );
135
+ (new Filesystem ())->replaceInFile ('AppPath ' , 'Modules/ ' . ucfirst ($ this ->appName ), $ this ->appPath . '/Provider/ ' . ucfirst ($ this ->appName ) . 'Provider.php ' );
101
136
}
102
137
103
138
private function createRoute ()
0 commit comments