|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the API Platform project. |
| 5 | + * |
| 6 | + * (c) Kévin Dunglas <dunglas@gmail.com> |
| 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\Tests\Fixtures\TestBundle\Entity; |
| 15 | + |
| 16 | +use ApiPlatform\Doctrine\Orm\Filter\PartialSearchFilter; |
| 17 | +use ApiPlatform\Metadata\ApiResource; |
| 18 | +use ApiPlatform\Metadata\Get; |
| 19 | +use ApiPlatform\Metadata\GetCollection; |
| 20 | +use ApiPlatform\Metadata\Parameters; |
| 21 | +use ApiPlatform\Metadata\QueryParameter; |
| 22 | +use Doctrine\ORM\Mapping as ORM; |
| 23 | + |
| 24 | +#[ORM\Entity] |
| 25 | +#[ApiResource( |
| 26 | + uriTemplate: 'parameter_on_properties', |
| 27 | + // normalizationContext: ['hydra_prefix' => false], |
| 28 | + // provider: [self::class, 'provide'], |
| 29 | + operations: [ |
| 30 | + new GetCollection( |
| 31 | + // parameters: [ |
| 32 | + // new QueryParameter( |
| 33 | + // key: 'qname', |
| 34 | + // filter: new PartialSearchFilter(), |
| 35 | + // property: 'name', |
| 36 | + // ), |
| 37 | + // // new QueryParameter( |
| 38 | + // // key: 'de', |
| 39 | + // // filter: new PartialSearchFilter(), |
| 40 | + // // property: 'description', |
| 41 | + // // ), |
| 42 | + // ], |
| 43 | + ), |
| 44 | + new Get(), |
| 45 | + ] |
| 46 | +)] |
| 47 | +class ParameterOnProperties |
| 48 | +{ |
| 49 | + #[ORM\Id] |
| 50 | + #[ORM\GeneratedValue] |
| 51 | + #[ORM\Column(type: 'integer')] |
| 52 | + private ?int $id = null; |
| 53 | + |
| 54 | + #[ORM\Column(type: 'string')] |
| 55 | + #[QueryParameter(key: 'qname', filter: new PartialSearchFilter())] |
| 56 | + private string $name = ''; |
| 57 | + |
| 58 | + #[ORM\Column(type: 'string', nullable: true)] |
| 59 | + private ?string $description = null; |
| 60 | + |
| 61 | + public function __construct(string $name = '', ?string $description = null) |
| 62 | + { |
| 63 | + $this->name = $name; |
| 64 | + $this->description = $description; |
| 65 | + } |
| 66 | + |
| 67 | + public function getId(): ?int |
| 68 | + { |
| 69 | + return $this->id; |
| 70 | + } |
| 71 | + |
| 72 | + public function getName(): string |
| 73 | + { |
| 74 | + return $this->name; |
| 75 | + } |
| 76 | + |
| 77 | + public function setName(string $name): self |
| 78 | + { |
| 79 | + $this->name = $name; |
| 80 | + |
| 81 | + return $this; |
| 82 | + } |
| 83 | + |
| 84 | + public function getDescription(): ?string |
| 85 | + { |
| 86 | + return $this->description; |
| 87 | + } |
| 88 | + |
| 89 | + public function setDescription(?string $description): self |
| 90 | + { |
| 91 | + $this->description = $description; |
| 92 | + |
| 93 | + return $this; |
| 94 | + } |
| 95 | + |
| 96 | + // public static function provide(): array |
| 97 | + // { |
| 98 | + // return [ |
| 99 | + // new self('foo', 'bar'), |
| 100 | + // new self('baz', 'qux'), |
| 101 | + // new self('qoox', 'corge'), |
| 102 | + // ]; |
| 103 | + // } |
| 104 | +} |
0 commit comments