Skip to content

feat: add ConfigPlugin to auto-load module config files#131

Open
calebdw wants to merge 3 commits intoInterNACHI:mainfrom
calebdw:calebdw/push-oyturnnkrrox
Open

feat: add ConfigPlugin to auto-load module config files#131
calebdw wants to merge 3 commits intoInterNACHI:mainfrom
calebdw:calebdw/push-oyturnnkrrox

Conversation

@calebdw
Copy link

@calebdw calebdw commented Feb 13, 2026

Hello!

In our project, we created a base service provider which allows every module to have its own config file (here we place things like the morph_map for that module and other module-specific configs). With the new plugin system, I figured this would be great to PR upstream.

Example:

abstract class ModuleServiceProvider extends ServiceProvider
{
    #[Override]
    public function register(): void
    {
        if ($this->app instanceof CachesConfiguration && $this->app->configurationIsCached()) {
            return;
        }

        $modules = $this->app->make('config')->get('app-modules.modules_directory');
        $module  = $this->moduleName();
        $config  = $this->app->basePath("{$modules}/{$module}/config/{$module}.php");

        if (file_exists($config)) {
            $this->mergeConfigFrom($config, $module);
        }
    }

    protected function moduleName(): string
    {
        return Str::of(static::class)
            ->afterLast('\\')
            ->before('ServiceProvider')
            ->snake('-')
            ->lower()
            ->toString();
    }
}

This has 3 commits:

  1. I had to add an .editorconfig to keep my editor (neovim btw 🙃) from trying to convert tabs to spaces---feel free to customize
  2. I added a new OnRegister attribute that allows plugins to hook into register
  3. I added the new ConfigPlugin

Thanks!

This project uses tabs for PHP indentation. Adding an .editorconfig
helps editors and IDEs respect this convention automatically.

- PHP: tabs (project convention)
- JSON: 4 spaces
- YAML: 2 spaces
- All files: UTF-8, LF line endings, final newline
Introduces a registration-phase hook for plugins, mirroring the existing
boot-phase pattern. Plugins can use #[OnRegister] attribute to run during
the service provider's register() method instead of boot().

This is needed for plugins like config loading that must complete before
other services are resolved.
Add ConfigPlugin that automatically discovers and loads configuration files
from module config/ directories. Module configs are merged with app-level
configs, where app-level config values take precedence over module defaults.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant