megaads/clara
Composer 安装命令:
composer require megaads/clara
包简介
Module management in Laravel
README 文档
README
A module management in Laravel
System requirements
- PHP: >=5.6
- Laravel Framework: >=5.4
Installation
Clara is packed as a composer package. So it can be installed quickly:
-
Require the composer package
composer require megaads/clara -
Register the provider:
Megaads\Clara\Providers\ModuleServiceProvider -
Register the facade:
Megaads\Clara\Facades\ModuleFacade -
Autoloading
By default, Module classes are not loaded automatically. You can autoload your modules in composer.json
{
"autoload": {
"psr-4": {
"App\\": "app/",
"Modules\\": "app/Modules"
}
},
"extra": {
"merge-plugin": {
"include": [
"app/Modules/*/module.json"
]
}
}
}
- Publish Clara configurations
To override Clara default configuration options, you will need to publish Clara configuration file to the application's config directory.
php artisan vendor:publish --provider="Megaads\Clara\Providers\ModuleServiceProvider"
Module Management
Create module
php artisan module:make <ModuleName> ...
Naming conventions
Module names should follow UpperCamelCase syntax (without any space characters). For example: FacebookComment
and module namespace in kebab-case that correspond to a module name in CamelCase. For example: facebook-comment
Folder structure
app
│
└───Modules
└───ModuleName
│
└───Config
│ app.php
│
└───Controllers
│ Controller.php
│ ...
│
└───Helpers
│ helper.php
│ ...
│
└───Middlewares
│ ExampleMiddleware.php
│ ...
│
└───Models
│ ...
│
└───Resources
│ Views
│ Assets
│ ...
│
└───Routes
│ routes.php
│ ...
│
└───Kernel.php
│
└───module.json
│
└───start.php
module.json: the module configuration file is based oncomposer.jsonform. All properties in themodule.jsonwill be merged tocomposer.jsonof the project.start.php: the module's start file that will be loaded every requests. So module actions, module views... can be registered in this file.
Module installing
Install a module using the module name
php artisan module:install <ModuleName>
Clara takes the name of the module that requested to search for it in the app repository that you have registered in config/clara.php configuration, after downloading the module files, Clara adds the module configuration to the module.json file
Install module list from module.json
php artisan module:install
This will searches and downloads the modules listed in module.json from the app repository into the app/Modules/ directory
Install a module from a zip file or an URL
php artisan module:install <ModuleZipFilePath> <ModuleZipFileURL> ...
Enable a module
php artisan module:enable <ModuleName> ...
Disable a module
php artisan module:disable <ModuleName> ...
Remove a module
php artisan module:remove <ModuleName> ...
Remove all modules
php artisan module:remove-all
Module Action
Fire a action
Using PHP
Module::action('action_name', [params]);
Using blade statement
@action('action_name', [params])
Handle a action
Module::onAction('action_name', function ($params) { }, PRIORITY);
Handle a action using a controller
Module::onAction('action_name', 'Modules\Example\Controllers\HomeController@action', PRIORITY);
By default, Clara supplies actions:
- module_made
- module_loaded
- module_disabled
- module_enabled
- module_removed
- module_removed_all
Module View
Register a view
Using PHP
Module::view('view_name', [params], IS_MULTI_LAYER);
Module::view('view_name', 'This is a view placeholder', IS_MULTI_LAYER);
Module::view('view_name', function() { return 'This is a view placeholder'; }, IS_MULTI_LAYER);
Using blade statement
@view('view_name', [params])
Handle a view
Module::onView('view_name', function ($params) { return view('{module-namespace}:home.index'); }, PRIORITY);
Handle a view using a controller
Module::onView('view_name', 'Modules\ExampleModule\Controllers\HomeController@index', PRIORITY);
Module variable
Register a variable
Using PHP
$variable = Module::variable('handle', $default, PRIORITY);
Using blade statement
@variable('variable_name', 'handle', $default);
Handle a variable
Module::onVariable('hanlde', function ($params) { }, PRIORITY, NUUM_OF_PARAM);
Module Assets
Clara will create a symbol link from module asset directory app/Modules/{ModuleName}/Resources/Assets to public/modules/{module-namespace} while a module was installed, made or enabled.
Include a module asset
Using PHP
<script type="text/javascript" src="<?= Module::asset('{module-namespace}/js/demo.js') ?>"></script>
Using blade statement
<script type="text/javascript" src="@asset('{module-namespace}/js/demo.js')"></script>
Create module asset link manually
php artisan module:asset:link <ModuleName>
Create module asset link manually for all activated modules
php artisan module:asset:link --all
Module Configurations
All of the configuration files for the module are stored in the {ModuleName}/Config directory
Accessing Configuration Values
Sometimes you may need to access configuration values at run-time. You may do so using the Config class
Config::get('{module-namespace}::app.message', 'hello world');
Module Utility Methods
Get all modules
$modules = Module::all();
Get the current module
$module = Module::this();
Get module options
$option = Module::option('option.name');
Set module option
$option = Module::option('option.name', 'option.value');
License
The Clara is open-sourced software licensed under the MIT license
Contact us / Instant feedback
Email: info@megaads.vn | phult.contact@gmail.com
If you find a bug, please report it here on Github
megaads/clara 适用场景与选型建议
megaads/clara 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 932 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 08 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「module」 「laravel」 「modular」 「refactor」 「lumen」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 megaads/clara 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 megaads/clara 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 megaads/clara 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Silverstripe content blocks module
Enterprise-Grade Modular Architecture for Laravel Applications - A powerful Laravel package that revolutionizes application development with robust Service Repository Pattern, Dynamic Module Management, and 50+ Artisan commands for scalable, maintainable applications.
Create laravel modular app using laravel modular plugin
bootstrap select field module implementing http://silviomoreto.github.io/bootstrap-select/
Yii2 module to manage website content. Kind of a CMS...
Alfabank REST API integration
统计信息
- 总下载量: 932
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-08-13