Search by

echo-fusion / modulemanager

amir-shadanfar

Module registry for the EchoFusion framework: modules declare their config, service providers, routes and templates as data.

Package info

github.com/echo-fusion/modulemanager

pkg:composer/echo-fusion/modulemanager

Statistics

Installs: 270

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.2 2026-10-12 12:21 UTC

This package is auto-updated.

Last update: 2026-10-12 12:21:36 UTC


README

CI Packagist PHP License

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 by getRoutes(), naming both modules).

Testing

composer test

Credits

License

The MIT License (MIT). Please see LICENSE for more information.