Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6de1a1f

Browse files
vinceAmstoutzsoyuka
andcommittedDec 24, 2024
feat(doctrine): doctrine filters like laravel eloquent filters (api-platform#6775)
* feat(doctrine): doctrine filters like laravel eloquent filters * fix: allow multiple validation with :property placeholder * fix: correct escape filter condition * fix: remove duplicated block --------- Co-authored-by: soyuka <soyuka@users.noreply.github.com>
1 parent 71a7413 commit 6de1a1f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2111
-96
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <dunglas@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Doctrine\Common\Filter;
15+
16+
use Doctrine\Persistence\ManagerRegistry;
17+
18+
interface ManagerRegistryAwareInterface
19+
{
20+
public function hasManagerRegistry(): bool;
21+
22+
public function getManagerRegistry(): ManagerRegistry;
23+
24+
public function setManagerRegistry(ManagerRegistry $managerRegistry): void;
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <dunglas@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Doctrine\Common\Filter;
15+
16+
use ApiPlatform\Metadata\Parameter;
17+
use ApiPlatform\OpenApi\Model\Parameter as OpenApiParameter;
18+
19+
trait PropertyPlaceholderOpenApiParameterTrait
20+
{
21+
/**
22+
* @return array<OpenApiParameter>|null
23+
*/
24+
public function getOpenApiParameters(Parameter $parameter): ?array
25+
{
26+
if (str_contains($parameter->getKey(), ':property')) {
27+
$parameters = [];
28+
$key = str_replace('[:property]', '', $parameter->getKey());
29+
foreach (array_keys($parameter->getExtraProperties()['_properties'] ?? []) as $property) {
30+
$parameters[] = new OpenApiParameter(name: \sprintf('%s[%s]', $key, $property), in: 'query');
31+
}
32+
33+
return $parameters;
34+
}
35+
36+
return null;
37+
}
38+
}

0 commit comments

Comments
 (0)
Please sign in to comment.