Skip to content

Commit a7bc769

Browse files
committed
fix: apply last reviews made in th latest pr
Continues the work at api-platform#7079 and before at api-platform#6865
1 parent 1c0da55 commit a7bc769

File tree

11 files changed

+88
-15
lines changed

11 files changed

+88
-15
lines changed

src/Doctrine/Odm/Filter/IriFilter.php

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
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\Odm\Filter;
15+
16+
use ApiPlatform\Metadata\OpenApiParameterFilterInterface;
17+
use ApiPlatform\Metadata\Operation;
18+
use ApiPlatform\Metadata\Parameter;
19+
use ApiPlatform\Metadata\ParameterProviderFilterInterface;
20+
use ApiPlatform\OpenApi\Model\Parameter as OpenApiParameter;
21+
use ApiPlatform\State\Provider\IriConverterParameterProvider;
22+
use Doctrine\ODM\MongoDB\Aggregation\Builder;
23+
24+
class IriFilter implements FilterInterface, OpenApiParameterFilterInterface, ParameterProviderFilterInterface
25+
{
26+
public function apply(Builder $aggregationBuilder, string $resourceClass, ?Operation $operation = null, array &$context = []): void
27+
{
28+
if (!$parameter = $context['parameter'] ?? null) {
29+
return;
30+
}
31+
32+
\assert($parameter instanceof Parameter);
33+
34+
$value = $parameter->getValue();
35+
if (!\is_array($value)) {
36+
$value = [$value];
37+
}
38+
39+
// TODO: do something for nested properties?
40+
$matchField = $parameter->getProperty();
41+
42+
$aggregationBuilder
43+
->match()
44+
->field($matchField)
45+
->in($value);
46+
}
47+
48+
public static function getParameterProvider(): string
49+
{
50+
return IriConverterParameterProvider::class;
51+
}
52+
53+
public function getOpenApiParameters(Parameter $parameter): OpenApiParameter|array|null
54+
{
55+
return new OpenApiParameter(name: $parameter->getKey().'[]', in: 'query', style: 'deepObject', explode: true);
56+
}
57+
58+
public function getDescription(string $resourceClass): array
59+
{
60+
return [];
61+
}
62+
}

src/Doctrine/Orm/Filter/ExactSearchFilter.php

Whitespace-only changes.

src/Doctrine/Orm/Filter/PartialSearchFilter.php

Whitespace-only changes.

src/GraphQl/Tests/Type/TypeConverterTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030
use GraphQL\Type\Definition\EnumType;
3131
use GraphQL\Type\Definition\ObjectType;
3232
use GraphQL\Type\Definition\Type as GraphQLType;
33+
use PHPUnit\Framework\Attributes\DataProvider;
34+
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
3335
use PHPUnit\Framework\TestCase;
3436
use Prophecy\Argument;
3537
use Prophecy\PhpUnit\ProphecyTrait;
3638
use Prophecy\Prophecy\ObjectProphecy;
3739
use Symfony\Component\PropertyInfo\Type as LegacyType;
3840
use Symfony\Component\TypeInfo\Type;
39-
use PHPUnit\Framework\Attributes\DataProvider;
40-
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
4141

4242
/**
4343
* @author Alan Poulain <[email protected]>

src/GraphQl/Type/FieldsBuilder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
4646
use Symfony\Component\TypeInfo\Type;
4747
use Symfony\Component\TypeInfo\Type\CollectionType;
48-
use Symfony\Component\TypeInfo\TypeIdentifier;
4948
use Symfony\Component\TypeInfo\Type\ObjectType;
49+
use Symfony\Component\TypeInfo\TypeIdentifier;
5050

5151
/**
5252
* Builds the GraphQL fields.

tests/Fixtures/TestBundle/Document/Chicken.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
class Chicken
2222
{
2323
#[ODM\Id]
24-
private string $id;
24+
private ?string $id = null;
2525

2626
#[ODM\Field(type: 'string')]
2727
private string $name;

tests/Fixtures/TestBundle/Document/ChickenCoop.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@
1313

1414
namespace ApiPlatform\Tests\Fixtures\TestBundle\Document;
1515

16-
use ApiPlatform\Doctrine\Orm\Filter\IriFilter;
16+
use ApiPlatform\Doctrine\Odm\Filter\IriFilter;
1717
use ApiPlatform\Metadata\GetCollection;
1818
use ApiPlatform\Metadata\QueryParameter;
19-
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Chicken;
2019
use Doctrine\Common\Collections\ArrayCollection;
2120
use Doctrine\Common\Collections\Collection;
2221
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
2322

2423
#[ODM\Document]
25-
#[GetCollection(normalizationContext: ['hydra_prefix' => false], parameters: ['chickens' => new QueryParameter(filter: new IriFilter())])]
24+
#[GetCollection(
25+
normalizationContext: ['hydra_prefix' => false],
26+
parameters: ['chickens' => new QueryParameter(filter: new IriFilter())])
27+
]
2628
class ChickenCoop
2729
{
2830
#[ODM\Id]

tests/Fixtures/TestBundle/Document/Company.php

+10-4
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,22 @@
2222
use Symfony\Component\Serializer\Annotation\Groups;
2323

2424
#[ApiResource]
25-
#[GetCollection()]
25+
#[GetCollection]
2626
#[Get]
2727
#[Post]
28-
#[ApiResource(uriTemplate: '/employees/{employeeId}/rooms/{roomId}/company/{companyId}', uriVariables: ['employeeId' => ['from_class' => Employee::class, 'from_property' => 'company']])]
28+
#[ApiResource(
29+
uriTemplate: '/employees/{employeeId}/rooms/{roomId}/company/{companyId}',
30+
uriVariables: ['employeeId' => ['from_class' => Employee::class, 'from_property' => 'company']]
31+
)]
2932
#[Get]
30-
#[ApiResource(uriTemplate: '/employees/{employeeId}/company', uriVariables: ['employeeId' => ['from_class' => Employee::class, 'from_property' => 'company']])]
33+
#[ApiResource(
34+
uriTemplate: '/employees/{employeeId}/company',
35+
uriVariables: ['employeeId' => ['from_class' => Employee::class, 'from_property' => 'company']]
36+
)]
3137
#[ODM\Document]
3238
class Company
3339
{
34-
#[ODM\Id(strategy: 'INCREMENT', type: 'int')]
40+
#[ODM\Id(type: 'int', strategy: 'INCREMENT')]
3541
private ?int $id = null;
3642

3743
#[ODM\Field]

tests/Fixtures/TestBundle/Entity/Chicken.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Doctrine\ORM\Mapping as ORM;
1818

1919
#[ORM\Entity]
20-
#[Get()]
20+
#[Get]
2121
class Chicken
2222
{
2323
#[ORM\Id]

tests/Fixtures/TestBundle/Entity/ChickenCoop.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,18 @@
2121
use Doctrine\ORM\Mapping as ORM;
2222

2323
#[ORM\Entity]
24-
#[GetCollection(normalizationContext: ['hydra_prefix' => false], parameters: ['chickens' => new QueryParameter(filter: new IriFilter())])]
24+
#[GetCollection(
25+
normalizationContext: ['hydra_prefix' => false],
26+
parameters: ['chickens' => new QueryParameter(filter: new IriFilter())]
27+
)]
2528
class ChickenCoop
2629
{
2730
#[ORM\Id]
2831
#[ORM\GeneratedValue]
2932
#[ORM\Column(type: 'integer')]
3033
private ?int $id = null;
3134

32-
#[ORM\OneToMany(mappedBy: 'chickenCoop', targetEntity: Chicken::class, cascade: ['persist'])]
35+
#[ORM\OneToMany(targetEntity: Chicken::class, mappedBy: 'chickenCoop', cascade: ['persist'])]
3336
private Collection $chickens;
3437

3538
public function __construct()

tests/Fixtures/TestBundle/Entity/Company.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use Symfony\Component\Serializer\Annotation\Groups;
2323

2424
#[ApiResource]
25-
#[GetCollection()]
25+
#[GetCollection]
2626
#[Get]
2727
#[Post]
2828
#[ApiResource(

0 commit comments

Comments
 (0)