|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Schema; |
|
6
|
|
|
|
|
7
|
|
|
use Yiisoft\Db\Exception\NotSupportedException; |
|
8
|
|
|
|
|
9
|
|
|
use function array_keys; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* TableSchema represents the metadata of a database table. |
|
13
|
|
|
* |
|
14
|
|
|
* @property array $columnNames List of column names. This property is read-only. |
|
15
|
|
|
*/ |
|
16
|
|
|
abstract class AbstractTableSchema implements TableSchemaInterface |
|
17
|
|
|
{ |
|
18
|
|
|
private string|null $schemaName = null; |
|
19
|
|
|
private string $name = ''; |
|
20
|
|
|
private string|null $fullName = null; |
|
21
|
|
|
private string|null $comment = null; |
|
22
|
|
|
private string|null $sequenceName = null; |
|
23
|
|
|
/** @psalm-var string[] */ |
|
24
|
|
|
private array $primaryKey = []; |
|
25
|
|
|
/** @psalm-var ColumnSchemaInterface[] */ |
|
26
|
|
|
private array $columns = []; |
|
27
|
|
|
/** @psalm-var array<array-key, array> */ |
|
28
|
|
|
protected array $foreignKeys = []; |
|
29
|
|
|
protected string|null $createSql = null; |
|
30
|
|
|
private string|null $catalogName = null; |
|
31
|
|
|
private string|null $serverName = null; |
|
32
|
|
|
|
|
33
|
|
|
public function getColumn(string $name): ColumnSchemaInterface|null |
|
34
|
|
|
{ |
|
35
|
|
|
return $this->columns[$name] ?? null; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function getColumnNames(): array |
|
39
|
|
|
{ |
|
40
|
|
|
return array_keys($this->columns); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function getSchemaName(): string|null |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->schemaName; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getName(): string |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->name; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function getFullName(): string|null |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->fullName; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function getSequenceName(): string|null |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->sequenceName; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function getPrimaryKey(): array |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->primaryKey; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function getColumns(): array |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->columns; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function getComment(): string|null |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->comment; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function schemaName(string|null $value): void |
|
79
|
|
|
{ |
|
80
|
|
|
$this->schemaName = $value; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function name(string $value): void |
|
84
|
|
|
{ |
|
85
|
|
|
$this->name = $value; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function fullName(string|null $value): void |
|
89
|
|
|
{ |
|
90
|
|
|
$this->fullName = $value; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function comment(string|null $value): void |
|
94
|
|
|
{ |
|
95
|
|
|
$this->comment = $value; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function sequenceName(string|null $value): void |
|
99
|
|
|
{ |
|
100
|
|
|
$this->sequenceName = $value; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function primaryKey(string $value): void |
|
104
|
|
|
{ |
|
105
|
|
|
$this->primaryKey[] = $value; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function columns(string $index, ColumnSchemaInterface $value): void |
|
109
|
|
|
{ |
|
110
|
|
|
$this->columns[$index] = $value; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function getCatalogName(): string|null |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->catalogName; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
public function catalogName(string|null $value): void |
|
119
|
|
|
{ |
|
120
|
|
|
$this->catalogName = $value; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
public function getServerName(): string|null |
|
124
|
|
|
{ |
|
125
|
|
|
return $this->serverName; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
public function serverName(string|null $value): void |
|
129
|
|
|
{ |
|
130
|
|
|
$this->serverName = $value; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
public function getCreateSql(): string|null |
|
134
|
|
|
{ |
|
135
|
|
|
return $this->createSql; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function createSql(string $sql): void |
|
139
|
|
|
{ |
|
140
|
|
|
$this->createSql = $sql; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
public function getForeignKeys(): array |
|
144
|
|
|
{ |
|
145
|
|
|
return $this->foreignKeys; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
public function foreignKeys(array $value): void |
|
149
|
|
|
{ |
|
150
|
|
|
$this->foreignKeys = $value; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
public function foreignKey(string|int $id, array $to): void |
|
154
|
|
|
{ |
|
155
|
|
|
$this->foreignKeys[$id] = $to; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
public function compositeFK(int $id, string $from, string $to): void |
|
159
|
|
|
{ |
|
160
|
|
|
throw new NotSupportedException(static::class . ' does not support composite FK.'); |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
|