forked from api-platform/core
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
223 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,7 +136,7 @@ public function setNormalizer(NormalizerInterface $normalizer): void | |
* @param FilterInterface[] $filters | ||
* @param array<string, Parameter> $parameters | ||
*/ | ||
private function getSearch(string $resourceClass, array $parts, array $filters, array|Parameters|null $parameters, string $hydraPrefix): array | ||
private function getSearch(string $resourceClass, array $parts, array $filters, ?Parameters $parameters, string $hydraPrefix): array | ||
Check failure on line 139 in src/Hydra/Serializer/CollectionFiltersNormalizer.php GitHub Actions / PHPStan (PHP 8.3)
|
||
{ | ||
$variables = []; | ||
$mapping = []; | ||
|
@@ -153,9 +153,11 @@ private function getSearch(string $resourceClass, array $parts, array $filters, | |
continue; | ||
} | ||
|
||
if (!($property = $parameter->getProperty()) && ($filterId = $parameter->getFilter()) && ($filter = $this->getFilter($filterId))) { | ||
foreach ($filter->getDescription($resourceClass) as $variable => $description) { | ||
// This is a practice induced by PHP and is not necessary when implementing URI template | ||
if (($filterId = $parameter->getFilter()) && \is_string($filterId) && ($filter = $this->getFilter($filterId))) { | ||
$description = $filter->getDescription($resourceClass); | ||
|
||
foreach ($description as $variable => $description) { | ||
// // This is a practice induced by PHP and is not necessary when implementing URI template | ||
if (str_ends_with((string) $variable, '[]')) { | ||
continue; | ||
} | ||
|
@@ -171,10 +173,12 @@ private function getSearch(string $resourceClass, array $parts, array $filters, | |
$mapping[] = $m; | ||
} | ||
|
||
continue; | ||
if ($description) { | ||
continue; | ||
} | ||
} | ||
|
||
if (!$property) { | ||
if (!($property = $parameter->getProperty())) { | ||
continue; | ||
} | ||
|
||
|
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
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
36 changes: 36 additions & 0 deletions
36
tests/Fixtures/TestBundle/ApiResource/FilterWithStateOptions.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,36 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* 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; | ||
|
||
use ApiPlatform\Doctrine\Orm\Filter\DateFilter; | ||
use ApiPlatform\Doctrine\Orm\State\CollectionProvider; | ||
use ApiPlatform\Doctrine\Orm\State\Options; | ||
use ApiPlatform\Metadata\ApiFilter; | ||
use ApiPlatform\Metadata\GetCollection; | ||
use ApiPlatform\Metadata\QueryParameter; | ||
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\FilterWithStateOptionsEntity; | ||
|
||
#[GetCollection( | ||
uriTemplate: 'filter_with_state_options', | ||
stateOptions: new Options(entityClass: FilterWithStateOptionsEntity::class), | ||
parameters: ['date' => new QueryParameter(filter: 'filter_with_state_options_date', property: 'dummyDate')], | ||
provider: CollectionProvider::class | ||
)] | ||
#[ApiFilter(DateFilter::class, alias: 'filter_with_state_options_date', properties: ['dummyDate' => DateFilter::EXCLUDE_NULL])] | ||
final class FilterWithStateOptions | ||
{ | ||
public function __construct(public readonly string $id, public readonly \DateTimeImmutable $dummyDate, public readonly string $name) | ||
{ | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
tests/Fixtures/TestBundle/Entity/FilterWithStateOptionsEntity.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,32 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* 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\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
#[ORM\Entity] | ||
class FilterWithStateOptionsEntity | ||
{ | ||
public function __construct( | ||
#[ORM\Column(type: 'integer')] | ||
#[ORM\Id] | ||
#[ORM\GeneratedValue(strategy: 'AUTO')] | ||
public ?int $id = null, | ||
#[ORM\Column(type: 'date_immutable', nullable: true)] | ||
public ?\DateTimeImmutable $dummyDate = null, | ||
#[ORM\Column(type: 'string', nullable: true)] | ||
public ?string $name = null, | ||
) { | ||
} | ||
} |
Oops, something went wrong.