ldc-mesbr-app/src/Domain/Models/ValueObjects/GS1.php
2026-09-24 14:29:26 +02:00

33 lines
738 B
PHP

<?php
declare(strict_types=1);
namespace Domain\Models\ValueObjects;
use Domain\Enums\BarcodeFormat;
use Shared\DDD\Models\Equatable;
final readonly class GS1 implements \Stringable, Equatable
{
public function __construct(
public string $value,
public BarcodeFormat $format
) {
$trimmed = mb_trim($this->value);
if ($trimmed === '') {
throw new \DomainException('GS1 value cannot be empty.');
}
}
#[\Override]
public function equals(mixed $other): bool
{
return $other instanceof self && $this->value === $other->value && $this->format === $other->format;
}
public function __toString(): string
{
return $this->value;
}
}