-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImportEntity.php
128 lines (102 loc) · 3 KB
/
ImportEntity.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
declare(strict_types=1);
namespace Vrok\DoctrineAddons\Tests\Fixtures;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping as ORM;
use PHPUnit\Framework\TestCase;
use Vrok\DoctrineAddons\ImportExport\ImportableEntity;
use Vrok\DoctrineAddons\ImportExport\ImportableProperty;
#[ImportableEntity]
#[ORM\Entity]
class ImportEntity
{
// region typed (builtin), nullable property with getter/setter
#[ImportableProperty]
#[ORM\Id]
#[ORM\Column]
private ?string $name = '';
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $value): self
{
$this->name = null !== $value ? $value.' via setter' : null;
return $this;
}
// endregion
// region untyped Collection property
#[ImportableProperty]
private Collection $collection;
public function getCollection(): Collection
{
return $this->collection;
}
public function setCollection(array $elements): self
{
$this->collection->clear();
foreach ($elements as $element) {
$this->addToCollection($element);
}
return $this;
}
public function addToCollection(self $element): self
{
if ($this->collection->contains($element)) {
return $this;
}
$this->collection->add($element);
return $this;
}
// endregion
// region typed (object), nullable property with getter/setter
#[ImportableProperty]
#[ORM\Column(nullable: true)]
private ?self $parent = null;
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $value): self
{
$this->parent = $value;
return $this;
}
// endregion
// region DateTime nullable property w/o getter/setter
#[ImportableProperty]
#[ORM\Column(nullable: true)]
public ?\DateTimeImmutable $timestamp = null;
// endregion
// region typed (object), nullable property w/o getter/setter
#[ImportableProperty]
public ?TestEntity $otherReference = null;
// endregion
// region property without Importable attribute
public string $notImported = 'initial';
// endregion
// region array property with listof Attribute for a DTO
#[ImportableProperty(listOf: TestDTO::class)]
#[ORM\Column]
public array $dtoList = [];
// endregion
// region array property with listof Attribute for an Interface
#[ImportableProperty(listOf: DtoInterface::class)]
#[ORM\Column]
public array $interfaceList = [];
// endregion
// region union-typed, nullable property
#[ImportableProperty]
public TestCase|EntityManager|null $union = null;
// endregion
// region untyped property
#[ImportableProperty]
public $untypedProp;
// endregion
public function __construct()
{
$this->collection = new ArrayCollection();
}
}