diff options
Diffstat (limited to 'vendor/doctrine/dbal/src/Schema/TableDiff.php')
-rw-r--r-- | vendor/doctrine/dbal/src/Schema/TableDiff.php | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Schema/TableDiff.php b/vendor/doctrine/dbal/src/Schema/TableDiff.php new file mode 100644 index 0000000..1cd59e8 --- /dev/null +++ b/vendor/doctrine/dbal/src/Schema/TableDiff.php | |||
@@ -0,0 +1,164 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Doctrine\DBAL\Schema; | ||
6 | |||
7 | use function array_filter; | ||
8 | use function count; | ||
9 | |||
10 | /** | ||
11 | * Table Diff. | ||
12 | */ | ||
13 | class TableDiff | ||
14 | { | ||
15 | /** | ||
16 | * Constructs a TableDiff object. | ||
17 | * | ||
18 | * @internal The diff can be only instantiated by a {@see Comparator}. | ||
19 | * | ||
20 | * @param array<ForeignKeyConstraint> $droppedForeignKeys | ||
21 | * @param array<Column> $addedColumns | ||
22 | * @param array<ColumnDiff> $modifiedColumns | ||
23 | * @param array<Column> $droppedColumns | ||
24 | * @param array<string, Column> $renamedColumns | ||
25 | * @param array<Index> $addedIndexes | ||
26 | * @param array<Index> $modifiedIndexes | ||
27 | * @param array<Index> $droppedIndexes | ||
28 | * @param array<string, Index> $renamedIndexes | ||
29 | * @param array<ForeignKeyConstraint> $addedForeignKeys | ||
30 | * @param array<ForeignKeyConstraint> $modifiedForeignKeys | ||
31 | */ | ||
32 | public function __construct( | ||
33 | private readonly Table $oldTable, | ||
34 | private readonly array $addedColumns, | ||
35 | private readonly array $modifiedColumns, | ||
36 | private readonly array $droppedColumns, | ||
37 | private readonly array $renamedColumns, | ||
38 | private array $addedIndexes, | ||
39 | private readonly array $modifiedIndexes, | ||
40 | private array $droppedIndexes, | ||
41 | private readonly array $renamedIndexes, | ||
42 | private readonly array $addedForeignKeys, | ||
43 | private readonly array $modifiedForeignKeys, | ||
44 | private readonly array $droppedForeignKeys, | ||
45 | ) { | ||
46 | } | ||
47 | |||
48 | public function getOldTable(): Table | ||
49 | { | ||
50 | return $this->oldTable; | ||
51 | } | ||
52 | |||
53 | /** @return array<Column> */ | ||
54 | public function getAddedColumns(): array | ||
55 | { | ||
56 | return $this->addedColumns; | ||
57 | } | ||
58 | |||
59 | /** @return array<ColumnDiff> */ | ||
60 | public function getModifiedColumns(): array | ||
61 | { | ||
62 | return $this->modifiedColumns; | ||
63 | } | ||
64 | |||
65 | /** @return array<Column> */ | ||
66 | public function getDroppedColumns(): array | ||
67 | { | ||
68 | return $this->droppedColumns; | ||
69 | } | ||
70 | |||
71 | /** @return array<string,Column> */ | ||
72 | public function getRenamedColumns(): array | ||
73 | { | ||
74 | return $this->renamedColumns; | ||
75 | } | ||
76 | |||
77 | /** @return array<Index> */ | ||
78 | public function getAddedIndexes(): array | ||
79 | { | ||
80 | return $this->addedIndexes; | ||
81 | } | ||
82 | |||
83 | /** | ||
84 | * @internal This method exists only for compatibility with the current implementation of schema managers | ||
85 | * that modify the diff while processing it. | ||
86 | */ | ||
87 | public function unsetAddedIndex(Index $index): void | ||
88 | { | ||
89 | $this->addedIndexes = array_filter( | ||
90 | $this->addedIndexes, | ||
91 | static function (Index $addedIndex) use ($index): bool { | ||
92 | return $addedIndex !== $index; | ||
93 | }, | ||
94 | ); | ||
95 | } | ||
96 | |||
97 | /** @return array<Index> */ | ||
98 | public function getModifiedIndexes(): array | ||
99 | { | ||
100 | return $this->modifiedIndexes; | ||
101 | } | ||
102 | |||
103 | /** @return array<Index> */ | ||
104 | public function getDroppedIndexes(): array | ||
105 | { | ||
106 | return $this->droppedIndexes; | ||
107 | } | ||
108 | |||
109 | /** | ||
110 | * @internal This method exists only for compatibility with the current implementation of schema managers | ||
111 | * that modify the diff while processing it. | ||
112 | */ | ||
113 | public function unsetDroppedIndex(Index $index): void | ||
114 | { | ||
115 | $this->droppedIndexes = array_filter( | ||
116 | $this->droppedIndexes, | ||
117 | static function (Index $droppedIndex) use ($index): bool { | ||
118 | return $droppedIndex !== $index; | ||
119 | }, | ||
120 | ); | ||
121 | } | ||
122 | |||
123 | /** @return array<string,Index> */ | ||
124 | public function getRenamedIndexes(): array | ||
125 | { | ||
126 | return $this->renamedIndexes; | ||
127 | } | ||
128 | |||
129 | /** @return array<ForeignKeyConstraint> */ | ||
130 | public function getAddedForeignKeys(): array | ||
131 | { | ||
132 | return $this->addedForeignKeys; | ||
133 | } | ||
134 | |||
135 | /** @return array<ForeignKeyConstraint> */ | ||
136 | public function getModifiedForeignKeys(): array | ||
137 | { | ||
138 | return $this->modifiedForeignKeys; | ||
139 | } | ||
140 | |||
141 | /** @return array<ForeignKeyConstraint> */ | ||
142 | public function getDroppedForeignKeys(): array | ||
143 | { | ||
144 | return $this->droppedForeignKeys; | ||
145 | } | ||
146 | |||
147 | /** | ||
148 | * Returns whether the diff is empty (contains no changes). | ||
149 | */ | ||
150 | public function isEmpty(): bool | ||
151 | { | ||
152 | return count($this->addedColumns) === 0 | ||
153 | && count($this->modifiedColumns) === 0 | ||
154 | && count($this->droppedColumns) === 0 | ||
155 | && count($this->renamedColumns) === 0 | ||
156 | && count($this->addedIndexes) === 0 | ||
157 | && count($this->modifiedIndexes) === 0 | ||
158 | && count($this->droppedIndexes) === 0 | ||
159 | && count($this->renamedIndexes) === 0 | ||
160 | && count($this->addedForeignKeys) === 0 | ||
161 | && count($this->modifiedForeignKeys) === 0 | ||
162 | && count($this->droppedForeignKeys) === 0; | ||
163 | } | ||
164 | } | ||