echo-fusion / modulemanager
Module registry for the EchoFusion framework: modules declare their config, service providers, routes and templates as data.
Requires
- php: ~8.1.0 || ~8.2.0 || ~8.3.0
- echo-fusion/contracts: ^1.5 || ^2.0
Requires (Dev)
- echo-fusion/codestandard: ^1.0
- friendsofphp/php-cs-fixer: ^3.64
- phpunit/phpunit: ^9.5
- vimeo/psalm: ^5.26
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-12 12:21:36 UTC
README
ModuleManager is a registry for application modules. A module is a self-contained feature bundle (for example "Blog" or "Shop") that declares what it adds to the application as data: its configuration, service providers, routes and template directory. The manager collects and merges them so the application can wire everything in one place.
It implements EchoFusion\Contracts\ModuleManager\ModuleManagerInterface and modules implement EchoFusion\Contracts\ModuleManager\ModuleInterface, both from echo-fusion/contracts.
Part of EchoFusion, a modular PHP framework built from small packages.
Installation
composer require echo-fusion/modulemanager
Requirements
- PHP 8.1, 8.2 or 8.3
Usage
Define a module
Extend AbstractModule and override only what the module provides (everything defaults to empty):
use EchoFusion\ModuleManager\AbstractModule; final class BlogModule extends AbstractModule { public function getName(): string { return 'blog'; } public function getConfig(): array { return ['blog' => ['posts_per_page' => 10]]; } public function getProviders(): array { return [BlogServiceProvider::class]; } public function getRoutes(): array { return [ 'blog.index' => [ 'method' => 'GET', 'path' => '/blog', 'action' => [BlogController::class, 'index'], ], ]; } public function getTemplatePath(): ?string { return __DIR__ . '/../templates'; } }
The route format is the one accepted by RouteLoaderInterface::fromArray() of echo-fusion/routemanager.
Register modules
use EchoFusion\ModuleManager\ModuleManager; $modules = new ModuleManager([new BlogModule(), new ShopModule()]); $modules->register(new AdminModule()); // or one at a time $modules->has('blog'); // true $modules->get('blog'); // the BlogModule instance $modules->all(); // ['blog' => ..., 'shop' => ..., 'admin' => ...]
What the application gets
| Method | Result |
|---|---|
getConfig() |
All module configs deeply merged in registration order (later modules win; associative arrays are merged recursively, lists are replaced). |
getProviders() |
All service provider class names, without duplicates. |
getRoutes() |
All routes keyed by name. |
getTemplatePaths() |
['blog' => '/path/to/templates', ...] for modules that have templates. |
Errors
All exceptions extend EchoFusion\ModuleManager\Exceptions\ModuleException:
DuplicateModuleException: a module name was registered twice.ModuleNotFoundException:get()was called with an unknown name.DuplicateRouteException: two modules define a route with the same name (thrown bygetRoutes(), naming both modules).
Testing
composer test
Credits
License
The MIT License (MIT). Please see LICENSE for more information.