ndoubismarck / cakephp-modules
Module support plugin for CakePHP
1.0.0
2022-03-30 06:49 UTC
Requires
- php: >=7.2
- ext-json: *
- cakephp/cakephp: ^4.0
Requires (Dev)
- cakephp/cakephp-codesniffer: ^4.5
- cakephp/debug_kit: ^4.5
- phpunit/phpunit: ^8.5 || ^9.3
README
This CakePHP plugin intends to provide a framework around modules. Modules are a set of reusable classes that can be accessed from anywhere within the application. The idea is to improve maintainability and keep code clean and modular.
Installation
You can install this plugin into your CakePHP application using Composer:
composer require ndoubismarck/cakephp-modules
Load the plugin by adding the following statement in your project's src/Application.php
:
public function bootstrap(): void { parent::bootstrap(); $this->addPlugin('Modules'); }
Baking modules
Bake a module by executing:
bin/cake bake module Example
This will create a module named Example
in modules/Example
Loading modules
The ModuleAwareTrait
provides functionality for loading module classes as properties of the host object
For example:
- In app controller
use Cake\Controller\Controller; use Modules\ModuleAwareTrait; /** * @property ExampleModule $ExampleModule */ class AppController extends Controller { use ModuleAwareTrait; public function initialize(): void { $this->loadModule('Example'); } }
- In any other class
use Modules\ModuleAwareTrait; /** * @property ExampleModule $ExampleModule */ class MyClass { use ModuleAwareTrait; public function __construct() { $this->loadModule('Example'); } }