Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Doctrine\DBAL\Schema;
4
 
5
use Doctrine\DBAL\Platforms\AbstractPlatform;
6
use Doctrine\Deprecations\Deprecation;
7
 
8
use function array_filter;
9
use function array_values;
10
use function count;
11
 
12
/**
13
 * Table Diff.
14
 */
15
class TableDiff
16
{
17
    /**
18
     * @deprecated Use {@see getOldTable()} instead.
19
     *
20
     * @var string
21
     */
22
    public $name;
23
 
24
    /**
25
     * @deprecated Rename tables via {@link AbstractSchemaManager::renameTable()} instead.
26
     *
27
     * @var string|false
28
     */
29
    public $newName = false;
30
 
31
    /**
32
     * All added columns
33
     *
34
     * @internal Use {@see getAddedColumns()} instead.
35
     *
36
     * @var Column[]
37
     */
38
    public $addedColumns;
39
 
40
    /**
41
     * All modified columns
42
     *
43
     * @internal Use {@see getModifiedColumns()} instead.
44
     *
45
     * @var ColumnDiff[]
46
     */
47
    public $changedColumns = [];
48
 
49
    /**
50
     * All dropped columns
51
     *
52
     * @internal Use {@see getDroppedColumns()} instead.
53
     *
54
     * @var Column[]
55
     */
56
    public $removedColumns = [];
57
 
58
    /**
59
     * Columns that are only renamed from key to column instance name.
60
     *
61
     * @internal Use {@see getRenamedColumns()} instead.
62
     *
63
     * @var Column[]
64
     */
65
    public $renamedColumns = [];
66
 
67
    /**
68
     * All added indexes.
69
     *
70
     * @internal Use {@see getAddedIndexes()} instead.
71
     *
72
     * @var Index[]
73
     */
74
    public $addedIndexes = [];
75
 
76
    /**
77
     * All changed indexes.
78
     *
79
     * @internal Use {@see getModifiedIndexes()} instead.
80
     *
81
     * @var Index[]
82
     */
83
    public $changedIndexes = [];
84
 
85
    /**
86
     * All removed indexes
87
     *
88
     * @internal Use {@see getDroppedIndexes()} instead.
89
     *
90
     * @var Index[]
91
     */
92
    public $removedIndexes = [];
93
 
94
    /**
95
     * Indexes that are only renamed but are identical otherwise.
96
     *
97
     * @internal Use {@see getRenamedIndexes()} instead.
98
     *
99
     * @var Index[]
100
     */
101
    public $renamedIndexes = [];
102
 
103
    /**
104
     * All added foreign key definitions
105
     *
106
     * @internal Use {@see getAddedForeignKeys()} instead.
107
     *
108
     * @var ForeignKeyConstraint[]
109
     */
110
    public $addedForeignKeys = [];
111
 
112
    /**
113
     * All changed foreign keys
114
     *
115
     * @internal Use {@see getModifiedForeignKeys()} instead.
116
     *
117
     * @var ForeignKeyConstraint[]
118
     */
119
    public $changedForeignKeys = [];
120
 
121
    /**
122
     * All removed foreign keys
123
     *
124
     * @internal Use {@see getDroppedForeignKeys()} instead.
125
     *
126
     * @var (ForeignKeyConstraint|string)[]
127
     */
128
    public $removedForeignKeys = [];
129
 
130
    /**
131
     * @internal Use {@see getOldTable()} instead.
132
     *
133
     * @var Table|null
134
     */
135
    public $fromTable;
136
 
137
    /**
138
     * Constructs a TableDiff object.
139
     *
140
     * @internal The diff can be only instantiated by a {@see Comparator}.
141
     *
142
     * @param string                            $tableName
143
     * @param array<Column>                     $addedColumns
144
     * @param array<ColumnDiff>                 $modifiedColumns
145
     * @param array<Column>                     $droppedColumns
146
     * @param array<Index>                      $addedIndexes
147
     * @param array<Index>                      $changedIndexes
148
     * @param array<Index>                      $removedIndexes
149
     * @param list<ForeignKeyConstraint>        $addedForeignKeys
150
     * @param list<ForeignKeyConstraint>        $changedForeignKeys
151
     * @param list<ForeignKeyConstraint|string> $removedForeignKeys
152
     * @param array<string,Column>              $renamedColumns
153
     * @param array<string,Index>               $renamedIndexes
154
     */
155
    public function __construct(
156
        $tableName,
157
        $addedColumns = [],
158
        $modifiedColumns = [],
159
        $droppedColumns = [],
160
        $addedIndexes = [],
161
        $changedIndexes = [],
162
        $removedIndexes = [],
163
        ?Table $fromTable = null,
164
        $addedForeignKeys = [],
165
        $changedForeignKeys = [],
166
        $removedForeignKeys = [],
167
        $renamedColumns = [],
168
        $renamedIndexes = []
169
    ) {
170
        $this->name               = $tableName;
171
        $this->addedColumns       = $addedColumns;
172
        $this->changedColumns     = $modifiedColumns;
173
        $this->renamedColumns     = $renamedColumns;
174
        $this->removedColumns     = $droppedColumns;
175
        $this->addedIndexes       = $addedIndexes;
176
        $this->changedIndexes     = $changedIndexes;
177
        $this->renamedIndexes     = $renamedIndexes;
178
        $this->removedIndexes     = $removedIndexes;
179
        $this->addedForeignKeys   = $addedForeignKeys;
180
        $this->changedForeignKeys = $changedForeignKeys;
181
        $this->removedForeignKeys = $removedForeignKeys;
182
 
183
        if ($fromTable !== null) {
184
            Deprecation::trigger(
185
                'doctrine/dbal',
186
                'https://github.com/doctrine/dbal/pull/5678',
187
                'Not passing the $fromColumn to %s is deprecated.',
188
                __METHOD__,
189
            );
190
        }
191
 
192
        $this->fromTable = $fromTable;
193
    }
194
 
195
    /**
196
     * @deprecated Use {@see getOldTable()} instead.
197
     *
198
     * @param AbstractPlatform $platform The platform to use for retrieving this table diff's name.
199
     *
200
     * @return Identifier
201
     */
202
    public function getName(AbstractPlatform $platform)
203
    {
204
        return new Identifier(
205
            $this->fromTable instanceof Table ? $this->fromTable->getQuotedName($platform) : $this->name,
206
        );
207
    }
208
 
209
    /**
210
     * @deprecated Rename tables via {@link AbstractSchemaManager::renameTable()} instead.
211
     *
212
     * @return Identifier|false
213
     */
214
    public function getNewName()
215
    {
216
        Deprecation::triggerIfCalledFromOutside(
217
            'doctrine/dbal',
218
            'https://github.com/doctrine/dbal/pull/5663',
219
            '%s is deprecated. Rename tables via AbstractSchemaManager::renameTable() instead.',
220
            __METHOD__,
221
        );
222
 
223
        if ($this->newName === false) {
224
            return false;
225
        }
226
 
227
        return new Identifier($this->newName);
228
    }
229
 
230
    public function getOldTable(): ?Table
231
    {
232
        return $this->fromTable;
233
    }
234
 
235
    /** @return list<Column> */
236
    public function getAddedColumns(): array
237
    {
238
        return array_values($this->addedColumns);
239
    }
240
 
241
    /** @return list<ColumnDiff> */
242
    public function getModifiedColumns(): array
243
    {
244
        return array_values($this->changedColumns);
245
    }
246
 
247
    /** @return list<Column> */
248
    public function getDroppedColumns(): array
249
    {
250
        return array_values($this->removedColumns);
251
    }
252
 
253
    /** @return array<string,Column> */
254
    public function getRenamedColumns(): array
255
    {
256
        return $this->renamedColumns;
257
    }
258
 
259
    /** @return list<Index> */
260
    public function getAddedIndexes(): array
261
    {
262
        return array_values($this->addedIndexes);
263
    }
264
 
265
    /**
266
     * @internal This method exists only for compatibility with the current implementation of schema managers
267
     *           that modify the diff while processing it.
268
     */
269
    public function unsetAddedIndex(Index $index): void
270
    {
271
        $this->addedIndexes = array_filter(
272
            $this->addedIndexes,
273
            static function (Index $addedIndex) use ($index): bool {
274
                return $addedIndex !== $index;
275
            },
276
        );
277
    }
278
 
279
    /** @return array<Index> */
280
    public function getModifiedIndexes(): array
281
    {
282
        return array_values($this->changedIndexes);
283
    }
284
 
285
    /** @return list<Index> */
286
    public function getDroppedIndexes(): array
287
    {
288
        return array_values($this->removedIndexes);
289
    }
290
 
291
    /**
292
     * @internal This method exists only for compatibility with the current implementation of schema managers
293
     *           that modify the diff while processing it.
294
     */
295
    public function unsetDroppedIndex(Index $index): void
296
    {
297
        $this->removedIndexes = array_filter(
298
            $this->removedIndexes,
299
            static function (Index $removedIndex) use ($index): bool {
300
                return $removedIndex !== $index;
301
            },
302
        );
303
    }
304
 
305
    /** @return array<string,Index> */
306
    public function getRenamedIndexes(): array
307
    {
308
        return $this->renamedIndexes;
309
    }
310
 
311
    /** @return list<ForeignKeyConstraint> */
312
    public function getAddedForeignKeys(): array
313
    {
314
        return $this->addedForeignKeys;
315
    }
316
 
317
    /** @return list<ForeignKeyConstraint> */
318
    public function getModifiedForeignKeys(): array
319
    {
320
        return $this->changedForeignKeys;
321
    }
322
 
323
    /** @return list<ForeignKeyConstraint|string> */
324
    public function getDroppedForeignKeys(): array
325
    {
326
        return $this->removedForeignKeys;
327
    }
328
 
329
    /**
330
     * @internal This method exists only for compatibility with the current implementation of the schema comparator.
331
     *
332
     * @param ForeignKeyConstraint|string $foreignKey
333
     */
334
    public function unsetDroppedForeignKey($foreignKey): void
335
    {
336
        $this->removedForeignKeys = array_filter(
337
            $this->removedForeignKeys,
338
            static function ($removedForeignKey) use ($foreignKey): bool {
339
                return $removedForeignKey !== $foreignKey;
340
            },
341
        );
342
    }
343
 
344
    /**
345
     * Returns whether the diff is empty (contains no changes).
346
     */
347
    public function isEmpty(): bool
348
    {
349
        return count($this->addedColumns) === 0
350
            && count($this->changedColumns) === 0
351
            && count($this->removedColumns) === 0
352
            && count($this->renamedColumns) === 0
353
            && count($this->addedIndexes) === 0
354
            && count($this->changedIndexes) === 0
355
            && count($this->removedIndexes) === 0
356
            && count($this->renamedIndexes) === 0
357
            && count($this->addedForeignKeys) === 0
358
            && count($this->changedForeignKeys) === 0
359
            && count($this->removedForeignKeys) === 0;
360
    }
361
}