|
20 | 20 | use Doctrine\Common\Collections\ArrayCollection; |
21 | 21 | use Doctrine\Common\Collections\Collection; |
22 | 22 | use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; |
| 23 | +use Symfony\Component\Serializer\Attribute\Context; |
| 24 | +use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; |
23 | 25 | use Symfony\Component\Validator\Constraints as Assert; |
24 | 26 |
|
25 | 27 | /** |
|
28 | 30 | * @author Kévin Dunglas <[email protected]> |
29 | 31 | * @author Alexandre Delplace <[email protected]> |
30 | 32 | */ |
31 | | -#[ApiResource(extraProperties: ['doctrine_mongodb' => ['execute_options' => ['allowDiskUse' => true]], 'standard_put' => false, 'rfc_7807_compliant_errors' => false], filters: ['my_dummy.mongodb.boolean', 'my_dummy.mongodb.date', 'my_dummy.mongodb.exists', 'my_dummy.mongodb.numeric', 'my_dummy.mongodb.order', 'my_dummy.mongodb.range', 'my_dummy.mongodb.search', 'my_dummy.property'])] |
| 33 | +#[ApiResource(normalizationContext: [AbstractNormalizer::IGNORED_ATTRIBUTES => ['dummyDateWithFormat']], filters: ['my_dummy.mongodb.boolean', 'my_dummy.mongodb.date', 'my_dummy.mongodb.exists', 'my_dummy.mongodb.numeric', 'my_dummy.mongodb.order', 'my_dummy.mongodb.range', 'my_dummy.mongodb.search', 'my_dummy.property'], extraProperties: ['doctrine_mongodb' => ['execute_options' => ['allowDiskUse' => true]], 'standard_put' => false, 'rfc_7807_compliant_errors' => false])] |
32 | 34 | #[ApiResource(uriTemplate: '/related_owned_dummies/{id}/owning_dummy{._format}', uriVariables: ['id' => new Link(fromClass: RelatedOwnedDummy::class, identifiers: ['id'], fromProperty: 'owningDummy')], status: 200, filters: ['my_dummy.mongodb.boolean', 'my_dummy.mongodb.date', 'my_dummy.mongodb.exists', 'my_dummy.mongodb.numeric', 'my_dummy.mongodb.order', 'my_dummy.mongodb.range', 'my_dummy.mongodb.search', 'my_dummy.property'], operations: [new Get()])] |
33 | 35 | #[ApiResource(uriTemplate: '/related_owning_dummies/{id}/owned_dummy{._format}', uriVariables: ['id' => new Link(fromClass: RelatedOwningDummy::class, identifiers: ['id'], fromProperty: 'ownedDummy')], status: 200, filters: ['my_dummy.mongodb.boolean', 'my_dummy.mongodb.date', 'my_dummy.mongodb.exists', 'my_dummy.mongodb.numeric', 'my_dummy.mongodb.order', 'my_dummy.mongodb.range', 'my_dummy.mongodb.search', 'my_dummy.property'], operations: [new Get()])] |
34 | 36 | #[ODM\Document] |
@@ -75,6 +77,13 @@ class Dummy |
75 | 77 | #[ApiProperty(iris: ['https://schema.org/DateTime'])] |
76 | 78 | #[ODM\Field(type: 'date', nullable: true)] |
77 | 79 | public $dummyDate; |
| 80 | + /** |
| 81 | + * @var \DateTime|null A dummy date |
| 82 | + */ |
| 83 | + #[Context(denormalizationContext: ['datetime_format' => 'Y-m-d'])] |
| 84 | + #[ApiProperty(iris: ['https://schema.org/DateTime'])] |
| 85 | + #[ODM\Field(type: 'date', nullable: true)] |
| 86 | + private $dummyDateWithFormat; |
78 | 87 | /** |
79 | 88 | * @var float|null A dummy float |
80 | 89 | */ |
@@ -113,9 +122,10 @@ public static function staticMethod(): void |
113 | 122 | { |
114 | 123 | } |
115 | 124 |
|
116 | | - public function __construct() |
| 125 | + public function __construct(?\DateTime $dummyDateWithFormat = null) |
117 | 126 | { |
118 | 127 | $this->relatedDummies = new ArrayCollection(); |
| 128 | + $this->dummyDateWithFormat = $dummyDateWithFormat; |
119 | 129 | } |
120 | 130 |
|
121 | 131 | public function getId(): ?int |
@@ -178,6 +188,11 @@ public function getDummyDate() |
178 | 188 | return $this->dummyDate; |
179 | 189 | } |
180 | 190 |
|
| 191 | + public function getDummyDateWithFormat() |
| 192 | + { |
| 193 | + return $this->dummyDateWithFormat; |
| 194 | + } |
| 195 | + |
181 | 196 | public function setDummyPrice($dummyPrice) |
182 | 197 | { |
183 | 198 | $this->dummyPrice = $dummyPrice; |
|
0 commit comments