Files
2026-11-26 16:43:55 +02:00

32 lines
643 B
PHP

<?php
declare(strict_types=1);
namespace App\Modules\Machines\Domain\ValueObjects;
use App\Modules\Machines\Domain\Exceptions\InvalidMachineName;
/**
* A machine's name, e.g. "Suurkuvatulostin 1".
*/
final readonly class MachineName
{
public const int MAX_LENGTH = 150;
public string $value;
/**
* @throws InvalidMachineName
*/
public function __construct(string $value)
{
$value = trim(preg_replace('/\s+/u', ' ', $value) ?? $value);
if ($value === '' || mb_strlen($value) > self::MAX_LENGTH) {
throw new InvalidMachineName;
}
$this->value = $value;
}
}