ldc-boutique-cnc-sable/app/Casts/OrderReferenceCast.php
Jérémy Munsch 713c937890
fix(casts): update OrderReferenceCast to use base58 encoding
Refactor OrderReferenceCast to utilize base58 encoding for order references instead of UUID.
This change improves compatibility with the new OrderReference implementation.
2026-10-27 16:17:28 +01:00

34 lines
986 B
PHP

<?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);
}
/** @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;
}
}