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]>
44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Fakes;
|
|
|
|
use App\Modules\Customers\Domain\Contracts\CustomerRepository;
|
|
use App\Modules\Customers\Domain\Entities\Customer;
|
|
use App\Modules\Customers\Domain\ValueObjects\BusinessId;
|
|
|
|
class InMemoryCustomerRepository implements CustomerRepository
|
|
{
|
|
/**
|
|
* @var array<int, Customer>
|
|
*/
|
|
public array $customers = [];
|
|
|
|
private int $nextId = 1;
|
|
|
|
public function findById(int $id): ?Customer
|
|
{
|
|
return isset($this->customers[$id]) ? clone $this->customers[$id] : null;
|
|
}
|
|
|
|
public function save(Customer $customer): Customer
|
|
{
|
|
$id = $customer->id() ?? $this->nextId++;
|
|
$stored = Customer::reconstitute($id, $customer->name(), $customer->type(), $customer->businessId());
|
|
|
|
$this->customers[$id] = $stored;
|
|
|
|
return clone $stored;
|
|
}
|
|
|
|
public function isBusinessIdTaken(BusinessId $businessId, ?int $exceptCustomerId = null): bool
|
|
{
|
|
foreach ($this->customers as $id => $customer) {
|
|
if ($id !== $exceptCustomerId && $customer->businessId()?->equals($businessId)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|