1 | <?php |
||
14 | class TableDumperCollection extends ArrayObject |
||
15 | { |
||
16 | /** |
||
17 | * {@inheritDoc} |
||
18 | */ |
||
19 | 15 | public function append($value) |
|
29 | |||
30 | /** |
||
31 | * {@inheritDoc} |
||
32 | */ |
||
33 | 30 | public function offsetSet($index, $newval) |
|
43 | |||
44 | |||
45 | /** |
||
46 | * @param Table|string Adds a table, either by name, or by Table instance, to the collection |
||
47 | * |
||
48 | * @return TableDumper Retruns a TableDumper of the table that was just added |
||
49 | */ |
||
50 | 15 | public function addTable($table): TableDumper |
|
69 | |||
70 | |||
71 | /** |
||
72 | * @param TableDumperCollection|array<TableDumper|Table|string> Adds a list of tables, either by passing TableDumperCollection, or an array containing either TableDumper objects, Table objects or table naes |
||
73 | * |
||
74 | * @return TableDumperCollection Returns a TableDumperCollection of the list of tables that was just added |
||
75 | */ |
||
76 | 18 | public function addListTables($listTables): TableDumperCollection |
|
104 | |||
105 | /** |
||
106 | * Writes all DROP statements to the dump stream |
||
107 | * |
||
108 | * @param resource $stream Stream to write the dump to |
||
109 | * |
||
110 | * @return void |
||
111 | */ |
||
112 | 3 | public function dumpDropStatements($stream): void |
|
113 | { |
||
114 | 3 | foreach ($this as $dumper) { |
|
115 | 3 | if ($dumper->hasDrop()) { |
|
116 | 3 | $dumper->dumpDropStatement($stream); |
|
117 | } |
||
118 | } |
||
119 | 3 | } |
|
120 | |||
121 | /** |
||
122 | * Writes all INSERT statements to the dump stream |
||
123 | * |
||
124 | * @param PDO $db PDO instance to use for DB queries |
||
125 | * @param resource $stream Stream to write the dump to |
||
126 | * |
||
127 | * @return void |
||
128 | */ |
||
129 | public function dumpInsertStatements(PDO $db, $stream): void |
||
137 | |||
138 | /** |
||
139 | * Writes all the SQL statements of this dumper to the dump stream |
||
140 | * |
||
141 | * @param PDO $db PDO instance to use for DB queries |
||
142 | * @param resource $stream Stream to write the dump to |
||
143 | * @param boolean $groupDrops Determines if DROP statements will be grouped |
||
144 | * @param boolean $groupInserts Determines if INSERT statements will be grouped |
||
145 | * |
||
146 | * @return void |
||
147 | */ |
||
148 | public function dump(PDO $db, $stream, bool $groupDrops = false, bool $groupInserts = false): void |
||
149 | { |
||
150 | if ($groupDrops) { |
||
151 | $this->dumpDropStatements($stream); |
||
152 | } |
||
153 | |||
154 | foreach ($this as $dumper) { |
||
155 | if ($dumper->hasDrop() && !$groupDrops) { |
||
156 | $dumper->dumpDropStatement($stream); |
||
157 | } |
||
158 | |||
159 | if ($dumper->hasStructure()) { |
||
160 | $dumper->dumpCreateStatement($db, $stream); |
||
161 | } |
||
162 | |||
163 | if ($dumper->hasData() && !$groupInserts) { |
||
164 | $dumper->dumpInsertStatement($db, $stream); |
||
165 | } |
||
166 | } |
||
167 | |||
168 | if ($groupInserts) { |
||
169 | $this->dumpInsertStatements($db, $stream); |
||
170 | } |
||
171 | } |
||
172 | |||
173 | |||
174 | 3 | public function __call(string $name, array $arguments) |
|
183 | } |