Skip to content

Commit e50afcc

Browse files
committed
feat: add a hook for entity to resource transformation
1 parent cbf293e commit e50afcc

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

tests/Behat/DoctrineContext.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
use ApiPlatform\Tests\Fixtures\TestBundle\Document\SoMany as SoManyDocument;
9898
use ApiPlatform\Tests\Fixtures\TestBundle\Document\Taxon as TaxonDocument;
9999
use ApiPlatform\Tests\Fixtures\TestBundle\Document\ThirdLevel as ThirdLevelDocument;
100+
use ApiPlatform\Tests\Fixtures\TestBundle\Document\TransformedDummyDocument;
100101
use ApiPlatform\Tests\Fixtures\TestBundle\Document\UrlEncodedId as UrlEncodedIdDocument;
101102
use ApiPlatform\Tests\Fixtures\TestBundle\Document\User as UserDocument;
102103
use ApiPlatform\Tests\Fixtures\TestBundle\Document\VideoGame as VideoGameDocument;
@@ -2714,4 +2715,9 @@ private function buildLinkHandledDummy(string $slug): LinkHandledDummy|LinkHandl
27142715
{
27152716
return $this->isOrm() ? new LinkHandledDummy($slug) : new LinkHandledDummyDocument($slug);
27162717
}
2718+
2719+
private function buildTransformedDummy(\DateTimeImmutable $dateTime): TransformedDummyEntity|TransformedDummyDocument
2720+
{
2721+
return $this->isOrm() ? new TransformedDummyEntity($dateTime) : new TransformedDummyDocument($dateTime);
2722+
}
27172723
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace ApiPlatform\Tests\Fixtures\TestBundle\Document;
4+
5+
use Doctrine\DBAL\Types\Types;
6+
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
7+
8+
class TransformedDummyDocument
9+
{
10+
11+
#[ODM\Id(type: 'int', strategy: 'INCREMENT')]
12+
private ?int $id = null;
13+
14+
#[ODM\Field(type: Types::DATETIME_IMMUTABLE)]
15+
private \DateTimeInterface $date;
16+
17+
public function __construct(\DateTimeInterface $date = null)
18+
{
19+
$this->setDate($date ?? new \DateTimeImmutable());
20+
}
21+
22+
public function getDate(): \DateTimeInterface
23+
{
24+
return $this->date;
25+
}
26+
27+
public function setDate(\DateTimeInterface $date): void
28+
{
29+
$this->date = $date;
30+
}
31+
32+
public function getId(): ?int
33+
{
34+
return $this->id;
35+
}
36+
37+
}

0 commit comments

Comments
 (0)