承接 zonneplan/laravel-module-loader 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

zonneplan/laravel-module-loader

Composer 安装命令:

composer require zonneplan/laravel-module-loader

包简介

Module loader for Laravel

README 文档

README

Latest Version on Packagist MIT Licensed Build Status Total Downloads

Laravel laravel-module-loader
5.8 ^1.0
6.0 ^1.0
7.0 ^1.0
8.0 ^2.0
9.0 ^3.0
10.0 ^4.0
11.0 ^5.0
12.0 ^6.0
13.0 ^7.0

The zonneplan/laravel-module-loader package provides an easy to use module loader which can be used to modulize your project.

How to use

First install the package, see the installation section.

Creating a new module:

  • Create a folder, for example: Modules in the app directory.
  • After that create another one, for example: User.
  • In the root of that folder insert a UserServiceProvider which extends our abstract Module class.
  • Implement the function getModuleNamespace() like:
namespace Modules\User;

use Zonneplan/ModuleLoader/Module;

class UserServiceProvider extends Module
{
    public function getModuleNamespace(): string
    {
        return 'user';
    }
}
  • Register the UserServiceProvider in the config/app.php file.
'providers' => [
    Modules\User\UserServiceProvider::class
]

Structure within the module:

The expected structure is seen below. Most of it is optional.

app
├── Modules
    ├──MyModule
       ├──Config
       ├──Console
       ├──Database
          ├──Factories
          ├──Migrations
       ├──Exceptions
       ├──Http
          ├──Controllers
          ├──Middleware
          ├──Requests
          ├──Resources
       ├──Resources
          ├──lang
          ├──views
       ├──Routes
          ├──web.php            
          ├──api.php            
          ├──channels.php       
          ├──console.php        
          ├──mcp.php        
       ├──MyModuleServiceProvider.php
       ├──tests

Access a view from the module:

To access a view from a module it will look like 'my-module::path.to.view'

For example:

// In a controller
view('user::index');

// In a blade file
@include('user::index');
@include('user::partials.form');

Registering Policies:

To register policies overwrite the $policies variable in the ServiceProvider of your module

For example:

protected $policies = [
    MyModel::class => MyModelPolicy::class,
];

Registering Middleware:

To register middleware overwrite the $middleware variable in the ServiceProvider of your module

For example:

protected $middleware = [
    'my-middleware' => MyMiddleware::class,
];

Registering Events & Listeners:

To register events & listeners overwrite the $listen variable in the ServiceProvider of your module

For example:

protected $listen = [
    MyEvent::class => [
        MyListener::class
    ],
];

Registering Event Subscribers:

To register event subscribers overwrite the $subscribe variable in the ServiceProvider of your module

For example:

protected $subscribe = [
    MySubscriber::class
];

Registering routes:

All modules will by default try to load all route files in the Routes folder. Any of the following files will be auto loaded:

routes.php api.php web.php mcp.php

Profiling module loading:

Module loading profiling is disabled by default. Publish the config file to enable it:

php artisan vendor:publish --tag=module-loader-config

The following environment variables are available:

MODULE_LOADER_PROFILING_ENABLED=false
MODULE_LOADER_PROFILING_DRIVER=log
MODULE_LOADER_PROFILING_INCLUDE_STEPS=false
MODULE_LOADER_PROFILING_SAMPLE_RATE=1.0
MODULE_LOADER_PROFILING_LOG_CHANNEL=null

Supported drivers:

  • log: writes structured timing records to the configured Laravel log channel.
  • callback: calls module-loader.profiling.reporter, which may be a callable or a class with a handle(array $measurement) method.
  • event: dispatches a Zonneplan\ModuleLoader\Events\ModuleProfiled event with the measurement.

The base register() and boot() methods are profiled when enabled. If include_steps is enabled, the built-in boot steps like config, translation, view, policy, route, and middleware loading are profiled separately. The sample_rate value is evaluated once per request or process, so sampled runs keep a complete module loading profile.

OpenTelemetry is intentionally not a dependency of this package. Applications that want OpenTelemetry spans can install open-telemetry/api and convert profiling measurements to spans from a callback reporter or a ModuleProfiled listener.

Requirements

This package requires at least Laravel 6 or higher, PHP 7.2 or higher

Installation

composer require zonneplan/laravel-module-loader

The package will automatically register itself.

Register the namespace: "Modules\\": "app/Modules" in composer.json like:

 "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Modules\\": "app/Modules"
        },
        ...

Authors

  • Aron Rotteveel
  • Dennis Stolmeijer
  • Wout Hoeve
  • Johnny Borg
  • Rick Gout
  • Thijs Nijholt

zonneplan/laravel-module-loader 适用场景与选型建议

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

它主要适用于以下技术方向: 「module」 「modules」 「loader」 「laravel」 「zonneplan」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 123.77k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 24
  • 点击次数: 24
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 24
  • Watchers: 8
  • Forks: 1
  • 开发语言: PHP

其他信息

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