From 26e3046328119ace6c6b7e7b02e11d4f13f545aa Mon Sep 17 00:00:00 2001 From: Solomon Ochepa Date: Sat, 31 Aug 2024 23:34:02 +0100 Subject: [PATCH] [test] Update test snapshots --- ...nable_and_route_provider_is_disable__1.txt | 46 ++++++++++--------- ...enable_and_route_provider_is_enable__1.txt | 46 ++++++++++--------- ...generates_api_module_with_resources__1.txt | 46 ++++++++++--------- ..._module_namespace_using_studly_case__1.txt | 41 ++++++++++------- ..._test_it_generates_module_resources__1.txt | 46 ++++++++++--------- ...generates_web_module_with_resources__1.txt | 46 ++++++++++--------- ...es_when_adding_more_than_one_option__1.txt | 46 ++++++++++--------- ...it_can_change_the_default_namespace__1.txt | 46 ++++++++++--------- ...ange_the_default_namespace_specific__1.txt | 46 ++++++++++--------- ..._migration_resources_location_paths__1.txt | 46 ++++++++++--------- ...vice_provider_with_resource_loading__1.txt | 46 ++++++++++--------- 11 files changed, 264 insertions(+), 237 deletions(-) diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_disable__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_disable__1.txt index cd8b623df..2731da8ee 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_disable__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_disable__1.txt @@ -4,15 +4,16 @@ namespace Modules\Blog\Providers; use Illuminate\Support\Facades\Blade; use Illuminate\Support\ServiceProvider; +use Illuminate\Support\Str; use Nwidart\Modules\Traits\PathNamespace; class BlogServiceProvider extends ServiceProvider { use PathNamespace; - protected string $moduleName = 'Blog'; + protected string $name = 'Blog'; - protected string $moduleNameLower = 'blog'; + protected string $name_lower = 'blog'; /** * Boot the application events. @@ -24,7 +25,7 @@ class BlogServiceProvider extends ServiceProvider $this->registerTranslations(); $this->registerConfig(); $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations')); + $this->loadMigrationsFrom(module_path($this->name, 'database/migrations')); } /** @@ -60,14 +61,14 @@ class BlogServiceProvider extends ServiceProvider */ public function registerTranslations(): void { - $langPath = resource_path('lang/modules/'.$this->moduleNameLower); + $langPath = resource_path('lang/modules/'.$this->name_lower); if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); + $this->loadTranslationsFrom($langPath, $this->name_lower); $this->loadJsonTranslationsFrom($langPath); } else { - $this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower); - $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang')); + $this->loadTranslationsFrom(module_path($this->name, 'lang'), $this->name_lower); + $this->loadJsonTranslationsFrom(module_path($this->name, 'lang')); } } @@ -76,8 +77,14 @@ class BlogServiceProvider extends ServiceProvider */ protected function registerConfig(): void { - $this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config'); - $this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower); + $configs = glob(module_path($this->name, 'config/*.php')); + foreach ($configs as $config) { + $filename = Str::of($config)->after(module_path($this->name, 'config/'))->remove('.php')->toString(); + $name = ($filename == 'config') ? $this->name_lower : $filename; // could be removed if the config file is named after the module [modules/Blog => config/blog.php]. + + $this->publishes([module_path($this->name, "config/{$filename}.php") => config_path($name . '.php')], 'config'); + $this->mergeConfigFrom(module_path($this->name, "config/{$filename}.php"), $name); + } } /** @@ -85,36 +92,31 @@ class BlogServiceProvider extends ServiceProvider */ public function registerViews(): void { - $viewPath = resource_path('views/modules/'.$this->moduleNameLower); - $sourcePath = module_path($this->moduleName, 'resources/views'); + $viewPath = resource_path('views/modules/'.$this->name_lower); + $sourcePath = module_path($this->name, 'resources/views'); - $this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']); + $this->publishes([$sourcePath => $viewPath], ['views', $this->name_lower.'-module-views']); - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->name_lower); - $componentNamespace = $this->module_namespace($this->moduleName, $this->app_path(config('modules.paths.generator.component-class.path'))); - Blade::componentNamespace($componentNamespace, $this->moduleNameLower); + $componentNamespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($componentNamespace, $this->name_lower); } /** * Get the services provided by the provider. - * - * @return array */ public function provides(): array { return []; } - /** - * @return array - */ private function getPublishableViewPaths(): array { $paths = []; foreach (config('view.paths') as $path) { - if (is_dir($path.'/modules/'.$this->moduleNameLower)) { - $paths[] = $path.'/modules/'.$this->moduleNameLower; + if (is_dir($path.'/modules/'.$this->name_lower)) { + $paths[] = $path.'/modules/'.$this->name_lower; } } diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_enable__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_enable__1.txt index 62bd6a496..4e6f62557 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_enable__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_enable__1.txt @@ -4,15 +4,16 @@ namespace Modules\Blog\Providers; use Illuminate\Support\Facades\Blade; use Illuminate\Support\ServiceProvider; +use Illuminate\Support\Str; use Nwidart\Modules\Traits\PathNamespace; class BlogServiceProvider extends ServiceProvider { use PathNamespace; - protected string $moduleName = 'Blog'; + protected string $name = 'Blog'; - protected string $moduleNameLower = 'blog'; + protected string $name_lower = 'blog'; /** * Boot the application events. @@ -24,7 +25,7 @@ class BlogServiceProvider extends ServiceProvider $this->registerTranslations(); $this->registerConfig(); $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations')); + $this->loadMigrationsFrom(module_path($this->name, 'database/migrations')); } /** @@ -60,14 +61,14 @@ class BlogServiceProvider extends ServiceProvider */ public function registerTranslations(): void { - $langPath = resource_path('lang/modules/'.$this->moduleNameLower); + $langPath = resource_path('lang/modules/'.$this->name_lower); if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); + $this->loadTranslationsFrom($langPath, $this->name_lower); $this->loadJsonTranslationsFrom($langPath); } else { - $this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower); - $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang')); + $this->loadTranslationsFrom(module_path($this->name, 'lang'), $this->name_lower); + $this->loadJsonTranslationsFrom(module_path($this->name, 'lang')); } } @@ -76,8 +77,14 @@ class BlogServiceProvider extends ServiceProvider */ protected function registerConfig(): void { - $this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config'); - $this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower); + $configs = glob(module_path($this->name, 'config/*.php')); + foreach ($configs as $config) { + $filename = Str::of($config)->after(module_path($this->name, 'config/'))->remove('.php')->toString(); + $name = ($filename == 'config') ? $this->name_lower : $filename; // could be removed if the config file is named after the module [modules/Blog => config/blog.php]. + + $this->publishes([module_path($this->name, "config/{$filename}.php") => config_path($name . '.php')], 'config'); + $this->mergeConfigFrom(module_path($this->name, "config/{$filename}.php"), $name); + } } /** @@ -85,36 +92,31 @@ class BlogServiceProvider extends ServiceProvider */ public function registerViews(): void { - $viewPath = resource_path('views/modules/'.$this->moduleNameLower); - $sourcePath = module_path($this->moduleName, 'resources/views'); + $viewPath = resource_path('views/modules/'.$this->name_lower); + $sourcePath = module_path($this->name, 'resources/views'); - $this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']); + $this->publishes([$sourcePath => $viewPath], ['views', $this->name_lower.'-module-views']); - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->name_lower); - $componentNamespace = $this->module_namespace($this->moduleName, $this->app_path(config('modules.paths.generator.component-class.path'))); - Blade::componentNamespace($componentNamespace, $this->moduleNameLower); + $componentNamespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($componentNamespace, $this->name_lower); } /** * Get the services provided by the provider. - * - * @return array */ public function provides(): array { return []; } - /** - * @return array - */ private function getPublishableViewPaths(): array { $paths = []; foreach (config('view.paths') as $path) { - if (is_dir($path.'/modules/'.$this->moduleNameLower)) { - $paths[] = $path.'/modules/'.$this->moduleNameLower; + if (is_dir($path.'/modules/'.$this->name_lower)) { + $paths[] = $path.'/modules/'.$this->name_lower; } } diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__1.txt index 62bd6a496..4e6f62557 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__1.txt @@ -4,15 +4,16 @@ namespace Modules\Blog\Providers; use Illuminate\Support\Facades\Blade; use Illuminate\Support\ServiceProvider; +use Illuminate\Support\Str; use Nwidart\Modules\Traits\PathNamespace; class BlogServiceProvider extends ServiceProvider { use PathNamespace; - protected string $moduleName = 'Blog'; + protected string $name = 'Blog'; - protected string $moduleNameLower = 'blog'; + protected string $name_lower = 'blog'; /** * Boot the application events. @@ -24,7 +25,7 @@ class BlogServiceProvider extends ServiceProvider $this->registerTranslations(); $this->registerConfig(); $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations')); + $this->loadMigrationsFrom(module_path($this->name, 'database/migrations')); } /** @@ -60,14 +61,14 @@ class BlogServiceProvider extends ServiceProvider */ public function registerTranslations(): void { - $langPath = resource_path('lang/modules/'.$this->moduleNameLower); + $langPath = resource_path('lang/modules/'.$this->name_lower); if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); + $this->loadTranslationsFrom($langPath, $this->name_lower); $this->loadJsonTranslationsFrom($langPath); } else { - $this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower); - $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang')); + $this->loadTranslationsFrom(module_path($this->name, 'lang'), $this->name_lower); + $this->loadJsonTranslationsFrom(module_path($this->name, 'lang')); } } @@ -76,8 +77,14 @@ class BlogServiceProvider extends ServiceProvider */ protected function registerConfig(): void { - $this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config'); - $this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower); + $configs = glob(module_path($this->name, 'config/*.php')); + foreach ($configs as $config) { + $filename = Str::of($config)->after(module_path($this->name, 'config/'))->remove('.php')->toString(); + $name = ($filename == 'config') ? $this->name_lower : $filename; // could be removed if the config file is named after the module [modules/Blog => config/blog.php]. + + $this->publishes([module_path($this->name, "config/{$filename}.php") => config_path($name . '.php')], 'config'); + $this->mergeConfigFrom(module_path($this->name, "config/{$filename}.php"), $name); + } } /** @@ -85,36 +92,31 @@ class BlogServiceProvider extends ServiceProvider */ public function registerViews(): void { - $viewPath = resource_path('views/modules/'.$this->moduleNameLower); - $sourcePath = module_path($this->moduleName, 'resources/views'); + $viewPath = resource_path('views/modules/'.$this->name_lower); + $sourcePath = module_path($this->name, 'resources/views'); - $this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']); + $this->publishes([$sourcePath => $viewPath], ['views', $this->name_lower.'-module-views']); - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->name_lower); - $componentNamespace = $this->module_namespace($this->moduleName, $this->app_path(config('modules.paths.generator.component-class.path'))); - Blade::componentNamespace($componentNamespace, $this->moduleNameLower); + $componentNamespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($componentNamespace, $this->name_lower); } /** * Get the services provided by the provider. - * - * @return array */ public function provides(): array { return []; } - /** - * @return array - */ private function getPublishableViewPaths(): array { $paths = []; foreach (config('view.paths') as $path) { - if (is_dir($path.'/modules/'.$this->moduleNameLower)) { - $paths[] = $path.'/modules/'.$this->moduleNameLower; + if (is_dir($path.'/modules/'.$this->name_lower)) { + $paths[] = $path.'/modules/'.$this->name_lower; } } diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_namespace_using_studly_case__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_namespace_using_studly_case__1.txt index f6c99ebc3..ab994bb0c 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_namespace_using_studly_case__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_namespace_using_studly_case__1.txt @@ -4,15 +4,16 @@ namespace Modules\ModuleName\Providers; use Illuminate\Support\Facades\Blade; use Illuminate\Support\ServiceProvider; +use Illuminate\Support\Str; use Nwidart\Modules\Traits\PathNamespace; class ModuleNameServiceProvider extends ServiceProvider { use PathNamespace; - protected string $moduleName = 'ModuleName'; + protected string $name = 'ModuleName'; - protected string $moduleNameLower = 'modulename'; + protected string $name_lower = 'modulename'; /** * Boot the application events. @@ -24,7 +25,7 @@ class ModuleNameServiceProvider extends ServiceProvider $this->registerTranslations(); $this->registerConfig(); $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations')); + $this->loadMigrationsFrom(module_path($this->name, 'database/migrations')); } /** @@ -60,14 +61,14 @@ class ModuleNameServiceProvider extends ServiceProvider */ public function registerTranslations(): void { - $langPath = resource_path('lang/modules/'.$this->moduleNameLower); + $langPath = resource_path('lang/modules/'.$this->name_lower); if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); + $this->loadTranslationsFrom($langPath, $this->name_lower); $this->loadJsonTranslationsFrom($langPath); } else { - $this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower); - $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang')); + $this->loadTranslationsFrom(module_path($this->name, 'lang'), $this->name_lower); + $this->loadJsonTranslationsFrom(module_path($this->name, 'lang')); } } @@ -76,8 +77,14 @@ class ModuleNameServiceProvider extends ServiceProvider */ protected function registerConfig(): void { - $this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config'); - $this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower); + $configs = glob(module_path($this->name, 'config/*.php')); + foreach ($configs as $config) { + $filename = Str::of($config)->after(module_path($this->name, 'config/'))->remove('.php')->toString(); + $name = ($filename == 'config') ? $this->name_lower : $filename; // could be removed if the config file is named after the module [modules/Blog => config/blog.php]. + + $this->publishes([module_path($this->name, "config/{$filename}.php") => config_path($name . '.php')], 'config'); + $this->mergeConfigFrom(module_path($this->name, "config/{$filename}.php"), $name); + } } /** @@ -85,15 +92,15 @@ class ModuleNameServiceProvider extends ServiceProvider */ public function registerViews(): void { - $viewPath = resource_path('views/modules/'.$this->moduleNameLower); - $sourcePath = module_path($this->moduleName, 'resources/views'); + $viewPath = resource_path('views/modules/'.$this->name_lower); + $sourcePath = module_path($this->name, 'resources/views'); - $this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']); + $this->publishes([$sourcePath => $viewPath], ['views', $this->name_lower.'-module-views']); - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->name_lower); - $componentNamespace = $this->module_namespace($this->moduleName, $this->app_path(config('modules.paths.generator.component-class.path'))); - Blade::componentNamespace($componentNamespace, $this->moduleNameLower); + $componentNamespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($componentNamespace, $this->name_lower); } /** @@ -113,8 +120,8 @@ class ModuleNameServiceProvider extends ServiceProvider { $paths = []; foreach (config('view.paths') as $path) { - if (is_dir($path.'/modules/'.$this->moduleNameLower)) { - $paths[] = $path.'/modules/'.$this->moduleNameLower; + if (is_dir($path.'/modules/'.$this->name_lower)) { + $paths[] = $path.'/modules/'.$this->name_lower; } } diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__1.txt index 62bd6a496..4e6f62557 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__1.txt @@ -4,15 +4,16 @@ namespace Modules\Blog\Providers; use Illuminate\Support\Facades\Blade; use Illuminate\Support\ServiceProvider; +use Illuminate\Support\Str; use Nwidart\Modules\Traits\PathNamespace; class BlogServiceProvider extends ServiceProvider { use PathNamespace; - protected string $moduleName = 'Blog'; + protected string $name = 'Blog'; - protected string $moduleNameLower = 'blog'; + protected string $name_lower = 'blog'; /** * Boot the application events. @@ -24,7 +25,7 @@ class BlogServiceProvider extends ServiceProvider $this->registerTranslations(); $this->registerConfig(); $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations')); + $this->loadMigrationsFrom(module_path($this->name, 'database/migrations')); } /** @@ -60,14 +61,14 @@ class BlogServiceProvider extends ServiceProvider */ public function registerTranslations(): void { - $langPath = resource_path('lang/modules/'.$this->moduleNameLower); + $langPath = resource_path('lang/modules/'.$this->name_lower); if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); + $this->loadTranslationsFrom($langPath, $this->name_lower); $this->loadJsonTranslationsFrom($langPath); } else { - $this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower); - $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang')); + $this->loadTranslationsFrom(module_path($this->name, 'lang'), $this->name_lower); + $this->loadJsonTranslationsFrom(module_path($this->name, 'lang')); } } @@ -76,8 +77,14 @@ class BlogServiceProvider extends ServiceProvider */ protected function registerConfig(): void { - $this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config'); - $this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower); + $configs = glob(module_path($this->name, 'config/*.php')); + foreach ($configs as $config) { + $filename = Str::of($config)->after(module_path($this->name, 'config/'))->remove('.php')->toString(); + $name = ($filename == 'config') ? $this->name_lower : $filename; // could be removed if the config file is named after the module [modules/Blog => config/blog.php]. + + $this->publishes([module_path($this->name, "config/{$filename}.php") => config_path($name . '.php')], 'config'); + $this->mergeConfigFrom(module_path($this->name, "config/{$filename}.php"), $name); + } } /** @@ -85,36 +92,31 @@ class BlogServiceProvider extends ServiceProvider */ public function registerViews(): void { - $viewPath = resource_path('views/modules/'.$this->moduleNameLower); - $sourcePath = module_path($this->moduleName, 'resources/views'); + $viewPath = resource_path('views/modules/'.$this->name_lower); + $sourcePath = module_path($this->name, 'resources/views'); - $this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']); + $this->publishes([$sourcePath => $viewPath], ['views', $this->name_lower.'-module-views']); - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->name_lower); - $componentNamespace = $this->module_namespace($this->moduleName, $this->app_path(config('modules.paths.generator.component-class.path'))); - Blade::componentNamespace($componentNamespace, $this->moduleNameLower); + $componentNamespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($componentNamespace, $this->name_lower); } /** * Get the services provided by the provider. - * - * @return array */ public function provides(): array { return []; } - /** - * @return array - */ private function getPublishableViewPaths(): array { $paths = []; foreach (config('view.paths') as $path) { - if (is_dir($path.'/modules/'.$this->moduleNameLower)) { - $paths[] = $path.'/modules/'.$this->moduleNameLower; + if (is_dir($path.'/modules/'.$this->name_lower)) { + $paths[] = $path.'/modules/'.$this->name_lower; } } diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__1.txt index 62bd6a496..4e6f62557 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__1.txt @@ -4,15 +4,16 @@ namespace Modules\Blog\Providers; use Illuminate\Support\Facades\Blade; use Illuminate\Support\ServiceProvider; +use Illuminate\Support\Str; use Nwidart\Modules\Traits\PathNamespace; class BlogServiceProvider extends ServiceProvider { use PathNamespace; - protected string $moduleName = 'Blog'; + protected string $name = 'Blog'; - protected string $moduleNameLower = 'blog'; + protected string $name_lower = 'blog'; /** * Boot the application events. @@ -24,7 +25,7 @@ class BlogServiceProvider extends ServiceProvider $this->registerTranslations(); $this->registerConfig(); $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations')); + $this->loadMigrationsFrom(module_path($this->name, 'database/migrations')); } /** @@ -60,14 +61,14 @@ class BlogServiceProvider extends ServiceProvider */ public function registerTranslations(): void { - $langPath = resource_path('lang/modules/'.$this->moduleNameLower); + $langPath = resource_path('lang/modules/'.$this->name_lower); if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); + $this->loadTranslationsFrom($langPath, $this->name_lower); $this->loadJsonTranslationsFrom($langPath); } else { - $this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower); - $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang')); + $this->loadTranslationsFrom(module_path($this->name, 'lang'), $this->name_lower); + $this->loadJsonTranslationsFrom(module_path($this->name, 'lang')); } } @@ -76,8 +77,14 @@ class BlogServiceProvider extends ServiceProvider */ protected function registerConfig(): void { - $this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config'); - $this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower); + $configs = glob(module_path($this->name, 'config/*.php')); + foreach ($configs as $config) { + $filename = Str::of($config)->after(module_path($this->name, 'config/'))->remove('.php')->toString(); + $name = ($filename == 'config') ? $this->name_lower : $filename; // could be removed if the config file is named after the module [modules/Blog => config/blog.php]. + + $this->publishes([module_path($this->name, "config/{$filename}.php") => config_path($name . '.php')], 'config'); + $this->mergeConfigFrom(module_path($this->name, "config/{$filename}.php"), $name); + } } /** @@ -85,36 +92,31 @@ class BlogServiceProvider extends ServiceProvider */ public function registerViews(): void { - $viewPath = resource_path('views/modules/'.$this->moduleNameLower); - $sourcePath = module_path($this->moduleName, 'resources/views'); + $viewPath = resource_path('views/modules/'.$this->name_lower); + $sourcePath = module_path($this->name, 'resources/views'); - $this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']); + $this->publishes([$sourcePath => $viewPath], ['views', $this->name_lower.'-module-views']); - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->name_lower); - $componentNamespace = $this->module_namespace($this->moduleName, $this->app_path(config('modules.paths.generator.component-class.path'))); - Blade::componentNamespace($componentNamespace, $this->moduleNameLower); + $componentNamespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($componentNamespace, $this->name_lower); } /** * Get the services provided by the provider. - * - * @return array */ public function provides(): array { return []; } - /** - * @return array - */ private function getPublishableViewPaths(): array { $paths = []; foreach (config('view.paths') as $path) { - if (is_dir($path.'/modules/'.$this->moduleNameLower)) { - $paths[] = $path.'/modules/'.$this->moduleNameLower; + if (is_dir($path.'/modules/'.$this->name_lower)) { + $paths[] = $path.'/modules/'.$this->name_lower; } } diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__1.txt index 62bd6a496..4e6f62557 100644 --- a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__1.txt @@ -4,15 +4,16 @@ namespace Modules\Blog\Providers; use Illuminate\Support\Facades\Blade; use Illuminate\Support\ServiceProvider; +use Illuminate\Support\Str; use Nwidart\Modules\Traits\PathNamespace; class BlogServiceProvider extends ServiceProvider { use PathNamespace; - protected string $moduleName = 'Blog'; + protected string $name = 'Blog'; - protected string $moduleNameLower = 'blog'; + protected string $name_lower = 'blog'; /** * Boot the application events. @@ -24,7 +25,7 @@ class BlogServiceProvider extends ServiceProvider $this->registerTranslations(); $this->registerConfig(); $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations')); + $this->loadMigrationsFrom(module_path($this->name, 'database/migrations')); } /** @@ -60,14 +61,14 @@ class BlogServiceProvider extends ServiceProvider */ public function registerTranslations(): void { - $langPath = resource_path('lang/modules/'.$this->moduleNameLower); + $langPath = resource_path('lang/modules/'.$this->name_lower); if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); + $this->loadTranslationsFrom($langPath, $this->name_lower); $this->loadJsonTranslationsFrom($langPath); } else { - $this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower); - $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang')); + $this->loadTranslationsFrom(module_path($this->name, 'lang'), $this->name_lower); + $this->loadJsonTranslationsFrom(module_path($this->name, 'lang')); } } @@ -76,8 +77,14 @@ class BlogServiceProvider extends ServiceProvider */ protected function registerConfig(): void { - $this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config'); - $this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower); + $configs = glob(module_path($this->name, 'config/*.php')); + foreach ($configs as $config) { + $filename = Str::of($config)->after(module_path($this->name, 'config/'))->remove('.php')->toString(); + $name = ($filename == 'config') ? $this->name_lower : $filename; // could be removed if the config file is named after the module [modules/Blog => config/blog.php]. + + $this->publishes([module_path($this->name, "config/{$filename}.php") => config_path($name . '.php')], 'config'); + $this->mergeConfigFrom(module_path($this->name, "config/{$filename}.php"), $name); + } } /** @@ -85,36 +92,31 @@ class BlogServiceProvider extends ServiceProvider */ public function registerViews(): void { - $viewPath = resource_path('views/modules/'.$this->moduleNameLower); - $sourcePath = module_path($this->moduleName, 'resources/views'); + $viewPath = resource_path('views/modules/'.$this->name_lower); + $sourcePath = module_path($this->name, 'resources/views'); - $this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']); + $this->publishes([$sourcePath => $viewPath], ['views', $this->name_lower.'-module-views']); - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->name_lower); - $componentNamespace = $this->module_namespace($this->moduleName, $this->app_path(config('modules.paths.generator.component-class.path'))); - Blade::componentNamespace($componentNamespace, $this->moduleNameLower); + $componentNamespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($componentNamespace, $this->name_lower); } /** * Get the services provided by the provider. - * - * @return array */ public function provides(): array { return []; } - /** - * @return array - */ private function getPublishableViewPaths(): array { $paths = []; foreach (config('view.paths') as $path) { - if (is_dir($path.'/modules/'.$this->moduleNameLower)) { - $paths[] = $path.'/modules/'.$this->moduleNameLower; + if (is_dir($path.'/modules/'.$this->name_lower)) { + $paths[] = $path.'/modules/'.$this->name_lower; } } diff --git a/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_change_the_default_namespace__1.txt b/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_change_the_default_namespace__1.txt index 86ef5859a..25ceaf7be 100644 --- a/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_change_the_default_namespace__1.txt +++ b/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_change_the_default_namespace__1.txt @@ -4,15 +4,16 @@ namespace Modules\Blog\SuperProviders; use Illuminate\Support\Facades\Blade; use Illuminate\Support\ServiceProvider; +use Illuminate\Support\Str; use Nwidart\Modules\Traits\PathNamespace; class BlogServiceProvider extends ServiceProvider { use PathNamespace; - protected string $moduleName = 'Blog'; + protected string $name = 'Blog'; - protected string $moduleNameLower = 'blog'; + protected string $name_lower = 'blog'; /** * Boot the application events. @@ -24,7 +25,7 @@ class BlogServiceProvider extends ServiceProvider $this->registerTranslations(); $this->registerConfig(); $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations')); + $this->loadMigrationsFrom(module_path($this->name, 'database/migrations')); } /** @@ -60,14 +61,14 @@ class BlogServiceProvider extends ServiceProvider */ public function registerTranslations(): void { - $langPath = resource_path('lang/modules/'.$this->moduleNameLower); + $langPath = resource_path('lang/modules/'.$this->name_lower); if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); + $this->loadTranslationsFrom($langPath, $this->name_lower); $this->loadJsonTranslationsFrom($langPath); } else { - $this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower); - $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang')); + $this->loadTranslationsFrom(module_path($this->name, 'lang'), $this->name_lower); + $this->loadJsonTranslationsFrom(module_path($this->name, 'lang')); } } @@ -76,8 +77,14 @@ class BlogServiceProvider extends ServiceProvider */ protected function registerConfig(): void { - $this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config'); - $this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower); + $configs = glob(module_path($this->name, 'config/*.php')); + foreach ($configs as $config) { + $filename = Str::of($config)->after(module_path($this->name, 'config/'))->remove('.php')->toString(); + $name = ($filename == 'config') ? $this->name_lower : $filename; // could be removed if the config file is named after the module [modules/Blog => config/blog.php]. + + $this->publishes([module_path($this->name, "config/{$filename}.php") => config_path($name . '.php')], 'config'); + $this->mergeConfigFrom(module_path($this->name, "config/{$filename}.php"), $name); + } } /** @@ -85,36 +92,31 @@ class BlogServiceProvider extends ServiceProvider */ public function registerViews(): void { - $viewPath = resource_path('views/modules/'.$this->moduleNameLower); - $sourcePath = module_path($this->moduleName, 'resources/views'); + $viewPath = resource_path('views/modules/'.$this->name_lower); + $sourcePath = module_path($this->name, 'resources/views'); - $this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']); + $this->publishes([$sourcePath => $viewPath], ['views', $this->name_lower.'-module-views']); - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->name_lower); - $componentNamespace = $this->module_namespace($this->moduleName, $this->app_path(config('modules.paths.generator.component-class.path'))); - Blade::componentNamespace($componentNamespace, $this->moduleNameLower); + $componentNamespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($componentNamespace, $this->name_lower); } /** * Get the services provided by the provider. - * - * @return array */ public function provides(): array { return []; } - /** - * @return array - */ private function getPublishableViewPaths(): array { $paths = []; foreach (config('view.paths') as $path) { - if (is_dir($path.'/modules/'.$this->moduleNameLower)) { - $paths[] = $path.'/modules/'.$this->moduleNameLower; + if (is_dir($path.'/modules/'.$this->name_lower)) { + $paths[] = $path.'/modules/'.$this->name_lower; } } diff --git a/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_change_the_default_namespace_specific__1.txt b/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_change_the_default_namespace_specific__1.txt index 86ef5859a..25ceaf7be 100644 --- a/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_change_the_default_namespace_specific__1.txt +++ b/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_change_the_default_namespace_specific__1.txt @@ -4,15 +4,16 @@ namespace Modules\Blog\SuperProviders; use Illuminate\Support\Facades\Blade; use Illuminate\Support\ServiceProvider; +use Illuminate\Support\Str; use Nwidart\Modules\Traits\PathNamespace; class BlogServiceProvider extends ServiceProvider { use PathNamespace; - protected string $moduleName = 'Blog'; + protected string $name = 'Blog'; - protected string $moduleNameLower = 'blog'; + protected string $name_lower = 'blog'; /** * Boot the application events. @@ -24,7 +25,7 @@ class BlogServiceProvider extends ServiceProvider $this->registerTranslations(); $this->registerConfig(); $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations')); + $this->loadMigrationsFrom(module_path($this->name, 'database/migrations')); } /** @@ -60,14 +61,14 @@ class BlogServiceProvider extends ServiceProvider */ public function registerTranslations(): void { - $langPath = resource_path('lang/modules/'.$this->moduleNameLower); + $langPath = resource_path('lang/modules/'.$this->name_lower); if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); + $this->loadTranslationsFrom($langPath, $this->name_lower); $this->loadJsonTranslationsFrom($langPath); } else { - $this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower); - $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang')); + $this->loadTranslationsFrom(module_path($this->name, 'lang'), $this->name_lower); + $this->loadJsonTranslationsFrom(module_path($this->name, 'lang')); } } @@ -76,8 +77,14 @@ class BlogServiceProvider extends ServiceProvider */ protected function registerConfig(): void { - $this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config'); - $this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower); + $configs = glob(module_path($this->name, 'config/*.php')); + foreach ($configs as $config) { + $filename = Str::of($config)->after(module_path($this->name, 'config/'))->remove('.php')->toString(); + $name = ($filename == 'config') ? $this->name_lower : $filename; // could be removed if the config file is named after the module [modules/Blog => config/blog.php]. + + $this->publishes([module_path($this->name, "config/{$filename}.php") => config_path($name . '.php')], 'config'); + $this->mergeConfigFrom(module_path($this->name, "config/{$filename}.php"), $name); + } } /** @@ -85,36 +92,31 @@ class BlogServiceProvider extends ServiceProvider */ public function registerViews(): void { - $viewPath = resource_path('views/modules/'.$this->moduleNameLower); - $sourcePath = module_path($this->moduleName, 'resources/views'); + $viewPath = resource_path('views/modules/'.$this->name_lower); + $sourcePath = module_path($this->name, 'resources/views'); - $this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']); + $this->publishes([$sourcePath => $viewPath], ['views', $this->name_lower.'-module-views']); - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->name_lower); - $componentNamespace = $this->module_namespace($this->moduleName, $this->app_path(config('modules.paths.generator.component-class.path'))); - Blade::componentNamespace($componentNamespace, $this->moduleNameLower); + $componentNamespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($componentNamespace, $this->name_lower); } /** * Get the services provided by the provider. - * - * @return array */ public function provides(): array { return []; } - /** - * @return array - */ private function getPublishableViewPaths(): array { $paths = []; foreach (config('view.paths') as $path) { - if (is_dir($path.'/modules/'.$this->moduleNameLower)) { - $paths[] = $path.'/modules/'.$this->moduleNameLower; + if (is_dir($path.'/modules/'.$this->name_lower)) { + $paths[] = $path.'/modules/'.$this->name_lower; } } diff --git a/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_have_custom_migration_resources_location_paths__1.txt b/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_have_custom_migration_resources_location_paths__1.txt index 991b8969b..1acdaf3cd 100644 --- a/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_have_custom_migration_resources_location_paths__1.txt +++ b/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_have_custom_migration_resources_location_paths__1.txt @@ -4,15 +4,16 @@ namespace Modules\Blog\Providers; use Illuminate\Support\Facades\Blade; use Illuminate\Support\ServiceProvider; +use Illuminate\Support\Str; use Nwidart\Modules\Traits\PathNamespace; class BlogServiceProvider extends ServiceProvider { use PathNamespace; - protected string $moduleName = 'Blog'; + protected string $name = 'Blog'; - protected string $moduleNameLower = 'blog'; + protected string $name_lower = 'blog'; /** * Boot the application events. @@ -24,7 +25,7 @@ class BlogServiceProvider extends ServiceProvider $this->registerTranslations(); $this->registerConfig(); $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, 'migrations')); + $this->loadMigrationsFrom(module_path($this->name, 'migrations')); } /** @@ -60,14 +61,14 @@ class BlogServiceProvider extends ServiceProvider */ public function registerTranslations(): void { - $langPath = resource_path('lang/modules/'.$this->moduleNameLower); + $langPath = resource_path('lang/modules/'.$this->name_lower); if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); + $this->loadTranslationsFrom($langPath, $this->name_lower); $this->loadJsonTranslationsFrom($langPath); } else { - $this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower); - $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang')); + $this->loadTranslationsFrom(module_path($this->name, 'lang'), $this->name_lower); + $this->loadJsonTranslationsFrom(module_path($this->name, 'lang')); } } @@ -76,8 +77,14 @@ class BlogServiceProvider extends ServiceProvider */ protected function registerConfig(): void { - $this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config'); - $this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower); + $configs = glob(module_path($this->name, 'config/*.php')); + foreach ($configs as $config) { + $filename = Str::of($config)->after(module_path($this->name, 'config/'))->remove('.php')->toString(); + $name = ($filename == 'config') ? $this->name_lower : $filename; // could be removed if the config file is named after the module [modules/Blog => config/blog.php]. + + $this->publishes([module_path($this->name, "config/{$filename}.php") => config_path($name . '.php')], 'config'); + $this->mergeConfigFrom(module_path($this->name, "config/{$filename}.php"), $name); + } } /** @@ -85,36 +92,31 @@ class BlogServiceProvider extends ServiceProvider */ public function registerViews(): void { - $viewPath = resource_path('views/modules/'.$this->moduleNameLower); - $sourcePath = module_path($this->moduleName, 'resources/views'); + $viewPath = resource_path('views/modules/'.$this->name_lower); + $sourcePath = module_path($this->name, 'resources/views'); - $this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']); + $this->publishes([$sourcePath => $viewPath], ['views', $this->name_lower.'-module-views']); - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->name_lower); - $componentNamespace = $this->module_namespace($this->moduleName, $this->app_path(config('modules.paths.generator.component-class.path'))); - Blade::componentNamespace($componentNamespace, $this->moduleNameLower); + $componentNamespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($componentNamespace, $this->name_lower); } /** * Get the services provided by the provider. - * - * @return array */ public function provides(): array { return []; } - /** - * @return array - */ private function getPublishableViewPaths(): array { $paths = []; foreach (config('view.paths') as $path) { - if (is_dir($path.'/modules/'.$this->moduleNameLower)) { - $paths[] = $path.'/modules/'.$this->moduleNameLower; + if (is_dir($path.'/modules/'.$this->name_lower)) { + $paths[] = $path.'/modules/'.$this->name_lower; } } diff --git a/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_generates_a_master_service_provider_with_resource_loading__1.txt b/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_generates_a_master_service_provider_with_resource_loading__1.txt index 62bd6a496..4e6f62557 100644 --- a/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_generates_a_master_service_provider_with_resource_loading__1.txt +++ b/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_generates_a_master_service_provider_with_resource_loading__1.txt @@ -4,15 +4,16 @@ namespace Modules\Blog\Providers; use Illuminate\Support\Facades\Blade; use Illuminate\Support\ServiceProvider; +use Illuminate\Support\Str; use Nwidart\Modules\Traits\PathNamespace; class BlogServiceProvider extends ServiceProvider { use PathNamespace; - protected string $moduleName = 'Blog'; + protected string $name = 'Blog'; - protected string $moduleNameLower = 'blog'; + protected string $name_lower = 'blog'; /** * Boot the application events. @@ -24,7 +25,7 @@ class BlogServiceProvider extends ServiceProvider $this->registerTranslations(); $this->registerConfig(); $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations')); + $this->loadMigrationsFrom(module_path($this->name, 'database/migrations')); } /** @@ -60,14 +61,14 @@ class BlogServiceProvider extends ServiceProvider */ public function registerTranslations(): void { - $langPath = resource_path('lang/modules/'.$this->moduleNameLower); + $langPath = resource_path('lang/modules/'.$this->name_lower); if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); + $this->loadTranslationsFrom($langPath, $this->name_lower); $this->loadJsonTranslationsFrom($langPath); } else { - $this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower); - $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang')); + $this->loadTranslationsFrom(module_path($this->name, 'lang'), $this->name_lower); + $this->loadJsonTranslationsFrom(module_path($this->name, 'lang')); } } @@ -76,8 +77,14 @@ class BlogServiceProvider extends ServiceProvider */ protected function registerConfig(): void { - $this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config'); - $this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower); + $configs = glob(module_path($this->name, 'config/*.php')); + foreach ($configs as $config) { + $filename = Str::of($config)->after(module_path($this->name, 'config/'))->remove('.php')->toString(); + $name = ($filename == 'config') ? $this->name_lower : $filename; // could be removed if the config file is named after the module [modules/Blog => config/blog.php]. + + $this->publishes([module_path($this->name, "config/{$filename}.php") => config_path($name . '.php')], 'config'); + $this->mergeConfigFrom(module_path($this->name, "config/{$filename}.php"), $name); + } } /** @@ -85,36 +92,31 @@ class BlogServiceProvider extends ServiceProvider */ public function registerViews(): void { - $viewPath = resource_path('views/modules/'.$this->moduleNameLower); - $sourcePath = module_path($this->moduleName, 'resources/views'); + $viewPath = resource_path('views/modules/'.$this->name_lower); + $sourcePath = module_path($this->name, 'resources/views'); - $this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']); + $this->publishes([$sourcePath => $viewPath], ['views', $this->name_lower.'-module-views']); - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->name_lower); - $componentNamespace = $this->module_namespace($this->moduleName, $this->app_path(config('modules.paths.generator.component-class.path'))); - Blade::componentNamespace($componentNamespace, $this->moduleNameLower); + $componentNamespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($componentNamespace, $this->name_lower); } /** * Get the services provided by the provider. - * - * @return array */ public function provides(): array { return []; } - /** - * @return array - */ private function getPublishableViewPaths(): array { $paths = []; foreach (config('view.paths') as $path) { - if (is_dir($path.'/modules/'.$this->moduleNameLower)) { - $paths[] = $path.'/modules/'.$this->moduleNameLower; + if (is_dir($path.'/modules/'.$this->name_lower)) { + $paths[] = $path.'/modules/'.$this->name_lower; } }