bchalier/laravel-modules
Composer 安装命令:
composer require bchalier/laravel-modules
包简介
Module management in laravel.
README 文档
README
Introduction
This package is made to allow you to divide everything laravel allow you to make but divided in modules.
I ended up making this package even if other are doing exactly the same thing because after trying to work with them, after some time I always found them incomplete, no longer maintained, not respecting laravel standards and ideas (having module:make-controller command instead of make:controller, another file structure etc) so after trying 3-4 modules I got frustrated and starting making my own package trying to not reproduce the mistakes I saw earlier.
Here are the result, I hove you will like it as much as I do ! This is my first public package so please fell free to send me any suggestions, questions, bug report, feature request you may have !
Versioning
This package follow Semantic Versioning, see : https://semver.org/
Installation
You can install the package via composer:
composer require bchalier/laravel-modules
Commands
All the standard make commands are extended with a -M|module=[module alias] options, here an example :
php artisan make:model -Muser UnicornModel
As it is an extend and not a replacement all options are available and working (or should be !)
php artisan make:model -cfmr -Muser UnicornModel
The package also add some commands for dealing with the modules themselves :
make:module {modules*} {?--fill}: make one or more new module, use the --fill option to add all possible elements in the newly created module.module:install {modules*}: install one or more module (in bdd)module:reinstall {modules*}: reinstall the module (update bdd), usefulmodule:uninstall {modules*}: uninstall one or more module (keep files, clean bdd)module:enable {modules*}: load the module (the files will always be loader by composer but the providers, routes etc will only if the module is enabled)module:disable {modules*}: disable the modulemodule:delete {modules*}: delete the bdd AND FILES of the module, be careful, this command will delete all your module files and uninstall it.
Structure
The insides of a module is pretty much just a normal laravel, here an example (make it yourselves with php artisan make:module test --fill) :
modules/Test/
├── app
│ ├── Broadcasting
│ │ └── DummyChannel.php
│ ├── Console
│ │ ├── Commands
│ │ │ └── DummyCommand.php
│ │ └── Kernel.php
│ ├── Events
│ │ └── DummyEvent.php
│ ├── Exceptions
│ │ └── DummyException.php
│ ├── Http
│ │ ├── Controllers
│ │ │ └── DummyController.php
│ │ ├── Middleware
│ │ │ └── DummyMiddleware.php
│ │ ├── Requests
│ │ │ └── DummyRequest.php
│ │ └── Resources
│ │ └── DummyResource.php
│ ├── Jobs
│ │ └── DummyJob.php
│ ├── Listener
│ │ └── DummyListener.php
│ ├── Mail
│ │ └── DummyMail.php
│ ├── Models
│ │ └── DummyModel.php
│ ├── Notification
│ │ └── DummyNotification.php
│ ├── Observers
│ │ └── DummyObserver.php
│ ├── Policies
│ │ └── DummyPolicy.php
│ ├── Providers
│ │ └── DummyProvider.php
│ ├── Rules
│ │ └── DummyRule.php
│ └── Services
│ └── DummyService.php
├── composer.json
├── config
│ ├── superconfig.php
├── database
│ ├── factories
│ │ └── DummyFactory.php
│ ├── migrations
│ │ └── 2019_07_04_105604_dummy_migration.php
│ └── seeds
│ ├── DatabaseSeeder.php
│ └── DummySeeder.php
├── resources
│ └── lang
│ ├── en
│ │ └── exceptions.php
│ └── fr
│ └── exceptions.php
├── routes
│ ├── api.php
│ ├── channels.php
│ ├── console.php
│ └── web.php
└── tests
├── Feature
│ └── DummyTest.php
└── Unit
└── DummyTest.php
Composer
At the root of your module you have a composer.json, same as the one you know with just a bit extra, you will find an example bellow.
IT DOES NOT INSTALL PACKAGES, would you want to look into wikimedia/composer-merge-plugin but it's not compatible with composer 2.
{
"name": "Core",
"description": "A perfect description for a brand new module !",
"keywords": [
"module",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.1"
},
"extra": {
"laravel-modules": {
"name": "Core",
"alias": "core",
"description": "The core module, for module management.",
"install": {
"migrate": true,
"createDir": "modules"
},
"loadParameters": {
"compartmentalize": {
"migrations": true
}
},
"providers": [
"SystemModules\\Core\\App\\Providers\\EventServiceProvider",
"SystemModules\\Core\\App\\Providers\\CommandExtendProvider"
],
"aliases": {
"Test": "Illuminate\\Support\\Facades\\App",
"ModulesManager": "SystemModules\\Core\\Services\\ModulesManager"
}
}
}
}
Here what that mean :
- name : literally whatever you want, simply a cosmetic value.
- alias : this is what you will be using in every command.
- description : a description, duh.
- install.migrate : migrate the migrations on module installation.
- install.createDir : create a dir of you liking on installation.
- loadParameters.compartmentalize.migrations : isolate the migration from the rest of your app, in this example the migration for the modules table will not be called on any of the
migratecommands except for themigrate:freshbecause it drop all tables regardless of migrations, you'll have to install all your modules again after this one. - providers : list all the providers you want to load in your module.
- aliases : list all the aliases you want to have in your module.
Remember that you will have to call php artisan module:reinstall YOUR_MODULE_ALIAS for updating the settings above.
.env
Here are some settings added that may be used in your .env :
API_PREFIX='web' // a prefix for all the web routes, '' by default
WEB_PREFIX='api' // a prefix for all the api routes, 'api' by default
MODULES_CONFIG_PATH='modules.json' // the location of the global config file (it store the installed modules)
That's pretty much it, there probably plenty of room for improvement so I'm waiting your comments on this !
bchalier/laravel-modules 适用场景与选型建议
bchalier/laravel-modules 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 23.5k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2019 年 06 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「package」 「module」 「modules」 「laravel」 「split」 「bchalier」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bchalier/laravel-modules 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bchalier/laravel-modules 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bchalier/laravel-modules 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This is Paymorrow module for OXID eShop.
Analysis module for finding problematical shop data.
yii2 swiper slider
An interactive tour through the TYPO3 backend.
Simple ASCII output of array data
统计信息
- 总下载量: 23.5k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-06-10