-
-
Notifications
You must be signed in to change notification settings - Fork 893
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
feat(doctrine): search filters like laravel eloquent filters #6865
base: main
Are you sure you want to change the base?
feat(doctrine): search filters like laravel eloquent filters #6865
Conversation
fc01fcd
to
093aede
Compare
7bfc697
to
a9d3bd6
Compare
|
||
$queryBuilder | ||
->andWhere(\sprintf('%s.%s = :%s', $alias, $property, $parameterName)) | ||
->setParameter($parameterName, $resource->getId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Properties should be available inside the $context['parameter']
:
If the parameter has :property
you should get an array of properties inside Parameter::extraProperties
if not use Parameter::property
and in the end the Parameter::key
.
The only thing we need to do here is to check if our doctrine entity has that property/association (re-use some of the code that we already have for that).
e3b56c8
to
55cb458
Compare
55cb458
to
06f47dd
Compare
|
||
public function getOpenApiParameters(Parameter $parameter): OpenApiParameter|array|null | ||
{ | ||
return new OpenApiParameter(name: $parameter->getKey().'[]', in: 'query', style: 'deepObject', explode: true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should hardcode parameter value style in the filter, I would rather be able to define the default strategy to use in the configuration and fallback to the default
return new OpenApiParameter(name: $parameter->getKey().'[]', in: 'query', style: 'deepObject', explode: true); | |
return new OpenApiParameter(name: $parameter->getKey(), in: 'query'); |
should be suffisant for most of the cases.
Any thoughts @soyuka ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you define your own OpenApiParameter this will not get called AFAIK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getType(string $doctrineType): string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TO DO: remove
if ( | ||
null === $value | ||
|| !$this->isPropertyEnabled($property, $resourceClass) | ||
|| !$this->isPropertyMapped($property, $resourceClass, true) | ||
) { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: try to remove
foreach ($context['filters'] as $property => $value) { | ||
$this->filterProperty($this->denormalizePropertyName($property), $value, $queryBuilder, $queryNameGenerator, $resourceClass, $operation, $context); | ||
} | ||
} | ||
|
||
public function getDescription(string $resourceClass): array | ||
{ | ||
throw new RuntimeException('Not implemented.'); | ||
} | ||
|
||
/** | ||
* Determines whether the given property is enabled. | ||
*/ | ||
protected function isPropertyEnabled(string $property, string $resourceClass): bool | ||
{ | ||
if (null === $this->properties) { | ||
// to ensure sanity, nested properties must still be explicitly enabled | ||
return !$this->isPropertyNested($property, $resourceClass); | ||
} | ||
|
||
return \array_key_exists($property, $this->properties); | ||
} | ||
|
||
protected function denormalizePropertyName(string|int $property): string | ||
{ | ||
if (!$this->nameConverter instanceof NameConverterInterface) { | ||
return (string) $property; | ||
} | ||
|
||
return implode('.', array_map($this->nameConverter->denormalize(...), explode('.', (string) $property))); | ||
} | ||
|
||
public function hasManagerRegistry(): bool | ||
{ | ||
return $this->managerRegistry instanceof ManagerRegistry; | ||
} | ||
|
||
public function getManagerRegistry(): ManagerRegistry | ||
{ | ||
return $this->managerRegistry; | ||
} | ||
|
||
public function setManagerRegistry(ManagerRegistry $managerRegistry): void | ||
{ | ||
$this->managerRegistry = $managerRegistry; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: try to remove
main
Completes #6775.
TODO:
Filters support
Extra work