1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cycle\Annotated\Annotation; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor; |
8
|
|
|
use Doctrine\Common\Annotations\Annotation\Target; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @Annotation |
12
|
|
|
* @NamedArgumentConstructor |
13
|
|
|
* @Target("CLASS") |
14
|
|
|
*/ |
15
|
|
|
#[\Attribute(\Attribute::TARGET_CLASS), NamedArgumentConstructor] |
16
|
|
|
final class Entity |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @param non-empty-string|null $role Entity role. Defaults to the lowercase class name without a namespace. |
|
|
|
|
20
|
|
|
* @param class-string|null $mapper Mapper class name. Defaults to {@see \Cycle\ORM\Mapper\Mapper} |
21
|
|
|
* @param class-string|null $repository Repository class to represent read operations for an entity. |
22
|
|
|
* Defaults to {@see \Cycle\ORM\Select\Repository} |
23
|
|
|
* @param non-empty-string|null $table Entity source table. Defaults to plural form of entity role. |
24
|
|
|
* @param bool $readonlySchema Set to true to disable schema synchronization for the assigned table. |
25
|
|
|
* @param non-empty-string|null $database Database name. Defaults to null (default database). |
26
|
|
|
* @param class-string|null $source Entity source class (internal). Defaults to {@see \Cycle\ORM\Select\Source} |
27
|
|
|
* @param non-empty-string|non-empty-string[]|null $typecast |
28
|
|
|
* @param class-string|null $scope Class name of constraint to be applied to every entity query. |
29
|
|
|
* @param Column[] $columns Entity columns. |
30
|
|
|
*/ |
31
|
480 |
|
public function __construct( |
32
|
|
|
private ?string $role = null, |
33
|
|
|
private ?string $mapper = null, |
34
|
|
|
private ?string $repository = null, |
35
|
|
|
private ?string $table = null, |
36
|
|
|
private bool $readonlySchema = false, |
37
|
|
|
private ?string $database = null, |
38
|
|
|
private ?string $source = null, |
39
|
|
|
private array|string|null $typecast = null, |
40
|
|
|
private ?string $scope = null, |
41
|
|
|
private array $columns = [], |
42
|
|
|
/** @deprecated Use {@see $scope} instead */ |
43
|
|
|
private ?string $constrain = null, |
44
|
|
|
) { |
45
|
480 |
|
} |
46
|
|
|
|
47
|
480 |
|
public function getRole(): ?string |
48
|
|
|
{ |
49
|
480 |
|
return $this->role; |
50
|
|
|
} |
51
|
|
|
|
52
|
480 |
|
public function getMapper(): ?string |
53
|
|
|
{ |
54
|
480 |
|
return $this->mapper; |
55
|
|
|
} |
56
|
|
|
|
57
|
480 |
|
public function getRepository(): ?string |
58
|
|
|
{ |
59
|
480 |
|
return $this->repository; |
60
|
|
|
} |
61
|
|
|
|
62
|
480 |
|
public function getTable(): ?string |
63
|
|
|
{ |
64
|
480 |
|
return $this->table; |
65
|
|
|
} |
66
|
|
|
|
67
|
480 |
|
public function isReadonlySchema(): bool |
68
|
|
|
{ |
69
|
480 |
|
return $this->readonlySchema; |
70
|
|
|
} |
71
|
|
|
|
72
|
480 |
|
public function getDatabase(): ?string |
73
|
|
|
{ |
74
|
480 |
|
return $this->database; |
75
|
|
|
} |
76
|
|
|
|
77
|
480 |
|
public function getSource(): ?string |
78
|
|
|
{ |
79
|
480 |
|
return $this->source; |
80
|
|
|
} |
81
|
|
|
|
82
|
480 |
|
public function getScope(): ?string |
83
|
|
|
{ |
84
|
480 |
|
return $this->scope ?? $this->constrain; |
85
|
|
|
} |
86
|
|
|
|
87
|
468 |
|
public function getColumns(): array |
88
|
|
|
{ |
89
|
468 |
|
return $this->columns; |
90
|
|
|
} |
91
|
|
|
|
92
|
480 |
|
public function getTypecast(): array|string|null |
93
|
|
|
{ |
94
|
480 |
|
if (is_array($this->typecast) && count($this->typecast) === 1) { |
95
|
|
|
return reset($this->typecast); |
96
|
|
|
} |
97
|
|
|
|
98
|
480 |
|
return $this->typecast; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|