1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cycle\Annotated\Annotation; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\Annotations\Annotation\Attribute; |
8
|
|
|
use Doctrine\Common\Annotations\Annotation\Attributes; |
9
|
|
|
use Doctrine\Common\Annotations\Annotation\Target; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @Annotation |
13
|
|
|
* @Target({"PROPERTY", "ANNOTATION", "CLASS"}) |
14
|
|
|
* @Attributes({ |
15
|
|
|
* @Attribute("type", type="string", required=true), |
16
|
|
|
* @Attribute("name", type="string"), |
17
|
|
|
* @Attribute("property", type="string"), |
18
|
|
|
* @Attribute("primary", type="bool"), |
19
|
|
|
* @Attribute("nullable", type="bool"), |
20
|
|
|
* @Attribute("default", type="mixed"), |
21
|
|
|
* @Attribute("typecast", type="mixed"), |
22
|
|
|
* }) |
23
|
|
|
*/ |
24
|
|
|
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)] |
25
|
|
|
final class Column |
26
|
|
|
{ |
27
|
|
|
/** @var bool */ |
28
|
|
|
private $hasDefault = false; |
29
|
|
|
|
30
|
|
|
/** @var string|null */ |
31
|
|
|
private $name; |
32
|
|
|
|
33
|
|
|
/** @var string|null */ |
34
|
|
|
private $property; |
35
|
|
|
|
36
|
|
|
/** @var string */ |
37
|
|
|
private $type; |
38
|
|
|
|
39
|
|
|
/** @var bool */ |
40
|
|
|
private $nullable = false; |
41
|
|
|
|
42
|
|
|
/** @var bool */ |
43
|
|
|
private $primary = false; |
44
|
|
|
|
45
|
|
|
/** @var mixed */ |
46
|
|
|
private $default; |
47
|
|
|
|
48
|
|
|
/** @var bool */ |
49
|
|
|
private $castDefault = false; |
50
|
|
|
|
51
|
|
|
/** @var mixed */ |
52
|
|
|
private $typecast; |
53
|
|
|
|
54
|
|
|
public function __construct(array $values) |
55
|
|
|
{ |
56
|
|
|
if (isset($values['default'])) { |
57
|
|
|
$this->hasDefault = true; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
foreach ($values as $key => $value) { |
61
|
|
|
$this->$key = $value; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return string|null |
67
|
|
|
*/ |
68
|
|
|
public function getType(): ?string |
69
|
|
|
{ |
70
|
|
|
return $this->type; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return string|null |
75
|
|
|
*/ |
76
|
|
|
public function getColumn(): ?string |
77
|
|
|
{ |
78
|
|
|
return $this->name; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return string|null |
83
|
|
|
*/ |
84
|
|
|
public function getProperty(): ?string |
85
|
|
|
{ |
86
|
|
|
return $this->property; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return bool |
91
|
|
|
*/ |
92
|
|
|
public function isNullable(): bool |
93
|
|
|
{ |
94
|
|
|
return $this->nullable; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return bool |
99
|
|
|
*/ |
100
|
|
|
public function isPrimary(): bool |
101
|
|
|
{ |
102
|
|
|
return $this->primary; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return bool |
107
|
|
|
*/ |
108
|
|
|
public function hasDefault(): bool |
109
|
|
|
{ |
110
|
|
|
return $this->hasDefault; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return mixed |
115
|
|
|
*/ |
116
|
|
|
public function getDefault() |
117
|
|
|
{ |
118
|
|
|
return $this->default; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return bool |
123
|
|
|
*/ |
124
|
|
|
public function castDefault(): bool |
125
|
|
|
{ |
126
|
|
|
return $this->castDefault; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return mixed|null |
131
|
|
|
*/ |
132
|
|
|
public function getTypecast() |
133
|
|
|
{ |
134
|
|
|
return $this->typecast; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|