Add modular layered architecture with Customers module
Introduce a modular monolith under app/Modules with Domain, Application, Infrastructure and Presentation layers. - Shared module: DomainException base, TransactionManager and an EventDispatcher that publishes events after commit. - Customers module: Customer entity, CustomerName and BusinessId (Y-tunnus checksum) value objects, RegisterCustomer/UpdateCustomer use cases, CustomerQueries read contract, Eloquent repository, and Livewire list and form pages with Finnish translations. - Pest arch tests enforce layer and module dependency rules for every module; Larastan (level 6) added as a dev dependency. - Raise Flux error text contrast to meet WCAG 2.2 AA. - Document the architecture in docs/architecture.md and CLAUDE.md. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Customers\Domain\Entities;
|
||||
|
||||
use App\Modules\Customers\Domain\Enums\CustomerType;
|
||||
use App\Modules\Customers\Domain\Exceptions\ConsumerCannotHaveBusinessId;
|
||||
use App\Modules\Customers\Domain\ValueObjects\BusinessId;
|
||||
use App\Modules\Customers\Domain\ValueObjects\CustomerName;
|
||||
|
||||
/**
|
||||
* A customer of the company: a business or a private consumer.
|
||||
*
|
||||
* Only the name is needed at job intake; other details are added later.
|
||||
*/
|
||||
final class Customer
|
||||
{
|
||||
private function __construct(
|
||||
private ?int $id,
|
||||
private CustomerName $name,
|
||||
private CustomerType $type,
|
||||
private ?BusinessId $businessId,
|
||||
) {
|
||||
self::ensureBusinessIdFitsType($type, $businessId);
|
||||
}
|
||||
|
||||
/**
|
||||
* A new customer that is not stored yet, so it has no id.
|
||||
*/
|
||||
public static function register(CustomerName $name, CustomerType $type, ?BusinessId $businessId = null): self
|
||||
{
|
||||
return new self(null, $name, $type, $businessId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuilds a stored customer. Used only by repositories.
|
||||
*/
|
||||
public static function reconstitute(int $id, CustomerName $name, CustomerType $type, ?BusinessId $businessId): self
|
||||
{
|
||||
return new self($id, $name, $type, $businessId);
|
||||
}
|
||||
|
||||
public function changeDetails(CustomerName $name, CustomerType $type, ?BusinessId $businessId): void
|
||||
{
|
||||
self::ensureBusinessIdFitsType($type, $businessId);
|
||||
|
||||
$this->name = $name;
|
||||
$this->type = $type;
|
||||
$this->businessId = $businessId;
|
||||
}
|
||||
|
||||
public function id(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function name(): CustomerName
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function type(): CustomerType
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function businessId(): ?BusinessId
|
||||
{
|
||||
return $this->businessId;
|
||||
}
|
||||
|
||||
private static function ensureBusinessIdFitsType(CustomerType $type, ?BusinessId $businessId): void
|
||||
{
|
||||
if ($type === CustomerType::Consumer && $businessId !== null) {
|
||||
throw new ConsumerCannotHaveBusinessId;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user