Skip to content

Commit c6a522b

Browse files
author
Florian Krämer
committed
Fixing layer rules
1 parent d53cb62 commit c6a522b

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

docs/Rules.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,15 @@ src/Capability/
190190
- Format: `LayerName: [AllowedDependency1, AllowedDependency2, ...]`
191191
- Default layers: Domain, Application, Infrastructure, Presentation
192192
- You can define any custom layer names you need
193-
- `allowedCrossModulePatterns`: **Required** - Regex patterns for class names that can be imported across modules.
193+
- `allowedCrossModulePatterns`: **Required** - Regex patterns for fully qualified class names that can be imported across modules.
194194
- **No defaults** - you must explicitly configure which classes can cross module boundaries
195-
- Common patterns: `/Facade$/`, `/FacadeInterface$/`, `/Input$/`, `/Result$/`
196-
- Each pattern is a regex that matches against the class name (not the full namespace)
195+
- Patterns match against the **fully qualified class name** (e.g., `App\Capability\User\UserFacade`)
196+
- Common patterns:
197+
- `/Facade$/` - Classes ending with "Facade"
198+
- `/FacadeInterface$/` - Classes ending with "FacadeInterface"
199+
- `/Input$/` - Classes ending with "Input"
200+
- `/Result$/` - Classes ending with "Result"
201+
- `/^App\\Capability\\.*\\Application\\Queries\\.*$/` - All classes in Application\Queries namespace
197202
- Empty array `[]` = no cross-module imports allowed (complete module isolation)
198203

199204
**Example Violations:**
@@ -308,7 +313,22 @@ allowedCrossModulePatterns:
308313
- '/^I[A-Z]/' # Any interface starting with "I" (e.g., IUserService)
309314
```
310315

311-
**Note:** Patterns are matched against the class name only (not the full namespace), so `UserManagementFacade` matches `/Facade$/`.
316+
**Pattern Matching Examples:**
317+
318+
Patterns match against the **fully qualified class name**:
319+
320+
```php
321+
// Class: App\Capability\UserManagement\UserManagementFacade
322+
'/Facade$/' // ✅ Matches (ends with Facade)
323+
'/^App\\Capability\\.*\\Facade$/' // ✅ Matches (full namespace pattern)
324+
325+
// Class: App\Capability\User\Application\Queries\FindUser\FindUserQuery
326+
'/Query$/' // ✅ Matches (ends with Query)
327+
'/^App\\Capability\\.*\\Application\\Queries\\.*$/' // ✅ Matches (namespace pattern)
328+
'/^App\\Capability\\User\\.*$/' // ✅ Matches (specific module)
329+
```
330+
331+
This allows you to be very specific about which classes can cross module boundaries based on their location in the namespace hierarchy.
312332

313333
## Circular Module Dependency Rule
314334

0 commit comments

Comments
 (0)