1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace App\Filter;
- use ApiPlatform\Core\Api\FilterInterface;
- /**
- * Class SearchFilter
- * @package App\Filter
- */
- class SearchFilter implements FilterInterface
- {
- /**
- * @var string Exact matching
- */
- const STRATEGY_EXACT = 'exact';
- /**
- * @var string The value must be contained in the field
- */
- const STRATEGY_PARTIAL = 'partial';
- /**
- * @var string Finds fields that are starting with the value
- */
- const STRATEGY_START = 'start';
- /**
- * @var string Finds fields that are ending with the value
- */
- const STRATEGY_END = 'end';
- /**
- * @var string Finds fields that are starting with the word
- */
- const STRATEGY_WORD_START = 'word_start';
- protected $properties;
- /**
- * SearchFilter constructor.
- * @param array|null $properties
- */
- public function __construct(array $properties = null)
- {
- $this->properties = $properties;
- }
- /**
- * {@inheritdoc}
- */
- public function getDescription(string $resourceClass): array
- {
- $description = [];
- $properties = $this->properties;
- foreach ($properties as $property => $strategy) {
- $filterParameterNames = [
- $property,
- $property.'[]',
- ];
- foreach ($filterParameterNames as $filterParameterName) {
- $description[$filterParameterName] = [
- 'property' => $property,
- 'type' => 'string',
- 'required' => false,
- 'strategy' => self::STRATEGY_EXACT,
- 'is_collection' => '[]' === substr($filterParameterName, -2),
- ];
- }
- }
- return $description;
- }
- }
- ?>
|