PHPackages                             cadre/module - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. cadre/module

AbandonedLibrary[Utility &amp; Helpers](/categories/utility)

cadre/module
============

Module system based on Aura.Di

0.5.3(8y ago)1653MITPHPPHP ^7.0

Since Oct 20Pushed 8y ago1 watchersCompare

[ Source](https://github.com/cadrephp/Cadre.Module)[ Packagist](https://packagist.org/packages/cadre/module)[ RSS](/packages/cadre-module/feed)WikiDiscussions 0.x Synced 2mo ago

READMEChangelog (7)Dependencies (6)Versions (11)Used By (0)

Cadre.Module
============

[](#cadremodule)

This is a lightweight module system based on [Aura.Di](https://github.com/auraphp/Aura.Di).

This library defines several classes that implement `Aura\Di\ContainerConfigInterface` so it can be used in any project that uses Aura.Di.

This is in early development so please provide feedback via [Issues](https://github.com/cadrephp/Cadre.Module/issues).

Installation and Autoloading
----------------------------

[](#installation-and-autoloading)

This package is installable and PSR-4 autoloadable via Composer as [cadre/module](https://packagist.org/packages/cadre/module).

Alternatively, [download a release](https://github.com/cadrephp/Cadre.Module/releases), or clone this repository, then map the `Cadre\Module\` namespace to the package `src/` directory.

Dependencies
------------

[](#dependencies)

This package requires PHP 7.0 or later; it has been tested on PHP 7.0 and PHP 7.1. We recommend using the latest available version of PHP as a matter of principle.

Quality
-------

[](#quality)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/f4ee2cca0ac732956b30f7a29bb7168a1b14fc8c1462740eaf9a315019b44272/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f63616472657068702f43616472652e4d6f64756c652f6261646765732f7175616c6974792d73636f72652e706e673f623d302e78)](https://scrutinizer-ci.com/g/cadrephp/Cadre.Module/?branch=0.x)[![Code Coverage](https://camo.githubusercontent.com/486ae1a252fc4311d16f2a34350e9854c94c8cc9132d0bdd873ddf782013ba78/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f63616472657068702f43616472652e4d6f64756c652f6261646765732f636f7665726167652e706e673f623d302e78)](https://scrutinizer-ci.com/g/cadrephp/Cadre.Module/?branch=0.x)[![Build Status](https://camo.githubusercontent.com/b734c55cdfd60eda5cb25d78d6c2373125a0f3e071d32427beda4c5e665687b7/68747470733a2f2f7472617669732d63692e6f72672f63616472657068702f43616472652e4d6f64756c652e7376673f6272616e63683d302e78)](https://travis-ci.org/cadrephp/Cadre.Module)

To run the unit tests at the command line, issue `composer install` and then `vendor/bin/phpunit` at the package root. This requires [Composer](http://getcomposer.org/) to be available as `composer`, and [PHPUnit](http://phpunit.de/) to be available as `vendor/bin/phpunit`.

This package attempts to comply with [PSR-1](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md), [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md), and [PSR-4](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md). If you notice compliance oversights, please send a patch via pull request.

Example
-------

[](#example)

```
$loader = new ModuleLoader([
    FirstModule::class,
    SecondModule::class,
], 'development', 'web');

$builder = new ContainerBuilder();
$di = $builder->newConfiguredInstance([$loader]);

$obj = $di->newInstance(ClassFromThirdModule::class);
```

```
use Aura\Di\Container;
use Cadre\Module\Module;

class FirstModule extends Module
{
    public function require()
    {
        if ($this->loader()->isContext('web')) {
            // Only require ThirdModule in the web context
            return [ThirdModule::class];
        } else {
            return [];
        }
    }

    public function define(Container $di)
    {
        $di->params[ClassFromFirstModule::class]['foo'] = 'bar';
    }
}
```

Cadre\\Module\\ModuleInterface
------------------------------

[](#cadremodulemoduleinterface)

This interface extends `Aura\Di\ContainerConfigInterface` and defines four methods.

### require()

[](#require)

Returns an array of class names of other modules that it requires.

### conflict()

[](#conflict)

Returns an array of class names of other modules that it conflicts with.

### replace()

[](#replace)

Returns an array of class names of other modules that it replaces.

Cadre\\Module\\Module
---------------------

[](#cadremodulemodule)

This is a base class that your module can extend. It contains default implementations of all methods from `Cadre\Module\ModuleInterface`.

### loader()

[](#loader)

This method is only defined on `Cadre\Module\Module` and returns the associated `Cadre\Module\ModuleLoaderInterface`.

This is so you can conditionally configure your module based on the existance of other modules.

```
public function define(Container $di)
{
    if ($this->loader()->loaded(OtherModule::class)) {
        $di->set('service', $di->lazyNew(OtherService::class);
    } else {
        $di->set('service', $di->lazyNew(DefaultService::class);
    }
}
```

Cadre\\Module\\ModuleLoaderInterface
------------------------------------

[](#cadremodulemoduleloaderinterface)

This interface extends `Aura\Di\ContainerConfigInterface` and defines three methods.

### loaded($name)

[](#loadedname)

Returns true or false if the module specified by `$name` has been loaded.

### isEnv($environment)

[](#isenvenvironment)

Returns true or false if the ModuleLoader was instanciated with the specified environment.

### isContext($context)

[](#iscontextcontext)

Returns true or false if the ModuleLoader was instanciated with the specified context.

Cadre\\Module\\ModuleLoader
---------------------------

[](#cadremodulemoduleloader)

This class does all the work. It contains default implementations of all methods from `Cadre\Module\ModuleInterface`.

### \_\_construct(array $modules, string $environment = '', string $context = '')

[](#__constructarray-modules-string-environment---string-context--)

When you create a new `ModuleLoader` you pass into it the modules you want to load.

You may also specify the environment you're running. When you specify a environment we will check for a method requiring modules when in that environment. For example if your environment is "dev" we will look for a method `requireDev`.

To generate the method name we convert a snake cased (ex: special\_environment) environment into a camel cased method name prefixed with "require" (ex: requireSpecialEnvironment).

You may also specify the context you're running. By default we do nothing with the context. However, you can query it via `isContext` method on the loader from inside a module. For example if your context is "web" you could query against it like `if ($this->loader()->isContext('web')) { }` and configure things differently.

### protected resolveDependencies()

[](#protected-resolvedependencies)

This method is called from `loaded`, `define` and `modify`.

It starts with the list of modules from the constructor and goes through them loading the modules and then adding require and optionally require{Environment} modules to the list to load.

Throws `Cadre\Module\ConflictingModuleException` if conflicting module is loaded. Throws `Cadre\Module\AlreadyReplacedException` if replaced module has already been replaced. Throws `Cadre\Module\AlreadyLoadedException` if replaced module has been loaded.

### define(Container $di)

[](#definecontainer-di)

Passes through to the `define` method on all loaded modules.

### modify(Container $di)

[](#modifycontainer-di)

Passes through to the `modify` method on all loaded modules.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~26 days

Recently: every ~1 days

Total

11

Last Release

3233d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/97c4de661b1a9718e83127e45b82b743076baf61bb9321708c9dfad7b02ad5a1?d=identicon)[andrewshell](/maintainers/andrewshell)

---

Top Contributors

[![andrewshell](https://avatars.githubusercontent.com/u/144136?v=4)](https://github.com/andrewshell "andrewshell (21 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/cadre-module/health.svg)

```
[![Health](https://phpackages.com/badges/cadre-module/health.svg)](https://phpackages.com/packages/cadre-module)
```

###  Alternatives

[based/momentum-trail

Fully typed frontend route helper for Laravel apps

80389.6k](/packages/based-momentum-trail)[kornrunner/secp256k1

Pure PHP secp256k1

37566.4k109](/packages/kornrunner-secp256k1)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
