Skip to content

Commit

Permalink
[test] Update test snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
solomon-ochepa committed Aug 31, 2024
1 parent 8f7b9e9 commit 26e3046
Show file tree
Hide file tree
Showing 11 changed files with 264 additions and 237 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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'));
}

/**
Expand Down Expand Up @@ -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'));
}
}

Expand All @@ -76,45 +77,46 @@ 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);
}
}

/**
* Register views.
*/
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<string>
*/
public function provides(): array
{
return [];
}

/**
* @return array<string>
*/
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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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'));
}

/**
Expand Down Expand Up @@ -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'));
}
}

Expand All @@ -76,45 +77,46 @@ 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);
}
}

/**
* Register views.
*/
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<string>
*/
public function provides(): array
{
return [];
}

/**
* @return array<string>
*/
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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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'));
}

/**
Expand Down Expand Up @@ -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'));
}
}

Expand All @@ -76,45 +77,46 @@ 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);
}
}

/**
* Register views.
*/
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<string>
*/
public function provides(): array
{
return [];
}

/**
* @return array<string>
*/
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;
}
}

Expand Down
Loading

0 comments on commit 26e3046

Please sign in to comment.