Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/Descriptors/Values.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function mixed(null|string|Closure $attribute = null): ValueMixed
/**
* @param null|string|Closure(T):mixed $attribute
*
* @return ValueEnum<T>
* @return ValueEnum<T, mixed>
*/
protected function enum(null|string|Closure $attribute = null): ValueEnum
{
Expand All @@ -110,10 +110,9 @@ protected function struct(Closure $attribute): ValueStruct
}

/**
* @template U
* @param Value<U> $type
* @param Value<T> $type
* @param null|string|Closure(T):(array<mixed>|null) $attribute
* @return ValueArray<T, U>
* @return ValueArray<T, mixed>
*/
protected function arrayOf(Value $type, null|string|Closure $attribute = null): ValueArray
{
Expand Down
18 changes: 18 additions & 0 deletions src/Descriptors/Values/ValueEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,28 @@

/**
* @template T
* @template U extends UnitEnum|BackedEnum
* @extends Value<T>
*/
class ValueEnum extends Value
{
/**
* @var class-string<U>|null
*/
protected null|string $type = null;

/**
* Define the type of elements in the array
*
* @param class-string<U> $type
* @return $this<T, U>
*/
public function of(string $type): static
{
$this->type = $type;
return $this;
}

protected function value(mixed $of, Request $request): mixed
{
if ($of instanceof BackedEnum) return $of->value;
Expand Down