Skip to content

Commit c01e10f

Browse files
authored
fix(hydra): remove dependency from ApiPlatform/Api dependency (#6154)
1 parent 79fe01b commit c01e10f

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/Hydra/Serializer/CollectionFiltersNormalizer.php

+14-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace ApiPlatform\Hydra\Serializer;
1515

1616
use ApiPlatform\Api\FilterInterface as LegacyFilterInterface;
17-
use ApiPlatform\Api\FilterLocatorTrait;
1817
use ApiPlatform\Api\ResourceClassResolverInterface as LegacyResourceClassResolverInterface;
1918
use ApiPlatform\Doctrine\Odm\State\Options as ODMOptions;
2019
use ApiPlatform\Doctrine\Orm\State\Options;
@@ -37,14 +36,14 @@
3736
*/
3837
final class CollectionFiltersNormalizer implements NormalizerInterface, NormalizerAwareInterface, CacheableSupportsMethodInterface
3938
{
40-
use FilterLocatorTrait;
39+
private ?ContainerInterface $filterLocator = null;
4140

4241
/**
4342
* @param ContainerInterface $filterLocator The new filter locator or the deprecated filter collection
4443
*/
4544
public function __construct(private readonly NormalizerInterface $collectionNormalizer, private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory, private readonly LegacyResourceClassResolverInterface|ResourceClassResolverInterface $resourceClassResolver, ContainerInterface $filterLocator)
4645
{
47-
$this->setFilterLocator($filterLocator);
46+
$this->filterLocator = $filterLocator;
4847
}
4948

5049
/**
@@ -159,4 +158,16 @@ private function getSearch(string $resourceClass, array $parts, array $filters):
159158

160159
return ['@type' => 'hydra:IriTemplate', 'hydra:template' => sprintf('%s{?%s}', $parts['path'], implode(',', $variables)), 'hydra:variableRepresentation' => 'BasicRepresentation', 'hydra:mapping' => $mapping];
161160
}
161+
162+
/**
163+
* Gets a filter with a backward compatibility.
164+
*/
165+
private function getFilter(string $filterId): LegacyFilterInterface|FilterInterface|null
166+
{
167+
if ($this->filterLocator && $this->filterLocator->has($filterId)) {
168+
return $this->filterLocator->get($filterId);
169+
}
170+
171+
return null;
172+
}
162173
}

0 commit comments

Comments
 (0)