-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathColumn.php
More file actions
112 lines (96 loc) · 3.17 KB
/
Column.php
File metadata and controls
112 lines (96 loc) · 3.17 KB
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
<?php
declare(strict_types=1);
namespace Cycle\Annotated\Annotation;
use Cycle\ORM\Parser\Typecast;
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
use Doctrine\Common\Annotations\Annotation\Target;
use JetBrains\PhpStorm\ExpectedValues;
/**
* @Annotation
* @NamedArgumentConstructor
* @Target({"PROPERTY", "ANNOTATION", "CLASS"})
*/
#[
\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE),
NamedArgumentConstructor
]
final class Column
{
private bool $hasDefault = false;
private bool $hasNullable = false;
/**
* @param non-empty-string $type Column type. {@see \Cycle\Database\Schema\AbstractColumn::$mapping}
* @param non-empty-string|null $name Column name. Defaults to the property name.
* @param non-empty-string|null $property Property that belongs to column. For virtual columns.
* @param bool $primary Explicitly set column as a primary key.
* @param bool $nullable Set column as nullable.
* @param mixed|null $default Default column value.
* @param non-empty-string|null $typecast Typecast rule name.
* Regarding the default Typecast handler {@see Typecast} the value can be `callable` or
* one of ("int"|"float"|"bool"|"datetime") based on column type.
* If you want to use another rule you should add in the `typecast` argument of the {@see Entity} attribute
* a relevant Typecast handler that supports the rule.
* @param bool $castDefault
*/
public function __construct(
#[ExpectedValues(values: ['primary', 'bigPrimary', 'enum', 'boolean', 'integer', 'tinyInteger', 'bigInteger',
'string', 'text', 'tinyText', 'longText', 'double', 'float', 'decimal', 'datetime', 'date', 'time',
'timestamp', 'binary', 'tinyBinary', 'longBinary', 'json',
])]
private ?string $type = null,
private ?string $name = null,
private ?string $property = null,
private bool $primary = false,
private ?bool $nullable = null,
private mixed $default = null,
private mixed $typecast = null,
private bool $castDefault = false,
) {
if ($default !== null) {
$this->hasDefault = true;
}
if ($this->nullable !== null) {
$this->hasNullable = true;
}
}
public function getType(): ?string
{
return $this->type;
}
public function getColumn(): ?string
{
return $this->name;
}
public function getProperty(): ?string
{
return $this->property;
}
public function isNullable(): bool
{
return $this->nullable === true;
}
public function isPrimary(): bool
{
return $this->primary;
}
public function hasDefault(): bool
{
return $this->hasDefault;
}
public function hasNullable(): bool
{
return $this->hasNullable;
}
public function getDefault(): mixed
{
return $this->default;
}
public function castDefault(): bool
{
return $this->castDefault;
}
public function getTypecast(): mixed
{
return $this->typecast;
}
}