定制 mnabialek/laravel-modular 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mnabialek/laravel-modular

Composer 安装命令:

composer require mnabialek/laravel-modular

包简介

Allows creating Laravel modules for better project structure

README 文档

README

Build Status Coverage Status Scrutinizer Code Quality StyleCI

This module makes managing your Laravel 5 application much more easier. No more putting dozens or hundreds of files into single directory.

Now you can create for your Laravel 5 application multiple modules and each of them will have its own structure (in the way you decide).

Supported version

To install in Laravel 5.3+ use this branch, however to install in Laravel < 5.3 please refer to version 0.1.

Installation

  1. For Laravel 5.3+ run

    composer require mnabialek/laravel-modular 0.2.*

    in console to install this module.

  2. Open config/app.php and:

    • Add

       Mnabialek\LaravelModular\Providers\ModularServiceProvider::class,

      in same section (providers)

    • Add

      'Modular' => Mnabialek\LaravelModular\Facades\Modular::class,

      into aliases section

  3. Run

    php artisan vendor:publish --provider="Mnabialek\LaravelModular\Providers\ModularServiceProvider"

    in your console to publish default configuration files, sample app files (published in app/Core) and sample stubs files

  4. In default seeder database/seeds/DatabaseSeeder at the end of run method add:

     Modular::seed($this);
  5. In app/Providers/RouteServiceProvider.php at the end of map function add

    \Modular::loadRoutes($this->app['router'], 'web');
    \Modular::loadRoutes($this->app['router'], 'api');
  6. In database/factories/ModelFactory.php (this step applies only to Laravel 5.1+) add at the end of file:

    Modular::loadFactories($factory);

Getting started

To get started run:

php artisan module:make TestModule

This command will create your TestModule module structure. Open directory and look at its structure. As you see some files uses app/Core abstract classes (those file where created during installation).

First decide, whether you want to use app/Core files or not. If not, you can remove this directory. Go to resources/stubs/modular and look at sample stubs. You can now alter them depending on your needs (you can remove all usages of app/Core files`, create new stubs etc.

Now open config/modular.php file, go to stubs_groups section and adjust default structure - you can specify here what directories and files should be created for default modules. When you finish, run:

php artisan module:make TestModule2

Now this new module will be created according to your needs. Great - you created your first module as you wanted!

Customization

This module is highly customizable. The concept is based on using group stubs and in each group you can define which directories should be created and which files should be created (you can omit directories if you want when in those directories you want to place files - they will be automatically created).

You can create multiple stubs groups, you can configure many things. Just go to config/modular.php and look at sample settings and comments in this file - if you want to change them, just do it, generate new sample module (or files) and see what will happen.

For all stubs groups the following replacements will be done for filename and file content (assuming you haven't changed default { and } separators to custom ones):

  • {module} - this will be changed into module name
  • {class} - this will be changed into used name of module/submodule/file
  • {moduleNamespace} - this will be changed into module namespace
  • {namespace} - this will be changed into main namespace of modules directory
  • {plural|lower} - this will be changed into plural name of module (lowercase)

Routing customization

By default for each module you can load 2 routing files - web.php and api.php if you followed installation instructions. However, you might also decide to use single routing file for each module. In this case use

\Modular::loadRoutes($this->app['router']);

only in step 5 of installation.

You can also decide to put the whole routing files in groups as defaults in Laravel 5.3. In this case you can do it also in RouteServiceProvider - in such case please remember to alter your routes stubs to not apply same middleware twice because it will cause unexpected issues in your Laravel application.

Available commands

module:make

This command creates new modules. You can create one module or multiple modules at once.

Example usage:

php artisan module:make Product Order

You can control what is created when running this command in config/modular.php in stubs_groups section. You can pass optional stub group name using --group=test in case you want to use multiple types of modules.

module:files

Allow to create files in module that already exists.

Example usage:

php artisan module:make Product Camera Radio

You can control what is created when running this command in config/simplemodules.php in stubs_groups section. You can pass optional stub group name using --group=test.

By default it creates "submodule" in existing module.

module:create-migration

Creates migration file in given module

Example usage:

php artisan module:make-migration Product create_products_table

You can also use optional --type and --table options to set table and type of migration (you can of course create own types if you want) in order to create migration with template for given type, for example:

php artisan module:make-migration Product create_camera_table --table=cameras --type=create

it will create migration that is of type create - so in up method there will be creating cameras table and in down method deleting cameras table

module:seed

Runs main seeder for given modules. You need to remember that only main seeder will be launched. In case you have multiple seeders in single module, you should manually run extra seeders in main module seeder.

Example usage:

php artisan module:seed Product Order

migrate

This module register modules paths so when you run default Laravel migrate command all migrations will be run (both general and for all active modules)

Example usage:

php artisan migrate

db:seed

If you done all steps in Installation section when you run db:seed command all main seeds from active modules will be run

Example usage:

php artisan db:seed

Optimization

By default (you can customize it in config file), all modules are created with 2 options - active and routes - by default they are both set to true. The general rule for all modules options is like this - if option is set for module in configuration file, it will be used, otherwise some extra checks will be made to calculate. It does not apply to active option - in case it's missing it's assumed to be true.

Available options for modules:

  • active - whether module is active
  • provider - whether module has service provider
  • factory - whether module has model factory
  • routes - whether module has routes.php file
  • seeder - whether module has seeder file

In addition to use custom routing files, you can use also additional settings:

  • api_routes - whether module has api.php routing file
  • web_routes - whether module has web.php routing file

Prefix of option should match the name of routing file, if you would like additional extra.php routing file, you could use extra_routes option.

Be aware in case option set in configuration file won't be valid, some unexpected situations might happen. For example, if you set provider to false but later you will add service provider to module, it won't he loaded unless you change provider option to true or you remove it completely from configuration file for this module.

Release notes

Please refer to Changelog

Licence

This package is licenced under the MIT license

mnabialek/laravel-modular 适用场景与选型建议

mnabialek/laravel-modular 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 713 次下载、GitHub Stars 达 21, 最近一次更新时间为 2016 年 08 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 mnabialek/laravel-modular 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mnabialek/laravel-modular 我们能提供哪些服务?
定制开发 / 二次开发

基于 mnabialek/laravel-modular 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 713
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 21
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 21
  • Watchers: 6
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-08-11