feat: suite des rêgles de phparkitect + début d'un domain Shared avec les interfaces CQRS
This commit is contained in:
parent
e444d79101
commit
fe92e53be7
@@ -12,7 +12,7 @@ use Arkitect\Rules\Rule;
|
|||||||
|
|
||||||
return static function (Config $config): void {
|
return static function (Config $config): void {
|
||||||
$domainClassSet = ClassSet::fromDir(__DIR__ . '/src/Domain');
|
$domainClassSet = ClassSet::fromDir(__DIR__ . '/src/Domain');
|
||||||
$domains = ['Manga', 'Reader', 'Scraping'];
|
$businessDomains = ['Manga', 'Reader', 'Scraping'];
|
||||||
|
|
||||||
// Classes PHP standards et utilitaires
|
// Classes PHP standards et utilitaires
|
||||||
$standardExceptions = [
|
$standardExceptions = [
|
||||||
@@ -39,41 +39,40 @@ return static function (Config $config): void {
|
|||||||
|
|
||||||
$rules = [$namespaceRule];
|
$rules = [$namespaceRule];
|
||||||
|
|
||||||
// Les classes de Application ne doivent pas dépendre de l'infrastructure
|
// Règles spécifiques pour le domaine Shared
|
||||||
$rules[] = Rule::allClasses()
|
$rules[] = Rule::allClasses()
|
||||||
->that(new ResideInOneOfTheseNamespaces('App\Domain\*\Application'))
|
->that(new ResideInOneOfTheseNamespaces('App\Domain\Shared'))
|
||||||
->should(new NotDependsOnTheseNamespaces('App\Domain\*\Infrastructure'))
|
->should(new NotHaveDependencyOutsideNamespace(
|
||||||
->because('la couche Application ne doit pas dépendre de l\'infrastructure');
|
'App\Domain\Shared',
|
||||||
|
$standardExceptions
|
||||||
// Les classes de Domain ne doivent pas dépendre de l'infrastructure ou de l'application
|
|
||||||
$rules[] = Rule::allClasses()
|
|
||||||
->that(new ResideInOneOfTheseNamespaces('App\Domain\*\Domain'))
|
|
||||||
->should(new NotDependsOnTheseNamespaces(
|
|
||||||
'App\Domain\*\Infrastructure',
|
|
||||||
'App\Domain\*\Application'
|
|
||||||
))
|
))
|
||||||
->because('la couche Domain ne doit pas dépendre de l\'infrastructure ou de l\'application');
|
->because('le domaine Shared ne doit dépendre de personne');
|
||||||
|
|
||||||
// Génération des règles pour chaque domaine
|
|
||||||
foreach ($domains as $domain) {
|
|
||||||
// Récupération des autres domaines
|
|
||||||
$otherDomains = array_filter($domains, fn($d) => $d !== $domain);
|
|
||||||
$otherDomainsNamespaces = array_map(fn($d) => "App\Domain\\$d\*", $otherDomains);
|
|
||||||
|
|
||||||
|
// Génération des règles pour chaque domaine métier
|
||||||
|
foreach ($businessDomains as $domain) {
|
||||||
// Règle pour la couche Domain
|
// Règle pour la couche Domain
|
||||||
$rules[] = Rule::allClasses()
|
$rules[] = Rule::allClasses()
|
||||||
->that(new ResideInOneOfTheseNamespaces("App\Domain\\$domain\Domain"))
|
->that(new ResideInOneOfTheseNamespaces("App\Domain\\$domain\Domain"))
|
||||||
->should(new NotHaveDependencyOutsideNamespace("App\Domain\\$domain\Domain", $standardExceptions))
|
->should(new NotHaveDependencyOutsideNamespace(
|
||||||
->because("la couche Domain de $domain ne doit dépendre que de ses propres classes et des exceptions autorisées");
|
"App\Domain\\$domain\Domain",
|
||||||
|
$standardExceptions
|
||||||
|
))
|
||||||
|
->because("la couche Domain de $domain ne doit dépendre que de ses propres classes, des contrats partagés et des exceptions autorisées");
|
||||||
|
|
||||||
// Règle pour la couche Application
|
// Règle pour la couche Application
|
||||||
$rules[] = Rule::allClasses()
|
$rules[] = Rule::allClasses()
|
||||||
->that(new ResideInOneOfTheseNamespaces("App\Domain\\$domain\Application"))
|
->that(new ResideInOneOfTheseNamespaces("App\Domain\\$domain\Application"))
|
||||||
->should(new NotHaveDependencyOutsideNamespace(
|
->should(new NotHaveDependencyOutsideNamespace(
|
||||||
"App\Domain\\$domain",
|
"App\Domain\\$domain",
|
||||||
array_merge($standardExceptions, $externalDependencies)
|
array_merge($standardExceptions, $externalDependencies, ['App\Domain\Shared\Contract'])
|
||||||
))
|
))
|
||||||
->because("la couche Application de $domain ne peut dépendre que de son propre domaine et des dépendances autorisées");
|
->because("la couche Application de $domain ne peut dépendre que de son propre domaine, des contrats partagés et des dépendances autorisées");
|
||||||
|
|
||||||
|
// Interdiction explicite pour l'Application d'accéder à l'Infrastructure
|
||||||
|
$rules[] = Rule::allClasses()
|
||||||
|
->that(new ResideInOneOfTheseNamespaces("App\Domain\\$domain\Application"))
|
||||||
|
->should(new NotDependsOnTheseNamespaces("App\Domain\\$domain\Infrastructure"))
|
||||||
|
->because("la couche Application de $domain ne doit jamais dépendre de l'Infrastructure, même au sein de son propre domaine");
|
||||||
}
|
}
|
||||||
|
|
||||||
$config->add($domainClassSet, ...$rules);
|
$config->add($domainClassSet, ...$rules);
|
||||||
|
|||||||
15
src/Domain/Shared/Contract/CommandHandlerInterface.php
Normal file
15
src/Domain/Shared/Contract/CommandHandlerInterface.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Domain\Shared\Contract;
|
||||||
|
|
||||||
|
interface CommandHandlerInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @template T of CommandInterface
|
||||||
|
* @param T $command
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle(CommandInterface $command): void;
|
||||||
|
}
|
||||||
9
src/Domain/Shared/Contract/CommandInterface.php
Normal file
9
src/Domain/Shared/Contract/CommandInterface.php
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Domain\Shared\Contract;
|
||||||
|
|
||||||
|
interface CommandInterface
|
||||||
|
{
|
||||||
|
}
|
||||||
16
src/Domain/Shared/Contract/QueryHandlerInterface.php
Normal file
16
src/Domain/Shared/Contract/QueryHandlerInterface.php
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Domain\Shared\Contract;
|
||||||
|
|
||||||
|
interface QueryHandlerInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @template T of QueryInterface
|
||||||
|
* @template R of ResponseInterface
|
||||||
|
* @param T $query
|
||||||
|
* @return R
|
||||||
|
*/
|
||||||
|
public function handle(QueryInterface $query): ResponseInterface;
|
||||||
|
}
|
||||||
9
src/Domain/Shared/Contract/QueryInterface.php
Normal file
9
src/Domain/Shared/Contract/QueryInterface.php
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Domain\Shared\Contract;
|
||||||
|
|
||||||
|
interface QueryInterface
|
||||||
|
{
|
||||||
|
}
|
||||||
9
src/Domain/Shared/Contract/ResponseInterface.php
Normal file
9
src/Domain/Shared/Contract/ResponseInterface.php
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Domain\Shared\Contract;
|
||||||
|
|
||||||
|
interface ResponseInterface
|
||||||
|
{
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user