-
-
Notifications
You must be signed in to change notification settings - Fork 47
Open
Labels
enhancementNew feature or requestNew feature or request
Description
I recently implemented a simple pattern that allows us to split our architectural rules across multiple files, making our phparkitect.php
setup easier to scale and maintain as our codebase grows.
Here’s a simplified version of what we’re doing:
<?php
declare(strict_types=1);
use Arkitect\ClassSet;
use Arkitect\CLI\Config;
// Auto-require all PHP files in the architecture folder
foreach (glob(__DIR__.'/architecture/*.php') as $file) {
require_once $file;
}
return static function (Config $config): void {
$classSet = ClassSet::fromDir(__DIR__.'/src');
$allRules = [];
foreach (get_defined_functions()['user'] as $fn) {
if (str_ends_with($fn, 'architecturerules')) {
foreach ($fn() as $rule) {
$allRules[] = $rule;
}
}
}
$config->add($classSet, ...$allRules);
};
Each file inside the /architecture folder defines a single function (e.g. clockArchitectureRules
, quotingArchitectureRules
, etc.) that returns an iterable of rules.
I'm sharing this in case it could inspire a similar built-in feature, or if we'd be interested in documenting this pattern as a recommended practice.
Happy to hear your thoughts!
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity