29 lines
621 B
PHP
29 lines
621 B
PHP
<?php
|
|
|
|
namespace App\Domain\Model\Id;
|
|
|
|
final readonly class CarModelId
|
|
{
|
|
public function __construct(
|
|
public string $value
|
|
) {
|
|
if (!str_starts_with($value, 'carmodel_')) {
|
|
throw new \InvalidArgumentException('CarModelId must start with "carmodel_"');
|
|
}
|
|
}
|
|
|
|
public function __toString(): string
|
|
{
|
|
return $this->value;
|
|
}
|
|
|
|
public function equals(CarModelId $other): bool
|
|
{
|
|
return $this->value === $other->value;
|
|
}
|
|
|
|
public static function generate(): CarModelId
|
|
{
|
|
return new CarModelId(uniqid('carmodel_', true));
|
|
}
|
|
}
|