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