ldc-boutique-cnc-sable/app/Casts/OrderReferenceCast.php

35 lines
986 B
PHP
Raw Permalink Normal View History

2026-06-14 21:32:07 +02:00
<?php
declare(strict_types=1);
namespace App\Casts;
use Domain\Models\ValueObjects\OrderReference;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
/**
* @implements CastsAttributes<OrderReference,OrderReference>
*/
class OrderReferenceCast implements CastsAttributes
{
/** @param array<string, mixed> $attributes */
public function get($model, string $key, $value, array $attributes): OrderReference
{
if ($value === null || ! is_string($value)) {
throw new \UnexpectedValueException('OrderReference cannot be null.');
}
return OrderReference::fromString($value);
2026-06-14 21:32:07 +02:00
}
/** @param array<string, mixed> $attributes */
public function set($model, string $key, $value, array $attributes): string
{
if (! $value instanceof OrderReference) {
throw new \UnexpectedValueException('The given value is not an instance of OrderReference.');
}
return (string) $value;
2026-06-14 21:32:07 +02:00
}
}