PluginProbe ʕ •ᴥ•ʔ
MailPoet – Newsletters, Email Marketing, and Automation / 5.36.0
MailPoet – Newsletters, Email Marketing, and Automation v5.36.0
5.36.0 5.35.1 5.35.0 5.34.3 5.34.2 5.34.1 5.34.0 5.33.1 5.33.0 5.32.0 5.31.0 5.30.0 5.29.0 5.28.1 5.28.0 5.27.0 5.26.0 5.26.1 5.25.0 5.24.0 4.43.0 4.43.1 4.44.0 4.44.1 4.45.0 4.46.0 4.47.0 4.48.0 4.48.1 4.48.2 4.49.0 4.49.1 4.5.0 4.5.1 4.5.2 4.50.0 4.50.1 4.51.0 4.51.1 4.51.2 4.52.0 4.53.0 4.54.0 4.55.0 4.56.0 4.57.0 4.58.0 4.58.1 4.58.2 4.6.0 4.6.1 4.6.2 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 5.0.0 5.0.1 5.0.2 5.1.0 5.1.1 5.10.0 5.10.1 5.11.0 5.12.0 5.12.1 5.12.10 5.12.11 5.12.12 5.12.13 5.12.2 5.12.3 5.12.4 5.12.5 5.12.6 5.12.7 5.12.8 5.12.9 5.13.0 5.13.1 5.13.2 5.14.0 5.14.1 5.14.2 5.14.3 5.15.0 5.15.1 5.16.0 5.16.1 5.16.2 5.16.3 5.16.4 5.17.0 5.17.1 5.17.2 5.17.3 5.17.4 5.17.5 5.17.6 5.18.0 5.19.0 5.2.0 5.2.1 5.2.2 5.2.3 5.20.0 5.21.0 5.21.1 5.21.2 5.21.3 5.22.0 5.22.1 5.22.2 5.22.3 5.22.4 5.23.0 5.23.1 5.23.2 5.3.0 5.3.1 5.3.2 5.3.3 5.3.4 5.3.5 5.3.6 5.3.7 5.4.0 5.4.1 5.4.2 5.5.0 5.5.1 5.5.2 5.6.0 5.6.1 5.6.2 5.6.3 5.6.4 5.7.0 5.7.1 5.8.0 5.8.1 5.9.0 3.0.0-beta.15 3.7.1 3.0.0-beta.16 3.7.2 3.0.0-beta.17 3.7.3 3.0.0-beta.18 3.7.4 3.0.0-beta.19 3.7.5 3.0.0-beta.2 3.7.6 3.0.0-beta.20 3.7.8 3.0.0-beta.21 3.70.0 3.0.0-beta.22 3.71.0 3.0.0-beta.23 3.71.1 3.0.0-beta.23.1 3.71.2 3.0.0-beta.23.2 3.71.3 3.0.0-beta.24 3.72.0 3.0.0-beta.25 3.73.0 3.0.0-beta.26 3.73.1 3.0.0-beta.27 3.73.2 3.0.0-beta.28 3.74.0 3.0.0-beta.29 3.74.1 3.0.0-beta.3 3.74.2 3.0.0-beta.30 3.74.3 3.0.0-beta.31 3.75.0 3.0.0-beta.32 3.75.1 3.0.0-beta.33 3.76.0 3.0.0-beta.33.1 3.77.0 3.0.0-beta.34.0.0 3.77.1 3.0.0-beta.36.0.0 3.78.0 3.0.0-beta.36.0.1 3.79.0 3.0.0-beta.36.2.0 3.8 3.0.0-beta.36.3.0 3.8.1 3.0.0-beta.36.3.1 3.8.2 3.0.0-beta.37.0.0 3.8.3 3.0.0-beta.4 3.8.4 3.0.0-beta.5 3.8.5 3.0.0-beta.6 3.8.6 3.0.0-beta.7 3.80.0 3.0.0-beta.7.1 3.81.0 3.0.0-beta.8 3.82.0 3.0.0-beta.9 3.83.0 3.0.0-rc.1.0.0 3.84.0 3.0.0-rc.1.0.1 3.84.1 3.0.0-rc.1.0.2 3.85.0 3.0.0-rc.1.0.3 3.85.1 3.0.0-rc.1.0.4 3.86.0 3.0.0-rc.2.0.0 3.87.0 3.0.0-rc.2.0.1 3.87.1 3.0.0-rc.2.0.2 3.87.2 3.0.0-rc.2.0.3 3.88.0 3.0.1 3.88.1 3.0.2 3.88.2 3.0.3 3.89.0 3.0.4 3.89.1 3.0.5 3.89.2 3.0.6 3.89.3 3.0.7 3.89.4 3.0.8 3.9.0 3.0.9 3.9.1 3.1.0 3.90.0 3.10 3.90.1 3.10.1 3.90.2 3.100.0 3.91.0 3.100.1 3.91.1 3.100.2 3.92.0 3.101.0 3.92.1 3.101.1 3.93.0 3.102.0 3.93.1 3.102.1 3.94.0 3.103.0 3.95.0 3.103.1 3.95.1 3.11.0 3.96.0 3.11.1 3.96.1 3.11.2 3.97.0 3.11.3 3.98.0 3.11.4 3.98.1 3.11.5 3.99.0 3.12.0 3.99.1 3.12.1 4.0.0 3.13.0 4.0.1 3.14.0 4.1.0 3.14.1 4.1.1 3.15.0 4.10.0 3.16.0 4.11.0 3.16.1 4.11.1 3.16.2 4.12.0 3.16.3 4.12.1 3.17.0 4.12.2 3.17.1 4.13.0 3.17.2 4.14.0 3.18.0 4.15.0 3.18.1 4.16.0 3.18.2 4.17.0 3.19.0 4.17.1 3.19.1 4.18.0 3.19.2 4.18.1 3.19.3 4.19.0 3.2.0 4.2.0 3.2.1 4.20.0 3.2.2 4.20.1 3.2.3 4.20.2 3.2.4 4.21.0 3.2.5 4.22.0 3.20.0 4.22.1 3.21.0 4.22.2 3.21.1 4.23.0 3.22.0 4.24.0 3.23.0 4.25.0 3.23.1 4.26.0 3.23.2 4.26.1 3.24.0 4.27.0 3.25.0 4.28.0 3.25.1 4.29.0 3.26.0 4.3.0 3.26.1 4.3.1 3.27.0 4.30.0 3.28.0 4.31.0 3.29.0 4.31.1 3.3.0 4.32.0 3.3.1 4.33.0 3.3.2 4.34.0 3.3.3 4.35.0 3.3.4 4.35.1 3.3.5 4.36.0 3.3.6 4.37.0 3.30.0 4.38.0 3.31.0 4.39.0 3.31.1 4.4.0 3.32.0 4.40.0 3.32.1 4.41.0 3.32.2 4.41.1 3.33.0 4.41.2 3.34.0 4.41.3 3.34.1 4.42.0 3.34.2 4.42.1 3.34.3 3.34.4 3.35.0 3.35.1 3.35.3 3.35.4 3.36.0 3.37.0 3.37.1 3.37.2 3.37.3 3.38.0 3.38.1 3.39.0 3.39.1 3.39.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.40.0 3.40.1 3.41.0 3.41.1 3.41.2 3.42.0 3.42.1 3.42.2 3.42.3 3.43.0 3.43.1 3.44.0 3.45.0 3.45.1 3.46.0 3.46.1 3.46.10 3.46.11 3.46.12 3.46.13 3.46.14 3.46.2 3.46.3 3.46.4 3.46.5 3.46.6 3.46.7 3.46.8 3.46.9 3.47.0 3.47.1 3.47.10 3.47.11 3.47.2 3.47.3 3.47.5 3.47.6 3.47.7 3.47.9 3.48.0 3.48.1 3.49.0 3.49.1 3.5.0 3.5.1 3.50.0 3.51.0 3.51.1 3.51.2 3.52.0 3.53.0 3.54.0 3.54.1 3.54.2 3.54.3 3.55.0 3.55.1 3.56.0 3.56.1 3.56.2 3.57.0 3.57.1 3.58.0 3.59.0 3.59.1 3.59.2 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.60.0 3.60.1 3.60.10 3.60.11 3.60.12 3.60.2 3.60.3 3.60.4 3.60.6 3.60.7 3.60.8 3.60.9 3.61.0 3.62.0 3.62.1 3.63.0 3.64.0 3.64.1 3.64.2 3.64.3 3.65.0 trunk 3.65.1 3.0.0 3.66.0 3.0.0-beta.1 3.67.0 3.0.0-beta.10 3.67.1 3.0.0-beta.11 3.68.0 3.0.0-beta.12 3.69.0 3.0.0-beta.13 3.69.1 3.0.0-beta.14 3.7.0
mailpoet / vendor-prefixed / doctrine / dbal / src / Schema / Table.php
mailpoet / vendor-prefixed / doctrine / dbal / src / Schema Last commit date
Exception 2 years ago Visitor 9 months ago AbstractAsset.php 2 years ago AbstractSchemaManager.php 9 months ago Column.php 2 years ago ColumnDiff.php 2 years ago Comparator.php 2 years ago Constraint.php 2 years ago DB2SchemaManager.php 2 years ago DefaultSchemaManagerFactory.php 2 years ago ForeignKeyConstraint.php 9 months ago Identifier.php 2 years ago Index.php 2 years ago LegacySchemaManagerFactory.php 2 years ago MySQLSchemaManager.php 9 months ago OracleSchemaManager.php 2 years ago PostgreSQLSchemaManager.php 9 months ago SQLServerSchemaManager.php 9 months ago Schema.php 2 years ago SchemaConfig.php 2 years ago SchemaDiff.php 2 years ago SchemaException.php 2 years ago SchemaManagerFactory.php 2 years ago Sequence.php 2 years ago SqliteSchemaManager.php 8 months ago Table.php 2 years ago TableDiff.php 2 years ago UniqueConstraint.php 2 years ago View.php 2 years ago
Table.php
456 lines
1 <?php
2 namespace MailPoetVendor\Doctrine\DBAL\Schema;
3 if (!defined('ABSPATH')) exit;
4 use MailPoetVendor\Doctrine\DBAL\Exception;
5 use MailPoetVendor\Doctrine\DBAL\Schema\Exception\InvalidTableName;
6 use MailPoetVendor\Doctrine\DBAL\Schema\Visitor\Visitor;
7 use MailPoetVendor\Doctrine\DBAL\Types\Type;
8 use MailPoetVendor\Doctrine\Deprecations\Deprecation;
9 use function array_filter;
10 use function array_keys;
11 use function array_merge;
12 use function in_array;
13 use function preg_match;
14 use function strlen;
15 use function strtolower;
16 use const ARRAY_FILTER_USE_KEY;
17 class Table extends AbstractAsset
18 {
19 protected $_columns = [];
20 protected $_indexes = [];
21 protected $_primaryKeyName;
22 protected $uniqueConstraints = [];
23 protected $_fkConstraints = [];
24 protected $_options = ['create_options' => []];
25 protected $_schemaConfig;
26 private array $implicitIndexes = [];
27 public function __construct(string $name, array $columns = [], array $indexes = [], array $uniqueConstraints = [], array $fkConstraints = [], array $options = [])
28 {
29 if ($name === '') {
30 throw InvalidTableName::new($name);
31 }
32 $this->_setName($name);
33 foreach ($columns as $column) {
34 $this->_addColumn($column);
35 }
36 foreach ($indexes as $idx) {
37 $this->_addIndex($idx);
38 }
39 foreach ($uniqueConstraints as $uniqueConstraint) {
40 $this->_addUniqueConstraint($uniqueConstraint);
41 }
42 foreach ($fkConstraints as $constraint) {
43 $this->_addForeignKeyConstraint($constraint);
44 }
45 $this->_options = array_merge($this->_options, $options);
46 }
47 public function setSchemaConfig(SchemaConfig $schemaConfig)
48 {
49 $this->_schemaConfig = $schemaConfig;
50 }
51 protected function _getMaxIdentifierLength()
52 {
53 if ($this->_schemaConfig instanceof SchemaConfig) {
54 return $this->_schemaConfig->getMaxIdentifierLength();
55 }
56 return 63;
57 }
58 public function setPrimaryKey(array $columnNames, $indexName = \false)
59 {
60 if ($indexName === \false) {
61 $indexName = 'primary';
62 }
63 $this->_addIndex($this->_createIndex($columnNames, $indexName, \true, \true));
64 foreach ($columnNames as $columnName) {
65 $column = $this->getColumn($columnName);
66 $column->setNotnull(\true);
67 }
68 return $this;
69 }
70 public function addIndex(array $columnNames, ?string $indexName = null, array $flags = [], array $options = [])
71 {
72 $indexName ??= $this->_generateIdentifierName(array_merge([$this->getName()], $columnNames), 'idx', $this->_getMaxIdentifierLength());
73 return $this->_addIndex($this->_createIndex($columnNames, $indexName, \false, \false, $flags, $options));
74 }
75 public function addUniqueConstraint(array $columnNames, ?string $indexName = null, array $flags = [], array $options = []) : Table
76 {
77 $indexName ??= $this->_generateIdentifierName(array_merge([$this->getName()], $columnNames), 'uniq', $this->_getMaxIdentifierLength());
78 return $this->_addUniqueConstraint($this->_createUniqueConstraint($columnNames, $indexName, $flags, $options));
79 }
80 public function dropPrimaryKey()
81 {
82 if ($this->_primaryKeyName === null) {
83 return;
84 }
85 $this->dropIndex($this->_primaryKeyName);
86 $this->_primaryKeyName = null;
87 }
88 public function dropIndex($name)
89 {
90 $name = $this->normalizeIdentifier($name);
91 if (!$this->hasIndex($name)) {
92 throw SchemaException::indexDoesNotExist($name, $this->_name);
93 }
94 unset($this->_indexes[$name]);
95 }
96 public function addUniqueIndex(array $columnNames, $indexName = null, array $options = [])
97 {
98 $indexName ??= $this->_generateIdentifierName(array_merge([$this->getName()], $columnNames), 'uniq', $this->_getMaxIdentifierLength());
99 return $this->_addIndex($this->_createIndex($columnNames, $indexName, \true, \false, [], $options));
100 }
101 public function renameIndex($oldName, $newName = null)
102 {
103 $oldName = $this->normalizeIdentifier($oldName);
104 $normalizedNewName = $this->normalizeIdentifier($newName);
105 if ($oldName === $normalizedNewName) {
106 return $this;
107 }
108 if (!$this->hasIndex($oldName)) {
109 throw SchemaException::indexDoesNotExist($oldName, $this->_name);
110 }
111 if ($this->hasIndex($normalizedNewName)) {
112 throw SchemaException::indexAlreadyExists($normalizedNewName, $this->_name);
113 }
114 $oldIndex = $this->_indexes[$oldName];
115 if ($oldIndex->isPrimary()) {
116 $this->dropPrimaryKey();
117 return $this->setPrimaryKey($oldIndex->getColumns(), $newName ?? \false);
118 }
119 unset($this->_indexes[$oldName]);
120 if ($oldIndex->isUnique()) {
121 return $this->addUniqueIndex($oldIndex->getColumns(), $newName, $oldIndex->getOptions());
122 }
123 return $this->addIndex($oldIndex->getColumns(), $newName, $oldIndex->getFlags(), $oldIndex->getOptions());
124 }
125 public function columnsAreIndexed(array $columnNames)
126 {
127 foreach ($this->getIndexes() as $index) {
128 if ($index->spansColumns($columnNames)) {
129 return \true;
130 }
131 }
132 return \false;
133 }
134 private function _createIndex(array $columnNames, $indexName, $isUnique, $isPrimary, array $flags = [], array $options = []) : Index
135 {
136 if (preg_match('(([^a-zA-Z0-9_]+))', $this->normalizeIdentifier($indexName)) === 1) {
137 throw SchemaException::indexNameInvalid($indexName);
138 }
139 foreach ($columnNames as $columnName) {
140 if (!$this->hasColumn($columnName)) {
141 throw SchemaException::columnDoesNotExist($columnName, $this->_name);
142 }
143 }
144 return new Index($indexName, $columnNames, $isUnique, $isPrimary, $flags, $options);
145 }
146 public function addColumn($name, $typeName, array $options = [])
147 {
148 $column = new Column($name, Type::getType($typeName), $options);
149 $this->_addColumn($column);
150 return $column;
151 }
152 public function changeColumn($name, array $options)
153 {
154 Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5747', '%s is deprecated. Use modifyColumn() instead.', __METHOD__);
155 return $this->modifyColumn($name, $options);
156 }
157 public function modifyColumn($name, array $options)
158 {
159 $column = $this->getColumn($name);
160 $column->setOptions($options);
161 return $this;
162 }
163 public function dropColumn($name)
164 {
165 $name = $this->normalizeIdentifier($name);
166 unset($this->_columns[$name]);
167 return $this;
168 }
169 public function addForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options = [], $name = null)
170 {
171 $name ??= $this->_generateIdentifierName(array_merge([$this->getName()], $localColumnNames), 'fk', $this->_getMaxIdentifierLength());
172 if ($foreignTable instanceof Table) {
173 foreach ($foreignColumnNames as $columnName) {
174 if (!$foreignTable->hasColumn($columnName)) {
175 throw SchemaException::columnDoesNotExist($columnName, $foreignTable->getName());
176 }
177 }
178 }
179 foreach ($localColumnNames as $columnName) {
180 if (!$this->hasColumn($columnName)) {
181 throw SchemaException::columnDoesNotExist($columnName, $this->_name);
182 }
183 }
184 $constraint = new ForeignKeyConstraint($localColumnNames, $foreignTable, $foreignColumnNames, $name, $options);
185 return $this->_addForeignKeyConstraint($constraint);
186 }
187 public function addOption($name, $value)
188 {
189 $this->_options[$name] = $value;
190 return $this;
191 }
192 protected function _addColumn(Column $column)
193 {
194 $columnName = $column->getName();
195 $columnName = $this->normalizeIdentifier($columnName);
196 if (isset($this->_columns[$columnName])) {
197 throw SchemaException::columnAlreadyExists($this->getName(), $columnName);
198 }
199 $this->_columns[$columnName] = $column;
200 }
201 protected function _addIndex(Index $indexCandidate)
202 {
203 $indexName = $indexCandidate->getName();
204 $indexName = $this->normalizeIdentifier($indexName);
205 $replacedImplicitIndexes = [];
206 foreach ($this->implicitIndexes as $name => $implicitIndex) {
207 if (!$implicitIndex->isFulfilledBy($indexCandidate) || !isset($this->_indexes[$name])) {
208 continue;
209 }
210 $replacedImplicitIndexes[] = $name;
211 }
212 if (isset($this->_indexes[$indexName]) && !in_array($indexName, $replacedImplicitIndexes, \true) || $this->_primaryKeyName !== null && $indexCandidate->isPrimary()) {
213 throw SchemaException::indexAlreadyExists($indexName, $this->_name);
214 }
215 foreach ($replacedImplicitIndexes as $name) {
216 unset($this->_indexes[$name], $this->implicitIndexes[$name]);
217 }
218 if ($indexCandidate->isPrimary()) {
219 $this->_primaryKeyName = $indexName;
220 }
221 $this->_indexes[$indexName] = $indexCandidate;
222 return $this;
223 }
224 protected function _addUniqueConstraint(UniqueConstraint $constraint) : Table
225 {
226 $mergedNames = array_merge([$this->getName()], $constraint->getColumns());
227 $name = strlen($constraint->getName()) > 0 ? $constraint->getName() : $this->_generateIdentifierName($mergedNames, 'fk', $this->_getMaxIdentifierLength());
228 $name = $this->normalizeIdentifier($name);
229 $this->uniqueConstraints[$name] = $constraint;
230 // If there is already an index that fulfills this requirements drop the request. In the case of __construct
231 // calling this method during hydration from schema-details all the explicitly added indexes lead to duplicates.
232 // This creates computation overhead in this case, however no duplicate indexes are ever added (column based).
233 $indexName = $this->_generateIdentifierName($mergedNames, 'idx', $this->_getMaxIdentifierLength());
234 $indexCandidate = $this->_createIndex($constraint->getColumns(), $indexName, \true, \false);
235 foreach ($this->_indexes as $existingIndex) {
236 if ($indexCandidate->isFulfilledBy($existingIndex)) {
237 return $this;
238 }
239 }
240 $this->implicitIndexes[$this->normalizeIdentifier($indexName)] = $indexCandidate;
241 return $this;
242 }
243 protected function _addForeignKeyConstraint(ForeignKeyConstraint $constraint)
244 {
245 $constraint->setLocalTable($this);
246 if (strlen($constraint->getName()) > 0) {
247 $name = $constraint->getName();
248 } else {
249 $name = $this->_generateIdentifierName(array_merge([$this->getName()], $constraint->getLocalColumns()), 'fk', $this->_getMaxIdentifierLength());
250 }
251 $name = $this->normalizeIdentifier($name);
252 $this->_fkConstraints[$name] = $constraint;
253 $indexName = $this->_generateIdentifierName(array_merge([$this->getName()], $constraint->getColumns()), 'idx', $this->_getMaxIdentifierLength());
254 $indexCandidate = $this->_createIndex($constraint->getColumns(), $indexName, \false, \false);
255 foreach ($this->_indexes as $existingIndex) {
256 if ($indexCandidate->isFulfilledBy($existingIndex)) {
257 return $this;
258 }
259 }
260 $this->_addIndex($indexCandidate);
261 $this->implicitIndexes[$this->normalizeIdentifier($indexName)] = $indexCandidate;
262 return $this;
263 }
264 public function hasForeignKey($name)
265 {
266 $name = $this->normalizeIdentifier($name);
267 return isset($this->_fkConstraints[$name]);
268 }
269 public function getForeignKey($name)
270 {
271 $name = $this->normalizeIdentifier($name);
272 if (!$this->hasForeignKey($name)) {
273 throw SchemaException::foreignKeyDoesNotExist($name, $this->_name);
274 }
275 return $this->_fkConstraints[$name];
276 }
277 public function removeForeignKey($name)
278 {
279 $name = $this->normalizeIdentifier($name);
280 if (!$this->hasForeignKey($name)) {
281 throw SchemaException::foreignKeyDoesNotExist($name, $this->_name);
282 }
283 unset($this->_fkConstraints[$name]);
284 }
285 public function hasUniqueConstraint(string $name) : bool
286 {
287 $name = $this->normalizeIdentifier($name);
288 return isset($this->uniqueConstraints[$name]);
289 }
290 public function getUniqueConstraint(string $name) : UniqueConstraint
291 {
292 $name = $this->normalizeIdentifier($name);
293 if (!$this->hasUniqueConstraint($name)) {
294 throw SchemaException::uniqueConstraintDoesNotExist($name, $this->_name);
295 }
296 return $this->uniqueConstraints[$name];
297 }
298 public function removeUniqueConstraint(string $name) : void
299 {
300 $name = $this->normalizeIdentifier($name);
301 if (!$this->hasUniqueConstraint($name)) {
302 throw SchemaException::uniqueConstraintDoesNotExist($name, $this->_name);
303 }
304 unset($this->uniqueConstraints[$name]);
305 }
306 public function getColumns()
307 {
308 $primaryKeyColumns = $this->getPrimaryKey() !== null ? $this->getPrimaryKeyColumns() : [];
309 $foreignKeyColumns = $this->getForeignKeyColumns();
310 $remainderColumns = $this->filterColumns(array_merge(array_keys($primaryKeyColumns), array_keys($foreignKeyColumns)), \true);
311 return array_merge($primaryKeyColumns, $foreignKeyColumns, $remainderColumns);
312 }
313 public function getForeignKeyColumns()
314 {
315 Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5731', '%s is deprecated. Use getForeignKey() and ForeignKeyConstraint::getLocalColumns() instead.', __METHOD__);
316 $foreignKeyColumns = [];
317 foreach ($this->getForeignKeys() as $foreignKey) {
318 $foreignKeyColumns = array_merge($foreignKeyColumns, $foreignKey->getLocalColumns());
319 }
320 return $this->filterColumns($foreignKeyColumns);
321 }
322 private function filterColumns(array $columnNames, bool $reverse = \false) : array
323 {
324 return array_filter($this->_columns, static function (string $columnName) use($columnNames, $reverse) : bool {
325 return in_array($columnName, $columnNames, \true) !== $reverse;
326 }, ARRAY_FILTER_USE_KEY);
327 }
328 public function hasColumn($name)
329 {
330 $name = $this->normalizeIdentifier($name);
331 return isset($this->_columns[$name]);
332 }
333 public function getColumn($name)
334 {
335 $name = $this->normalizeIdentifier($name);
336 if (!$this->hasColumn($name)) {
337 throw SchemaException::columnDoesNotExist($name, $this->_name);
338 }
339 return $this->_columns[$name];
340 }
341 public function getPrimaryKey()
342 {
343 if ($this->_primaryKeyName !== null) {
344 return $this->getIndex($this->_primaryKeyName);
345 }
346 return null;
347 }
348 public function getPrimaryKeyColumns()
349 {
350 Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5731', '%s is deprecated. Use getPrimaryKey() and Index::getColumns() instead.', __METHOD__);
351 $primaryKey = $this->getPrimaryKey();
352 if ($primaryKey === null) {
353 throw new Exception('Table ' . $this->getName() . ' has no primary key.');
354 }
355 return $this->filterColumns($primaryKey->getColumns());
356 }
357 public function hasPrimaryKey()
358 {
359 Deprecation::trigger('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5731', '%s is deprecated. Use getPrimaryKey() instead.', __METHOD__);
360 return $this->_primaryKeyName !== null && $this->hasIndex($this->_primaryKeyName);
361 }
362 public function hasIndex($name)
363 {
364 $name = $this->normalizeIdentifier($name);
365 return isset($this->_indexes[$name]);
366 }
367 public function getIndex($name)
368 {
369 $name = $this->normalizeIdentifier($name);
370 if (!$this->hasIndex($name)) {
371 throw SchemaException::indexDoesNotExist($name, $this->_name);
372 }
373 return $this->_indexes[$name];
374 }
375 public function getIndexes()
376 {
377 return $this->_indexes;
378 }
379 public function getUniqueConstraints() : array
380 {
381 return $this->uniqueConstraints;
382 }
383 public function getForeignKeys()
384 {
385 return $this->_fkConstraints;
386 }
387 public function hasOption($name)
388 {
389 return isset($this->_options[$name]);
390 }
391 public function getOption($name)
392 {
393 return $this->_options[$name];
394 }
395 public function getOptions()
396 {
397 return $this->_options;
398 }
399 public function visit(Visitor $visitor)
400 {
401 Deprecation::triggerIfCalledFromOutside('doctrine/dbal', 'https://github.com/doctrine/dbal/pull/5435', 'Table::visit() is deprecated.');
402 $visitor->acceptTable($this);
403 foreach ($this->getColumns() as $column) {
404 $visitor->acceptColumn($this, $column);
405 }
406 foreach ($this->getIndexes() as $index) {
407 $visitor->acceptIndex($this, $index);
408 }
409 foreach ($this->getForeignKeys() as $constraint) {
410 $visitor->acceptForeignKey($this, $constraint);
411 }
412 }
413 public function __clone()
414 {
415 foreach ($this->_columns as $k => $column) {
416 $this->_columns[$k] = clone $column;
417 }
418 foreach ($this->_indexes as $k => $index) {
419 $this->_indexes[$k] = clone $index;
420 }
421 foreach ($this->_fkConstraints as $k => $fk) {
422 $this->_fkConstraints[$k] = clone $fk;
423 $this->_fkConstraints[$k]->setLocalTable($this);
424 }
425 }
426 private function _createUniqueConstraint(array $columnNames, string $indexName, array $flags = [], array $options = []) : UniqueConstraint
427 {
428 if (preg_match('(([^a-zA-Z0-9_]+))', $this->normalizeIdentifier($indexName)) === 1) {
429 throw SchemaException::indexNameInvalid($indexName);
430 }
431 foreach ($columnNames as $columnName) {
432 if (!$this->hasColumn($columnName)) {
433 throw SchemaException::columnDoesNotExist($columnName, $this->_name);
434 }
435 }
436 return new UniqueConstraint($indexName, $columnNames, $flags, $options);
437 }
438 private function normalizeIdentifier(?string $identifier) : string
439 {
440 if ($identifier === null) {
441 return '';
442 }
443 return $this->trimQuotes(strtolower($identifier));
444 }
445 public function setComment(?string $comment) : self
446 {
447 // For keeping backward compatibility with MySQL in previous releases, table comments are stored as options.
448 $this->addOption('comment', $comment);
449 return $this;
450 }
451 public function getComment() : ?string
452 {
453 return $this->_options['comment'] ?? null;
454 }
455 }
456