-
Notifications
You must be signed in to change notification settings - Fork 1
/
phparkitect.php
46 lines (38 loc) · 1.78 KB
/
phparkitect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
declare(strict_types=1);
use Arkitect\ClassSet;
use Arkitect\CLI\Config;
use Arkitect\Expression\ForClasses\HaveNameMatching;
use Arkitect\Expression\ForClasses\ResideInOneOfTheseNamespaces;
use Arkitect\RuleBuilders\Architecture\Architecture;
use Arkitect\Rules\Rule;
return static function (Config $config): void {
$allClasses = ClassSet::fromDir(__DIR__.'/src');
$exagonalRules = Architecture::withComponents()
->component('Domain')->definedBy('App\Domain\*')
->component('Application')->definedBy('App\Application\*')
->component('Infrastructure')->definedBy('App\Infrastructure\*')
->where('Domain')->shouldNotDependOnAnyComponent()
->where('Application')->mayDependOnComponents('Domain')
->where('Infrastructure')->mayDependOnComponents('Domain', 'Application')
->rules();
$layeredRules = Architecture::withComponents()
->component('Entity')->definedBy('App\Entity\*')
->component('Repository')->definedBy('App\Repository\*')
->component('Service')->definedBy('App\Service\*')
->component('Controller')->definedBy('App\Controller\*')
->where('Entity')->shouldNotDependOnAnyComponent()
->where('Repository')->mayDependOnComponents('Entity')
->where('Service')->mayDependOnComponents('Entity', 'Repository')
->where('Controller')->mayDependOnComponents('Entity', 'Service')
->rules();
$namingRules = [];
$namingRules[] = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\Controller'))
->should(new HaveNameMatching('*Controller'))
->because('we want uniform naming');
$config
->add($allClasses, ...$exagonalRules)
->add($allClasses, ...$layeredRules)
->add($allClasses, ...$namingRules);
};