Download the PHP package cadre/module without Composer
On this page you can find all versions of the php package cadre/module. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package module
Cadre.Module
This is a lightweight module system based on 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.
Installation and Autoloading
This package is installable and PSR-4 autoloadable via Composer as cadre/module.
Alternatively, download a release, or clone this repository, then map the
Cadre\Module\
namespace to the package src/
directory.
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
To run the unit tests at the command line, issue composer install
and then
vendor/bin/phpunit
at the package root. This requires Composer to be
available as composer
, and PHPUnit to be available as vendor/bin/phpunit
.
This package attempts to comply with PSR-1, PSR-2, and PSR-4. If you notice compliance oversights, please send a patch via pull request.
Example
Cadre\Module\ModuleInterface
This interface extends Aura\Di\ContainerConfigInterface
and defines four methods.
require()
Returns an array of class names of other modules that it requires.
conflict()
Returns an array of class names of other modules that it conflicts with.
replace()
Returns an array of class names of other modules that it replaces.
Cadre\Module\Module
This is a base class that your module can extend. It contains default implementations of all
methods from Cadre\Module\ModuleInterface
.
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.
Cadre\Module\ModuleLoaderInterface
This interface extends Aura\Di\ContainerConfigInterface
and defines three methods.
loaded($name)
Returns true or false if the module specified by $name
has been loaded.
isEnv($environment)
Returns true or false if the ModuleLoader was instanciated with the specified environment.
isContext($context)
Returns true or false if the ModuleLoader was instanciated with the specified context.
Cadre\Module\ModuleLoader
This class does all the work. It contains default implementations of all
methods from Cadre\Module\ModuleInterface
.
__construct(array $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()
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)
Passes through to the define
method on all loaded modules.
modify(Container $di)
Passes through to the modify
method on all loaded modules.