1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Schema; |
6
|
|
|
|
7
|
|
|
use Yiisoft\Db\Exception\NotSupportedException; |
8
|
|
|
use function array_keys; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* TableSchema represents the metadata of a database table. |
12
|
|
|
* |
13
|
|
|
* @property array $columnNames List of column names. This property is read-only. |
14
|
|
|
*/ |
15
|
|
|
abstract class TableSchema implements TableSchemaInterface |
16
|
|
|
{ |
17
|
|
|
private ?string $schemaName = null; |
18
|
|
|
private string $name = ''; |
19
|
|
|
private ?string $fullName = null; |
20
|
|
|
private ?string $sequenceName = null; |
21
|
|
|
/** @psalm-var string[] */ |
22
|
|
|
private array $primaryKey = []; |
23
|
|
|
/** @psalm-var ColumnSchemaInterface[] */ |
24
|
|
|
private array $columns = []; |
25
|
|
|
/** @psalm-var array<array-key, array> */ |
26
|
|
|
protected array $foreignKeys = []; |
27
|
|
|
protected ?string $createSql = null; |
28
|
|
|
private ?string $catalogName = null; |
29
|
|
|
private ?string $serverName = null; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Gets the named column metadata. |
33
|
|
|
* |
34
|
297 |
|
* This is a convenient method for retrieving a named column even if it does not exist. |
35
|
|
|
* |
36
|
297 |
|
* @param string $name column name |
37
|
|
|
* |
38
|
|
|
* @return ColumnSchemaInterface|null metadata of the named column. Null if the named column does not exist. |
39
|
|
|
*/ |
40
|
|
|
public function getColumn(string $name): ?ColumnSchemaInterface |
41
|
|
|
{ |
42
|
|
|
return $this->columns[$name] ?? null; |
43
|
|
|
} |
44
|
140 |
|
|
45
|
|
|
/** |
46
|
140 |
|
* Returns the names of all columns in this table. |
47
|
|
|
* |
48
|
|
|
* @return array list of column names |
49
|
|
|
*/ |
50
|
|
|
public function getColumnNames(): array |
51
|
|
|
{ |
52
|
|
|
return array_keys($this->columns); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return string|null the name of the schema that this table belongs to. |
57
|
|
|
*/ |
58
|
|
|
public function getSchemaName(): ?string |
59
|
|
|
{ |
60
|
|
|
return $this->schemaName; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return string the name of this table. The schema name is not included. Use {@see fullName} to get the name with |
65
|
|
|
* schema name prefix. |
66
|
|
|
*/ |
67
|
|
|
public function getName(): string |
68
|
|
|
{ |
69
|
|
|
return $this->name; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return string|null the full name of this table, which includes the schema name prefix, if any. Note that if the |
74
|
|
|
* schema name is the same as the {@see Schema::defaultSchema|default schema name}, the schema name will not be |
75
|
|
|
* included. |
76
|
|
|
*/ |
77
|
1197 |
|
public function getFullName(): ?string |
78
|
|
|
{ |
79
|
1197 |
|
return $this->fullName; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return string|null sequence name for the primary key. Null if no sequence. |
84
|
|
|
*/ |
85
|
|
|
public function getSequenceName(): ?string |
86
|
1511 |
|
{ |
87
|
|
|
return $this->sequenceName; |
88
|
1511 |
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return array primary keys of this table. |
92
|
|
|
* |
93
|
|
|
* @psalm-return string[] |
94
|
|
|
*/ |
95
|
|
|
public function getPrimaryKey(): array |
96
|
354 |
|
{ |
97
|
|
|
return $this->primaryKey; |
98
|
354 |
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return array column metadata of this table. Each array element is a {@see ColumnSchemaInterface} object, indexed by |
102
|
|
|
* column names. |
103
|
|
|
* |
104
|
489 |
|
* @psalm-return ColumnSchemaInterface[] |
105
|
|
|
*/ |
106
|
489 |
|
public function getColumns(): array |
107
|
|
|
{ |
108
|
|
|
return $this->columns; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function schemaName(?string $value): void |
112
|
741 |
|
{ |
113
|
|
|
$this->schemaName = $value; |
114
|
741 |
|
} |
115
|
|
|
|
116
|
|
|
public function name(string $value): void |
117
|
|
|
{ |
118
|
|
|
$this->name = $value; |
119
|
|
|
} |
120
|
|
|
|
121
|
926 |
|
public function fullName(?string $value): void |
122
|
|
|
{ |
123
|
926 |
|
$this->fullName = $value; |
124
|
|
|
} |
125
|
|
|
|
126
|
1017 |
|
public function sequenceName(?string $value): void |
127
|
|
|
{ |
128
|
1017 |
|
$this->sequenceName = $value; |
129
|
1017 |
|
} |
130
|
|
|
|
131
|
1514 |
|
public function primaryKey(string $value): void |
132
|
|
|
{ |
133
|
1514 |
|
$this->primaryKey[] = $value; |
134
|
1514 |
|
} |
135
|
|
|
|
136
|
1514 |
|
public function columns(string $index, ColumnSchemaInterface $value): void |
137
|
|
|
{ |
138
|
1514 |
|
$this->columns[$index] = $value; |
139
|
1514 |
|
} |
140
|
|
|
|
141
|
899 |
|
public function getCatalogName(): ?string |
142
|
|
|
{ |
143
|
899 |
|
return $this->catalogName; |
144
|
899 |
|
} |
145
|
|
|
|
146
|
1130 |
|
/** |
147
|
|
|
* @param string|null name of the catalog (database) that this table belongs to. Defaults to null, meaning no |
|
|
|
|
148
|
1130 |
|
* catalog (or the current database). |
149
|
1130 |
|
*/ |
150
|
|
|
public function catalogName(?string $value): void |
151
|
1279 |
|
{ |
152
|
|
|
$this->catalogName = $value; |
153
|
1279 |
|
} |
154
|
1279 |
|
|
155
|
|
|
public function getServerName(): ?string |
156
|
|
|
{ |
157
|
|
|
return $this->serverName; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param string|null name of the server |
162
|
|
|
*/ |
163
|
|
|
public function serverName(?string $value): void |
164
|
|
|
{ |
165
|
|
|
$this->serverName = $value; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public function getCreateSql(): ?string |
169
|
|
|
{ |
170
|
|
|
return $this->createSql; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
public function createSql(string $sql): void |
174
|
|
|
{ |
175
|
|
|
$this->createSql = $sql; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* ```php |
180
|
|
|
* [ |
181
|
|
|
* 'ForeignTableName', |
182
|
|
|
* 'fk1' => 'pk1', // pk1 is in foreign table |
183
|
|
|
* 'fk2' => 'pk2', // if composite foreign key |
184
|
|
|
* ] |
185
|
|
|
* ``` |
186
|
|
|
* |
187
|
|
|
* @return array foreign keys of this table. Each array element is of the following structure: |
188
|
|
|
* @psalm-return array<array-key, array> |
189
|
|
|
*/ |
190
|
|
|
public function getForeignKeys(): array |
191
|
|
|
{ |
192
|
|
|
return $this->foreignKeys; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @psalm-param array<array-key, array> $value |
197
|
|
|
*/ |
198
|
|
|
public function foreignKeys(array $value): void |
199
|
|
|
{ |
200
|
|
|
$this->foreignKeys = $value; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
public function foreignKey(string|int $id, array $to): void |
204
|
|
|
{ |
205
|
|
|
$this->foreignKeys[$id] = $to; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
public function compositeFK(int $id, string $from, string $to): void |
209
|
|
|
{ |
210
|
|
|
throw new NotSupportedException('Composite foreign key not supported'); |
211
|
|
|
} |
212
|
|
|
} |
213
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths