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,62 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Customers\Domain\ValueObjects;
|
||||
|
||||
use App\Modules\Customers\Domain\Exceptions\InvalidBusinessId;
|
||||
|
||||
/**
|
||||
* Finnish business ID (Y-tunnus), e.g. 0737546-2.
|
||||
*
|
||||
* Seven digits, a hyphen and a check digit. Old six-digit IDs are
|
||||
* accepted and padded with a leading zero.
|
||||
*/
|
||||
final readonly class BusinessId
|
||||
{
|
||||
private const array WEIGHTS = [7, 9, 10, 5, 8, 4, 2];
|
||||
|
||||
public string $value;
|
||||
|
||||
public function __construct(string $value)
|
||||
{
|
||||
$value = trim($value);
|
||||
|
||||
if (preg_match('/^(\d{6,7})-(\d)$/', $value, $matches) !== 1) {
|
||||
throw new InvalidBusinessId;
|
||||
}
|
||||
|
||||
$digits = str_pad($matches[1], 7, '0', STR_PAD_LEFT);
|
||||
|
||||
if (self::checkDigitFor($digits) !== (int) $matches[2]) {
|
||||
throw new InvalidBusinessId;
|
||||
}
|
||||
|
||||
$this->value = "{$digits}-{$matches[2]}";
|
||||
}
|
||||
|
||||
public function equals(self $other): bool
|
||||
{
|
||||
return $this->value === $other->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns null when no valid check digit exists (remainder 1).
|
||||
*/
|
||||
private static function checkDigitFor(string $digits): ?int
|
||||
{
|
||||
$sum = 0;
|
||||
|
||||
foreach (str_split($digits) as $index => $digit) {
|
||||
$sum += (int) $digit * self::WEIGHTS[$index];
|
||||
}
|
||||
|
||||
$remainder = $sum % 11;
|
||||
|
||||
return match ($remainder) {
|
||||
0 => 0,
|
||||
1 => null,
|
||||
default => 11 - $remainder,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Customers\Domain\ValueObjects;
|
||||
|
||||
use App\Modules\Customers\Domain\Exceptions\InvalidCustomerName;
|
||||
|
||||
final readonly class CustomerName
|
||||
{
|
||||
public const int MAX_LENGTH = 255;
|
||||
|
||||
public string $value;
|
||||
|
||||
public function __construct(string $value)
|
||||
{
|
||||
$value = trim(preg_replace('/\s+/u', ' ', $value) ?? $value);
|
||||
|
||||
if ($value === '' || mb_strlen($value) > self::MAX_LENGTH) {
|
||||
throw new InvalidCustomerName;
|
||||
}
|
||||
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function equals(self $other): bool
|
||||
{
|
||||
return $this->value === $other->value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user