Skip to content

Commit

Permalink
Merge pull request #1019 from spiral/bugfix/uuid-caster
Browse files Browse the repository at this point in the history
[spiral/filters] Fix method supports in UuidCaster
  • Loading branch information
butschster committed Dec 1, 2023
2 parents cc5594a + 05188b6 commit ac995f5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Filters/src/Model/Mapper/UuidCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public function supports(\ReflectionNamedType $type): bool
$this->interfaceExists = \interface_exists(UuidInterface::class);
}

return $this->interfaceExists && $this->implements($type->getName(), UuidInterface::class);
return $this->interfaceExists &&
!$type->isBuiltin() &&
$this->implements($type->getName(), UuidInterface::class);
}

public function setValue(FilterInterface $filter, \ReflectionProperty $property, mixed $value): void
Expand All @@ -40,6 +42,10 @@ private function implements(string $haystack, string $interface): bool
return true;
}

if (!\class_exists($haystack)) {
return false;
}

foreach ((array)\class_implements($haystack) as $implements) {
if ($implements === $interface) {
return true;
Expand Down
1 change: 1 addition & 0 deletions src/Filters/tests/Mapper/UuidCasterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static function supportsDataProvider(): \Traversable
{
$ref = new \ReflectionClass(UserFilter::class);

yield 'string' => [$ref->getProperty('name'), false];
yield 'enum' => [$ref->getProperty('status'), false];
yield 'uuid' => [$ref->getProperty('groupUuid'), true];
}
Expand Down

0 comments on commit ac995f5

Please sign in to comment.