Skip to content

Commit

Permalink
Merge pull request #1979 from nWidart/add-multiple-config-support
Browse files Browse the repository at this point in the history
add support for multiple config files and nested config files
  • Loading branch information
dcblogdev authored Nov 16, 2024
2 parents 57734a0 + 757175e commit 0c04e1a
Show file tree
Hide file tree
Showing 12 changed files with 228 additions and 24 deletions.
21 changes: 19 additions & 2 deletions src/Commands/stubs/scaffold/provider.stub
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace $NAMESPACE$;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Nwidart\Modules\Traits\PathNamespace;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

class $CLASS$ extends ServiceProvider
{
Expand Down Expand Up @@ -76,8 +78,23 @@ class $CLASS$ extends ServiceProvider
*/
protected function registerConfig(): void
{
$this->publishes([module_path($this->name, '$PATH_CONFIG$/config.php') => config_path($this->nameLower.'.php')], 'config');
$this->mergeConfigFrom(module_path($this->name, '$PATH_CONFIG$/config.php'), $this->nameLower);
$relativeConfigPath = config('modules.paths.generator.config.path');
$configPath = module_path($this->name, $relativeConfigPath);

if (is_dir($configPath)) {
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($configPath));

foreach ($iterator as $file) {
if ($file->isFile() && $file->getExtension() === 'php') {
$relativePath = str_replace($configPath . DIRECTORY_SEPARATOR, '', $file->getPathname());
$configKey = $this->nameLower . '.' . str_replace([DIRECTORY_SEPARATOR, '.php'], ['.', ''], $relativePath);
$key = ($relativePath === 'config.php') ? $this->nameLower : $configKey;

$this->publishes([$file->getPathname() => config_path($relativePath)], $configPath);
$this->mergeConfigFrom($file->getPathname(), $key);
}
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace Modules\Blog\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Nwidart\Modules\Traits\PathNamespace;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

class BlogServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -76,8 +78,23 @@ class BlogServiceProvider extends ServiceProvider
*/
protected function registerConfig(): void
{
$this->publishes([module_path($this->name, 'config/config.php') => config_path($this->nameLower.'.php')], 'config');
$this->mergeConfigFrom(module_path($this->name, 'config/config.php'), $this->nameLower);
$relativeConfigPath = config('modules.paths.generator.config.path');
$configPath = module_path($this->name, $relativeConfigPath);

if (is_dir($configPath)) {
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($configPath));

foreach ($iterator as $file) {
if ($file->isFile() && $file->getExtension() === 'php') {
$relativePath = str_replace($configPath . DIRECTORY_SEPARATOR, '', $file->getPathname());
$configKey = $this->nameLower . '.' . str_replace([DIRECTORY_SEPARATOR, '.php'], ['.', ''], $relativePath);
$key = ($relativePath === 'config.php') ? $this->nameLower : $configKey;

$this->publishes([$file->getPathname() => config_path($relativePath)], $configPath);
$this->mergeConfigFrom($file->getPathname(), $key);
}
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace Modules\Blog\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Nwidart\Modules\Traits\PathNamespace;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

class BlogServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -76,8 +78,23 @@ class BlogServiceProvider extends ServiceProvider
*/
protected function registerConfig(): void
{
$this->publishes([module_path($this->name, 'config/config.php') => config_path($this->nameLower.'.php')], 'config');
$this->mergeConfigFrom(module_path($this->name, 'config/config.php'), $this->nameLower);
$relativeConfigPath = config('modules.paths.generator.config.path');
$configPath = module_path($this->name, $relativeConfigPath);

if (is_dir($configPath)) {
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($configPath));

foreach ($iterator as $file) {
if ($file->isFile() && $file->getExtension() === 'php') {
$relativePath = str_replace($configPath . DIRECTORY_SEPARATOR, '', $file->getPathname());
$configKey = $this->nameLower . '.' . str_replace([DIRECTORY_SEPARATOR, '.php'], ['.', ''], $relativePath);
$key = ($relativePath === 'config.php') ? $this->nameLower : $configKey;

$this->publishes([$file->getPathname() => config_path($relativePath)], $configPath);
$this->mergeConfigFrom($file->getPathname(), $key);
}
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace Modules\Blog\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Nwidart\Modules\Traits\PathNamespace;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

class BlogServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -76,8 +78,23 @@ class BlogServiceProvider extends ServiceProvider
*/
protected function registerConfig(): void
{
$this->publishes([module_path($this->name, 'config/config.php') => config_path($this->nameLower.'.php')], 'config');
$this->mergeConfigFrom(module_path($this->name, 'config/config.php'), $this->nameLower);
$relativeConfigPath = config('modules.paths.generator.config.path');
$configPath = module_path($this->name, $relativeConfigPath);

if (is_dir($configPath)) {
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($configPath));

foreach ($iterator as $file) {
if ($file->isFile() && $file->getExtension() === 'php') {
$relativePath = str_replace($configPath . DIRECTORY_SEPARATOR, '', $file->getPathname());
$configKey = $this->nameLower . '.' . str_replace([DIRECTORY_SEPARATOR, '.php'], ['.', ''], $relativePath);
$key = ($relativePath === 'config.php') ? $this->nameLower : $configKey;

$this->publishes([$file->getPathname() => config_path($relativePath)], $configPath);
$this->mergeConfigFrom($file->getPathname(), $key);
}
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace Modules\ModuleName\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Nwidart\Modules\Traits\PathNamespace;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

class ModuleNameServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -76,8 +78,23 @@ class ModuleNameServiceProvider extends ServiceProvider
*/
protected function registerConfig(): void
{
$this->publishes([module_path($this->name, 'config/config.php') => config_path($this->nameLower.'.php')], 'config');
$this->mergeConfigFrom(module_path($this->name, 'config/config.php'), $this->nameLower);
$relativeConfigPath = config('modules.paths.generator.config.path');
$configPath = module_path($this->name, $relativeConfigPath);

if (is_dir($configPath)) {
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($configPath));

foreach ($iterator as $file) {
if ($file->isFile() && $file->getExtension() === 'php') {
$relativePath = str_replace($configPath . DIRECTORY_SEPARATOR, '', $file->getPathname());
$configKey = $this->nameLower . '.' . str_replace([DIRECTORY_SEPARATOR, '.php'], ['.', ''], $relativePath);
$key = ($relativePath === 'config.php') ? $this->nameLower : $configKey;

$this->publishes([$file->getPathname() => config_path($relativePath)], $configPath);
$this->mergeConfigFrom($file->getPathname(), $key);
}
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace Modules\Blog\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Nwidart\Modules\Traits\PathNamespace;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

class BlogServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -76,8 +78,23 @@ class BlogServiceProvider extends ServiceProvider
*/
protected function registerConfig(): void
{
$this->publishes([module_path($this->name, 'config/config.php') => config_path($this->nameLower.'.php')], 'config');
$this->mergeConfigFrom(module_path($this->name, 'config/config.php'), $this->nameLower);
$relativeConfigPath = config('modules.paths.generator.config.path');
$configPath = module_path($this->name, $relativeConfigPath);

if (is_dir($configPath)) {
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($configPath));

foreach ($iterator as $file) {
if ($file->isFile() && $file->getExtension() === 'php') {
$relativePath = str_replace($configPath . DIRECTORY_SEPARATOR, '', $file->getPathname());
$configKey = $this->nameLower . '.' . str_replace([DIRECTORY_SEPARATOR, '.php'], ['.', ''], $relativePath);
$key = ($relativePath === 'config.php') ? $this->nameLower : $configKey;

$this->publishes([$file->getPathname() => config_path($relativePath)], $configPath);
$this->mergeConfigFrom($file->getPathname(), $key);
}
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace Modules\Blog\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Nwidart\Modules\Traits\PathNamespace;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

class BlogServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -76,8 +78,23 @@ class BlogServiceProvider extends ServiceProvider
*/
protected function registerConfig(): void
{
$this->publishes([module_path($this->name, 'config/config.php') => config_path($this->nameLower.'.php')], 'config');
$this->mergeConfigFrom(module_path($this->name, 'config/config.php'), $this->nameLower);
$relativeConfigPath = config('modules.paths.generator.config.path');
$configPath = module_path($this->name, $relativeConfigPath);

if (is_dir($configPath)) {
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($configPath));

foreach ($iterator as $file) {
if ($file->isFile() && $file->getExtension() === 'php') {
$relativePath = str_replace($configPath . DIRECTORY_SEPARATOR, '', $file->getPathname());
$configKey = $this->nameLower . '.' . str_replace([DIRECTORY_SEPARATOR, '.php'], ['.', ''], $relativePath);
$key = ($relativePath === 'config.php') ? $this->nameLower : $configKey;

$this->publishes([$file->getPathname() => config_path($relativePath)], $configPath);
$this->mergeConfigFrom($file->getPathname(), $key);
}
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace Modules\Blog\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Nwidart\Modules\Traits\PathNamespace;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

class BlogServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -76,8 +78,23 @@ class BlogServiceProvider extends ServiceProvider
*/
protected function registerConfig(): void
{
$this->publishes([module_path($this->name, 'config/config.php') => config_path($this->nameLower.'.php')], 'config');
$this->mergeConfigFrom(module_path($this->name, 'config/config.php'), $this->nameLower);
$relativeConfigPath = config('modules.paths.generator.config.path');
$configPath = module_path($this->name, $relativeConfigPath);

if (is_dir($configPath)) {
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($configPath));

foreach ($iterator as $file) {
if ($file->isFile() && $file->getExtension() === 'php') {
$relativePath = str_replace($configPath . DIRECTORY_SEPARATOR, '', $file->getPathname());
$configKey = $this->nameLower . '.' . str_replace([DIRECTORY_SEPARATOR, '.php'], ['.', ''], $relativePath);
$key = ($relativePath === 'config.php') ? $this->nameLower : $configKey;

$this->publishes([$file->getPathname() => config_path($relativePath)], $configPath);
$this->mergeConfigFrom($file->getPathname(), $key);
}
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace Modules\Blog\SuperProviders;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Nwidart\Modules\Traits\PathNamespace;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

class BlogServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -76,8 +78,23 @@ class BlogServiceProvider extends ServiceProvider
*/
protected function registerConfig(): void
{
$this->publishes([module_path($this->name, 'config/config.php') => config_path($this->nameLower.'.php')], 'config');
$this->mergeConfigFrom(module_path($this->name, 'config/config.php'), $this->nameLower);
$relativeConfigPath = config('modules.paths.generator.config.path');
$configPath = module_path($this->name, $relativeConfigPath);

if (is_dir($configPath)) {
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($configPath));

foreach ($iterator as $file) {
if ($file->isFile() && $file->getExtension() === 'php') {
$relativePath = str_replace($configPath . DIRECTORY_SEPARATOR, '', $file->getPathname());
$configKey = $this->nameLower . '.' . str_replace([DIRECTORY_SEPARATOR, '.php'], ['.', ''], $relativePath);
$key = ($relativePath === 'config.php') ? $this->nameLower : $configKey;

$this->publishes([$file->getPathname() => config_path($relativePath)], $configPath);
$this->mergeConfigFrom($file->getPathname(), $key);
}
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace Modules\Blog\SuperProviders;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Nwidart\Modules\Traits\PathNamespace;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

class BlogServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -76,8 +78,23 @@ class BlogServiceProvider extends ServiceProvider
*/
protected function registerConfig(): void
{
$this->publishes([module_path($this->name, 'config/config.php') => config_path($this->nameLower.'.php')], 'config');
$this->mergeConfigFrom(module_path($this->name, 'config/config.php'), $this->nameLower);
$relativeConfigPath = config('modules.paths.generator.config.path');
$configPath = module_path($this->name, $relativeConfigPath);

if (is_dir($configPath)) {
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($configPath));

foreach ($iterator as $file) {
if ($file->isFile() && $file->getExtension() === 'php') {
$relativePath = str_replace($configPath . DIRECTORY_SEPARATOR, '', $file->getPathname());
$configKey = $this->nameLower . '.' . str_replace([DIRECTORY_SEPARATOR, '.php'], ['.', ''], $relativePath);
$key = ($relativePath === 'config.php') ? $this->nameLower : $configKey;

$this->publishes([$file->getPathname() => config_path($relativePath)], $configPath);
$this->mergeConfigFrom($file->getPathname(), $key);
}
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace Modules\Blog\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Nwidart\Modules\Traits\PathNamespace;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

class BlogServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -76,8 +78,23 @@ class BlogServiceProvider extends ServiceProvider
*/
protected function registerConfig(): void
{
$this->publishes([module_path($this->name, 'config/config.php') => config_path($this->nameLower.'.php')], 'config');
$this->mergeConfigFrom(module_path($this->name, 'config/config.php'), $this->nameLower);
$relativeConfigPath = config('modules.paths.generator.config.path');
$configPath = module_path($this->name, $relativeConfigPath);

if (is_dir($configPath)) {
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($configPath));

foreach ($iterator as $file) {
if ($file->isFile() && $file->getExtension() === 'php') {
$relativePath = str_replace($configPath . DIRECTORY_SEPARATOR, '', $file->getPathname());
$configKey = $this->nameLower . '.' . str_replace([DIRECTORY_SEPARATOR, '.php'], ['.', ''], $relativePath);
$key = ($relativePath === 'config.php') ? $this->nameLower : $configKey;

$this->publishes([$file->getPathname() => config_path($relativePath)], $configPath);
$this->mergeConfigFrom($file->getPathname(), $key);
}
}
}
}

/**
Expand Down
Loading

0 comments on commit 0c04e1a

Please sign in to comment.