Skip to content

fix(hydra): remove dependency from ApiPlatform/Api dependency #6154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 1 commit
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
31 changes: 27 additions & 4 deletions src/Hydra/Serializer/CollectionFiltersNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@

namespace ApiPlatform\Hydra\Serializer;

use ApiPlatform\Api\FilterInterface as LegacyFilterInterface;
use ApiPlatform\Api\FilterLocatorTrait;
use ApiPlatform\Api\ResourceClassResolverInterface as LegacyResourceClassResolverInterface;
use ApiPlatform\Doctrine\Odm\State\Options as ODMOptions;
use ApiPlatform\Doctrine\Orm\State\Options;
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
use ApiPlatform\Metadata\FilterInterface;
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
use ApiPlatform\Metadata\ResourceClassResolverInterface;
Expand All @@ -37,8 +36,6 @@
*/
final class CollectionFiltersNormalizer implements NormalizerInterface, NormalizerAwareInterface, CacheableSupportsMethodInterface
{
use FilterLocatorTrait;

/**
* @param ContainerInterface $filterLocator The new filter locator or the deprecated filter collection
*/
Expand Down Expand Up @@ -159,4 +156,30 @@ private function getSearch(string $resourceClass, array $parts, array $filters):

return ['@type' => 'hydra:IriTemplate', 'hydra:template' => sprintf('%s{?%s}', $parts['path'], implode(',', $variables)), 'hydra:variableRepresentation' => 'BasicRepresentation', 'hydra:mapping' => $mapping];
}

private ?ContainerInterface $filterLocator = null;

/**
* Sets a filter locator with a backward compatibility.
*/
private function setFilterLocator(?ContainerInterface $filterLocator, bool $allowNull = false): void
{
if ($filterLocator instanceof ContainerInterface || (null === $filterLocator && $allowNull)) {
$this->filterLocator = $filterLocator;
} else {
throw new InvalidArgumentException(sprintf('The "$filterLocator" argument is expected to be an implementation of the "%s" interface%s.', ContainerInterface::class, $allowNull ? ' or null' : ''));
}
}

/**
* Gets a filter with a backward compatibility.
*/
private function getFilter(string $filterId): FilterInterface|null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's fine to keep this here imo we don't need the trait

{
if ($this->filterLocator && $this->filterLocator->has($filterId)) {
return $this->filterLocator->get($filterId);
}

return null;
}
}