Refactor OrderReferenceCast to utilize base58 encoding for order references instead of UUID. This change improves compatibility with the new OrderReference implementation.
34 lines
986 B
PHP
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;
|
|
}
|
|
}
|