carthage-software/mago
Mago is an extremely fast PHP linter, formatter, and static analyzer written in Rust. It helps teams catch issues early, enforce consistent style, and improve code quality across projects, with multiple install options like script, Homebrew, Composer, and Cargo.
+++ title = "Guard" description = "guard 的功能,以及它的两个部分如何分工。" nav_order = 10 nav_section = "工具" nav_subsection = "Guard" +++
mago guard 在 PHP 项目中强制执行架构边界和结构约定。它涵盖了与 deptrac 和 arkitect 相同的范围,集成于一个二进制文件中,运行在 Mago 的解析器之上。
该工具有两部分:边界 guard 验证分层之间的依赖,而结构 guard 在符号自身上执行约定。
边界 guard 验证依赖边。它确保应用各部分之间只通过你明确允许的方式互相调用,从而让领域层不被基础设施泄露污染,UI 也无法越过应用层。
典型规则:
Domain 层不能依赖任何其他层。UI 层可以依赖 Application,但反过来不行。结构 guard 在符号自身上执行约定:它们的名称、修饰符、父类型、attribute,以及它们所在命名空间的形态。
典型规则:
App\Http\Controllers 中的所有类都必须是 final 且以 Controller 结尾。Domain 下的接口必须以 Interface 结尾。enum 定义。How can I help you explore Laravel packages today?