定制 drmovi/phpstan-laravel-module-boundaries 二次开发

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

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

drmovi/phpstan-laravel-module-boundaries

Composer 安装命令:

composer require drmovi/phpstan-laravel-module-boundaries

包简介

PHPStan extension to enforce Laravel module boundaries and prevent cross-module imports

README 文档

README

A PHPStan extension that enforces module boundaries in Laravel applications to maintain bounded contexts and prevent unwanted cross-module dependencies.

Features

  • Detects and prevents cross-module imports between Laravel modules
  • Supports shared modules that can be imported by any module
  • Configurable via Laravel project's composer.json
  • Works with PHPStan 2.0+

Installation

Install the extension via Composer:

composer require --dev drmovi/phpstan-laravel-module-boundaries

Configuration

1. Laravel Project Configuration

In your Laravel project's composer.json, add the following configuration:

{
    "extra": {
        "modules": {
            "path": "app/Modules"
        },
        "phpstan-laravel-module-boundaries": {
            "shared": ["shared", "auth"]
        }
    }
}
  • laravel-module.path: The path to your modules directory relative to the project root
  • phpstan-laravel-module-boundaries.shared: Array of module names that are considered "shared" and can be imported by any module

2. PHPStan Configuration

The extension is automatically loaded when installed. No additional PHPStan configuration is required.

Rules

Module Boundary Rule

This rule enforces the following boundaries:

  1. Same Module: Files within a module can import from the same module ✅
  2. Shared Modules: Any module can import from modules listed in the shared configuration ✅
  3. Shared to Shared: Shared modules can import from other shared modules ✅
  4. Cross-Module: Non-shared modules cannot import from other non-shared modules ❌

Example

Given the following module structure:

app/Modules/
├── User/
│   └── UserService.php
├── Order/
│   └── OrderService.php
├── shared/
│   └── SharedHelper.php
└── auth/
    └── AuthService.php

With configuration:

{
    "extra": {
        "modules": {
            "path": "app/Modules"
        },
        "phpstan-laravel-module-boundaries": {
            "shared": ["shared", "auth"]
        }
    }
}

Allowed Imports ✅

// In User/UserService.php
use App\Modules\User\UserRepository;     // Same module
use App\Modules\shared\SharedHelper;     // From shared module
use App\Modules\auth\AuthService;        // From shared module
// In shared/SharedHelper.php
use App\Modules\auth\AuthService;        // Shared to shared

Forbidden Imports ❌

// In User/UserService.php
use App\Modules\Order\OrderService;      // Cross-module import
// In Order/OrderService.php
use App\Modules\User\UserService;        // Cross-module import

Error Messages

When a boundary violation is detected, PHPStan will report an error like:

Module "User" cannot import "App\Modules\Order\OrderService" from module "Order". 
Cross-module imports are only allowed from shared modules (shared, auth).

Requirements

  • PHP 8.4+
  • PHPStan 2.0+
  • Laravel project with modular structure

License

MIT License. See LICENSE file for details.

drmovi/phpstan-laravel-module-boundaries 适用场景与选型建议

drmovi/phpstan-laravel-module-boundaries 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 12 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-28