Skip to content
Closed
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
13 changes: 13 additions & 0 deletions src/Doctrine/Common/Filter/SearchFilterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
use ApiPlatform\Doctrine\Common\PropertyHelperTrait;
use ApiPlatform\Exception\InvalidArgumentException;
use Psr\Log\LoggerInterface;
use Ramsey\Uuid\Uuid as RamseyUuid;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use Symfony\Component\Uid\Uuid as SymfonyUuid;

/**
* Trait for filtering the collection by given properties.
Expand Down Expand Up @@ -163,6 +165,17 @@ protected function hasValidValues(array $values, ?string $type = null): bool
if (null !== $value && \in_array($type, (array) self::DOCTRINE_INTEGER_TYPE, true) && false === filter_var($value, \FILTER_VALIDATE_INT)) {
return false;
}

if (null !== $value && \in_array($type, (array) self::DOCTRINE_UUID_TYPE, true)) {
if (class_exists(RamseyUuid::class)) {
return RamseyUuid::isValid($value);
}
if (class_exists(SymfonyUuid::class)) {
return SymfonyUuid::isValid($value);
}

return 1 === preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/', $value);
}
}

return true;
Expand Down
1 change: 1 addition & 0 deletions src/Doctrine/Odm/Filter/SearchFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ final class SearchFilter extends AbstractFilter implements SearchFilterInterface
use SearchFilterTrait;

public const DOCTRINE_INTEGER_TYPE = [MongoDbType::INTEGER, MongoDbType::INT];
public const DOCTRINE_UUID_TYPE = [MongoDbType::BINDATAUUID, MongoDbType::BINDATAUUIDRFC4122];

public function __construct(ManagerRegistry $managerRegistry, IriConverterInterface $iriConverter, ?IdentifiersExtractorInterface $identifiersExtractor, PropertyAccessorInterface $propertyAccessor = null, LoggerInterface $logger = null, array $properties = null, NameConverterInterface $nameConverter = null)
{
Expand Down
3 changes: 3 additions & 0 deletions src/Doctrine/Orm/Filter/SearchFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ManagerRegistry;
use Psr\Log\LoggerInterface;
use Ramsey\Uuid\Doctrine\UuidType as RamseyUuidType;
use Symfony\Bridge\Doctrine\Types\UuidType as SymfonyUuidType;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
Expand All @@ -40,6 +42,7 @@ final class SearchFilter extends AbstractFilter implements SearchFilterInterface
use SearchFilterTrait;

public const DOCTRINE_INTEGER_TYPE = Types::INTEGER;
public const DOCTRINE_UUID_TYPE = [RamseyUuidType::NAME, SymfonyUuidType::NAME];

public function __construct(ManagerRegistry $managerRegistry, IriConverterInterface $iriConverter, PropertyAccessorInterface $propertyAccessor = null, LoggerInterface $logger = null, array $properties = null, IdentifiersExtractorInterface $identifiersExtractor = null, NameConverterInterface $nameConverter = null)
{
Expand Down