61 lines
1.9 KiB
PHP
61 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Filter;
|
|
|
|
use ApiPlatform\Doctrine\Orm\Filter\AbstractFilter;
|
|
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
|
|
use ApiPlatform\Metadata\Operation;
|
|
use App\Service\VersionedResourceService;
|
|
use Doctrine\ORM\QueryBuilder;
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
use Psr\Log\LoggerInterface;
|
|
use Symfony\Component\PropertyInfo\Type;
|
|
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
|
|
|
|
final class ResourceVersionResourceFilter extends AbstractFilter
|
|
{
|
|
public function __construct(
|
|
private VersionedResourceService $versionedResourceService,
|
|
protected ?ManagerRegistry $managerRegistry,
|
|
?LoggerInterface $logger = null,
|
|
protected ?array $properties = null,
|
|
protected ?NameConverterInterface $nameConverter = null,
|
|
) {
|
|
parent::__construct($managerRegistry, $logger, $properties, $nameConverter);
|
|
}
|
|
|
|
protected function filterProperty(
|
|
string $property,
|
|
$value,
|
|
QueryBuilder $queryBuilder,
|
|
QueryNameGeneratorInterface $queryNameGenerator,
|
|
string $resourceClass,
|
|
?Operation $operation = null,
|
|
array $context = [],
|
|
): void {
|
|
return;
|
|
}
|
|
|
|
public function getDescription(string $resourceClass): array
|
|
{
|
|
$description = [];
|
|
foreach ($this->properties as $property => $strategy) {
|
|
$description["$property"] = [
|
|
'property' => $property,
|
|
'type' => Type::BUILTIN_TYPE_STRING,
|
|
'required' => true,
|
|
'description' => 'The name of the resource.',
|
|
'schema' => [
|
|
'type' => Type::BUILTIN_TYPE_STRING,
|
|
'enum' => $this->versionedResourceService->getNames(),
|
|
],
|
|
'openapi' => [
|
|
'allowEmptyValue' => false,
|
|
],
|
|
];
|
|
}
|
|
|
|
return $description;
|
|
}
|
|
}
|