|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the API Platform project. |
| 5 | + * |
| 6 | + * (c) Kévin Dunglas <[email protected]> |
| 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\Metadata\ApiResource; |
| 17 | +use ApiPlatform\Metadata\Delete; |
| 18 | +use ApiPlatform\Metadata\Get; |
| 19 | +use ApiPlatform\Metadata\GetCollection; |
| 20 | +use ApiPlatform\Metadata\Link; |
| 21 | +use ApiPlatform\Metadata\Post; |
| 22 | +use ApiPlatform\Metadata\Put; |
| 23 | +use ApiPlatform\State\CreateProvider; |
| 24 | +use Doctrine\ORM\Mapping as ORM; |
| 25 | + |
| 26 | +#[ApiResource( |
| 27 | + types: ['https://schema.org/LocalBusiness'], |
| 28 | + operations: [ |
| 29 | + new GetCollection( |
| 30 | + uriTemplate: '/subresource_organizations/{subresourceOrganizationId}/subresource_factories', |
| 31 | + uriVariables: [ |
| 32 | + 'subresourceOrganizationId' => new Link(toProperty: 'subresourceOrganization', fromClass: SubresourceOrganization::class), |
| 33 | + ] |
| 34 | + ), |
| 35 | + new Post( |
| 36 | + uriTemplate: '/subresource_organizations/{subresourceOrganizationId}/subresource_factories', |
| 37 | + uriVariables: [ |
| 38 | + 'subresourceOrganizationId' => new Link(toProperty: 'subresourceOrganization', fromClass: SubresourceOrganization::class), |
| 39 | + ], |
| 40 | + provider: CreateProvider::class |
| 41 | + ), |
| 42 | + new Get( |
| 43 | + uriTemplate: '/subresource_organizations/{subresourceOrganizationId}/subresource_factories/{id}', |
| 44 | + uriVariables: [ |
| 45 | + 'subresourceOrganizationId' => new Link(toProperty: 'subresourceOrganization', fromClass: SubresourceOrganization::class), |
| 46 | + 'id' => new Link(fromClass: SubresourceFactory::class), |
| 47 | + ] |
| 48 | + ), |
| 49 | + new Put( |
| 50 | + uriTemplate: '/subresource_organizations/{subresourceOrganizationId}/subresource_factories/{id}', |
| 51 | + extraProperties: ['standard_put' => false], |
| 52 | + uriVariables: [ |
| 53 | + 'subresourceOrganizationId' => new Link(toProperty: 'subresourceOrganization', fromClass: SubresourceOrganization::class), |
| 54 | + 'id' => new Link(fromClass: SubresourceFactory::class), |
| 55 | + ] |
| 56 | + ), |
| 57 | + new Delete( |
| 58 | + uriTemplate: '/subresource_organizations/{subresourceOrganizationId}/subresource_factories/{id}', |
| 59 | + uriVariables: [ |
| 60 | + 'subresourceOrganizationId' => new Link(toProperty: 'subresourceOrganization', fromClass: SubresourceOrganization::class), |
| 61 | + 'id' => new Link(fromClass: SubresourceFactory::class), |
| 62 | + ] |
| 63 | + ), |
| 64 | + ] |
| 65 | +)] |
| 66 | +#[ORM\Entity] |
| 67 | +class SubresourceFactory |
| 68 | +{ |
| 69 | + #[ORM\Id] |
| 70 | + #[ORM\GeneratedValue] |
| 71 | + #[ORM\Column] |
| 72 | + private ?int $id = null; |
| 73 | + |
| 74 | + #[ORM\Column(length: 255, nullable: true)] |
| 75 | + private ?string $name = null; |
| 76 | + |
| 77 | + #[ORM\ManyToOne(inversedBy: 'factories')] |
| 78 | + #[ORM\JoinColumn(nullable: false)] |
| 79 | + private ?SubresourceOrganization $subresourceOrganization = null; |
| 80 | + |
| 81 | + public function getId(): ?int |
| 82 | + { |
| 83 | + return $this->id; |
| 84 | + } |
| 85 | + |
| 86 | + public function getName(): ?string |
| 87 | + { |
| 88 | + return $this->name; |
| 89 | + } |
| 90 | + |
| 91 | + public function setName(?string $name): self |
| 92 | + { |
| 93 | + $this->name = $name; |
| 94 | + |
| 95 | + return $this; |
| 96 | + } |
| 97 | + |
| 98 | + public function getSubresourceOrganization(): ?SubresourceOrganization |
| 99 | + { |
| 100 | + return $this->subresourceOrganization; |
| 101 | + } |
| 102 | + |
| 103 | + public function setSubresourceOrganization(?SubresourceOrganization $subresourceOrganization): self |
| 104 | + { |
| 105 | + $this->subresourceOrganization = $subresourceOrganization; |
| 106 | + |
| 107 | + return $this; |
| 108 | + } |
| 109 | +} |
0 commit comments