mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-09-04 11:45:00 +02:00
40 lines
748 B
PHP
40 lines
748 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\StateCasts;
|
|
|
|
use Filament\Schemas\Components\StateCasts\Contracts\StateCast;
|
|
use Illuminate\Support\Uri;
|
|
|
|
class UriStateCast implements StateCast
|
|
{
|
|
public function __construct(
|
|
protected bool $isNullable = true,
|
|
) {}
|
|
|
|
/**
|
|
* @param string|null $state
|
|
*/
|
|
public function get(mixed $state): ?Uri
|
|
{
|
|
if ($this->isNullable && blank($state)) {
|
|
return null;
|
|
}
|
|
|
|
return Uri::of($state);
|
|
}
|
|
|
|
/**
|
|
* @param Uri|null $state
|
|
*/
|
|
public function set(mixed $state): ?string
|
|
{
|
|
if ($this->isNullable && blank($state)) {
|
|
return null;
|
|
}
|
|
|
|
return $state->__toString();
|
|
}
|
|
}
|