-
-
Notifications
You must be signed in to change notification settings - Fork 868
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(serializer): support for getSupportedTypes (symfony 6.3) (#5671)
- Loading branch information
Showing
4 changed files
with
97 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
tests/Fixtures/TestBundle/ApiResource/Issue5648/CustomFilter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue5648; | ||
|
||
use ApiPlatform\Doctrine\Orm\Filter\AbstractFilter; | ||
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface; | ||
use ApiPlatform\Metadata\Operation; | ||
use Doctrine\ORM\Query\Expr\Join; | ||
use Doctrine\ORM\QueryBuilder; | ||
|
||
class CustomFilter extends AbstractFilter | ||
{ | ||
protected function filterProperty(string $property, $value, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, Operation $operation = null, array $context = []): void | ||
{ | ||
if ('custom' !== $property) { | ||
return; | ||
} | ||
|
||
$alias = $queryBuilder->getRootAliases()[0]; | ||
$secondAlias = $queryNameGenerator->generateJoinAlias('relatedDummies'); | ||
|
||
$joinCondition = $queryBuilder->expr()->like(sprintf('%s.name', $secondAlias), ':param'); | ||
|
||
$queryBuilder->join(sprintf('%s.relatedDummies', $alias), $secondAlias, Join::WITH, $joinCondition) | ||
->setParameter('param', '%'.$value.'%') | ||
->andWhere('1=1'); // problem only gets triggered when there is a where part. | ||
} | ||
|
||
public function getDescription(string $resourceClass): array | ||
{ | ||
return []; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
tests/Fixtures/TestBundle/ApiResource/Issue5648/DummyResource.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\Issue5648; | ||
|
||
use ApiPlatform\Doctrine\Orm\State\Options; | ||
use ApiPlatform\Metadata\ApiFilter; | ||
use ApiPlatform\Metadata\ApiProperty; | ||
use ApiPlatform\Metadata\ApiResource; | ||
use ApiPlatform\Metadata\Get; | ||
use ApiPlatform\Metadata\GetCollection; | ||
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy; | ||
|
||
#[ApiResource( | ||
operations: [ | ||
new GetCollection(uriTemplate: '/dummy_ressource_with_custom_filter', itemUriTemplate: '/dummy_ressource_with_custom_filter/{id}'), | ||
new Get(uriTemplate: '/dummy_ressource_with_custom_filter/{id}', uriVariables: ['id']), | ||
], | ||
stateOptions: new Options(entityClass: Dummy::class) | ||
)] | ||
#[ApiFilter(CustomFilter::class)] | ||
class DummyResource | ||
{ | ||
#[ApiProperty(identifier: true)] | ||
public ?int $id = null; | ||
|
||
public string $name; | ||
|
||
public array $relatedDummies; | ||
} |