Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Mar 23, 2024
1 parent 26d37d2 commit 23b0b6e
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/Doctrine/Orm/Extension/ParameterExtension.php
Expand Up @@ -22,6 +22,8 @@
use Psr\Container\ContainerInterface;

/**
* Reads operation parameters and execute its filter.
*
* @author Antoine Bluchet <soyuka@gmail.com>
*/
final class ParameterExtension implements QueryCollectionExtensionInterface, QueryItemExtensionInterface
Expand All @@ -47,7 +49,6 @@ private function applyFilter(QueryBuilder $queryBuilder, QueryNameGeneratorInter
}

$parameters = $parameter instanceof HeaderParameterInterface ? $request->attributes->get('_api_header_parameters') : $request->attributes->get('_api_query_parameters');

$parsedKey = explode('[:property]', $key);
if (isset($parsedKey[0]) && isset($parameters[$parsedKey[0]])) {
$key = $parsedKey[0];

Check warning on line 54 in src/Doctrine/Orm/Extension/ParameterExtension.php

View check run for this annotation

Codecov / codecov/patch

src/Doctrine/Orm/Extension/ParameterExtension.php#L51-L54

Added lines #L51 - L54 were not covered by tests
Expand Down
10 changes: 9 additions & 1 deletion src/Doctrine/Orm/Filter/AbstractFilter.php
Expand Up @@ -29,7 +29,7 @@ abstract class AbstractFilter implements FilterInterface
use PropertyHelperTrait;
protected LoggerInterface $logger;

public function __construct(protected ManagerRegistry $managerRegistry, ?LoggerInterface $logger = null, public ?array $properties = null, protected ?NameConverterInterface $nameConverter = null)
public function __construct(protected ManagerRegistry $managerRegistry, ?LoggerInterface $logger = null, protected ?array $properties = null, protected ?NameConverterInterface $nameConverter = null)
{
$this->logger = $logger ?? new NullLogger();
}
Expand Down Expand Up @@ -64,6 +64,14 @@ protected function getLogger(): LoggerInterface
return $this->logger;
}

/**
* @param string[] $properties
*/
public function setProperties(array $properties): void
{
$this->properties = $properties;
}

/**
* Determines whether the given property is enabled.
*/
Expand Down
1 change: 1 addition & 0 deletions src/Hydra/Serializer/CollectionFiltersNormalizer.php
Expand Up @@ -175,6 +175,7 @@ private function getSearch(string $resourceClass, array $parts, array $filters,
continue;

Check warning on line 175 in src/Hydra/Serializer/CollectionFiltersNormalizer.php

View check run for this annotation

Codecov / codecov/patch

src/Hydra/Serializer/CollectionFiltersNormalizer.php#L174-L175

Added lines #L174 - L175 were not covered by tests
}

// :property is a pattern allowed when defining parameters
$k = str_replace(':property', $description['property'], $key);
$variable = str_replace($description['property'], $k, $variable);
$variables[] = $variable;
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/ApiFilter.php
Expand Up @@ -26,7 +26,7 @@ final class ApiFilter
{
/**
* @param string|class-string<FilterInterface>|class-string<LegacyFilterInterface> $filterClass
* @param string $alias a service alias to be referenced in a Parameter
* @param string $alias a filter tag alias to be referenced in a Parameter
*/
public function __construct(
public string $filterClass,
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/Parameters.php
Expand Up @@ -14,7 +14,7 @@
namespace ApiPlatform\Metadata;

/**
* An parameter dictionnary.
* A parameter dictionnary.
*
* @implements \IteratorAggregate<string, Parameter>
*/
Expand Down
Expand Up @@ -22,6 +22,8 @@
use Psr\Container\ContainerInterface;

/**
* Prepares Parameters documentation by reading its filter details and declaring an OpenApi parameter.
*
* @experimental
*/
final class ParameterResourceMetadataCollectionFactory implements ResourceMetadataCollectionFactoryInterface
Expand Down
Expand Up @@ -23,7 +23,7 @@ final class SearchFilterValueTransformer implements FilterInterface
{
public function __construct(#[Autowire('@api_platform.doctrine.orm.search_filter.instance')] readonly FilterInterface $searchFilter, ?array $properties = null, private readonly ?string $key = null)
{
$searchFilter->properties = $properties;
$searchFilter->setProperties($properties);

Check failure on line 26 in tests/Fixtures/TestBundle/Filter/SearchFilterValueTransformer.php

View workflow job for this annotation

GitHub Actions / PHPStan (PHP 8.3)

Call to an undefined method ApiPlatform\Doctrine\Orm\Filter\FilterInterface::setProperties().
}

// This function is only used to hook in documentation generators (supported by Swagger and Hydra)
Expand Down
6 changes: 3 additions & 3 deletions tests/Fixtures/TestBundle/Filter/SearchTextAndDateFilter.php
Expand Up @@ -21,10 +21,10 @@

final class SearchTextAndDateFilter implements FilterInterface
{
public function __construct(#[Autowire('@api_platform.doctrine.orm.search_filter.instance')] readonly FilterInterface $searchFilter, #[Autowire('@api_platform.doctrine.orm.date_filter.instance')] readonly FilterInterface $dateFilter, ?array $properties = null, array $dateFilterProperties = [], array $searchFilterProperties = [])
public function __construct(#[Autowire('@api_platform.doctrine.orm.search_filter.instance')] readonly FilterInterface $searchFilter, #[Autowire('@api_platform.doctrine.orm.date_filter.instance')] readonly FilterInterface $dateFilter, protected ?array $properties = null, array $dateFilterProperties = [], array $searchFilterProperties = [])
{
$searchFilter->properties = $searchFilterProperties;
$dateFilter->properties = $dateFilterProperties;
$searchFilter->setProperties($searchFilterProperties);

Check failure on line 26 in tests/Fixtures/TestBundle/Filter/SearchTextAndDateFilter.php

View workflow job for this annotation

GitHub Actions / PHPStan (PHP 8.3)

Call to an undefined method ApiPlatform\Doctrine\Orm\Filter\FilterInterface::setProperties().
$dateFilter->setProperties($dateFilterProperties);

Check failure on line 27 in tests/Fixtures/TestBundle/Filter/SearchTextAndDateFilter.php

View workflow job for this annotation

GitHub Actions / PHPStan (PHP 8.3)

Call to an undefined method ApiPlatform\Doctrine\Orm\Filter\FilterInterface::setProperties().
}

// This function is only used to hook in documentation generators (supported by Swagger and Hydra)
Expand Down

0 comments on commit 23b0b6e

Please sign in to comment.