2dojo / module_manager
Requires
- 2dojo/module: 0.*
- laravel/framework: ~5.5
Requires (Dev)
- mockery/mockery: ^0.9.7
- orchestra/testbench: ~3.5
- phpunit/phpunit: ~6.0
This package is not auto-updated.
Last update: 2024-11-11 00:46:42 UTC
README
Table of contents
Installation
The Module Manager can be installed via composer:
composer require 2dojo/module_manager
This package uses Laravel auto-discovery so the ServiceProvider and the Facade automatically register itself.
After you installed this package you have to call the ModuleManager facade initializeModules method in you AppServiceProvider boot method.
<?php namespace App\Providers; ... class AppServiceProvider extends ServiceProvider { public function boot() { ModuleManager::initializeModules(); } }
If you want to store the module options in database you need to publish the migrations and config
php artisan vendor:publish --provider="TwoDojo\ModuleManager\ModuleManagerServiceProvider"
Run the migrations
php artisan migrate
And finally change the registry entry in the configuration to database
// config/module_manager.php 'registry' => 'database'
Module Development
You can create your modules in a separated composer package or in your laravel project for example in the app/Modules directory.
<?php namespace App\Modules; use TwoDojo\Module\AbstractModule; class ExampleModule extends AbstractModule { /** * @var string The module display name */ protected $name = 'ExampleModule'; }
After that you have to register the module in the ModuleManager for example in your AppServiceProvider register method or if you create a separated composer package you can register it in your package ServiceProvider boot method.
<?php namespace App\Providers; ... class PackageServiceProvider extends ServiceProvider { public function boot() { ModuleManager::registerModule(ExampleModule::class); ... } }
Module Manager Methods
registerModule
/** * Register a module to the module manager. * * @param string $moduleClass The module class * @return bool */ public function registerModule(string $moduleClass) : bool
initializeModules
/** * Initialize the registered modules */ public function initializeModules()
enableModule
/** * Enable a module * * @param $uniqueName The module unique name * @return bool */ public function enableModule($uniqueName) : bool
disableModule
/** * Disable a module * * @param string $uniqueName The module unique name * @return bool */ public function disableModule($uniqueName) : bool