1 | <?php |
||
46 | abstract class AbstractMigration implements MigrationInterface |
||
47 | { |
||
48 | /** |
||
49 | * @var string |
||
50 | */ |
||
51 | protected $environment; |
||
52 | /** |
||
53 | * @var float |
||
54 | */ |
||
55 | protected $version; |
||
56 | |||
57 | /** |
||
58 | * @var \Phinx\Db\Adapter\AdapterInterface |
||
59 | */ |
||
60 | protected $adapter; |
||
61 | |||
62 | /** |
||
63 | * @var \Symfony\Component\Console\Output\OutputInterface |
||
64 | */ |
||
65 | protected $output; |
||
66 | |||
67 | /** |
||
68 | * @var \Symfony\Component\Console\Input\InputInterface |
||
69 | */ |
||
70 | protected $input; |
||
71 | |||
72 | /** |
||
73 | * Whether this migration is being applied or reverted |
||
74 | * |
||
75 | * @var bool |
||
76 | */ |
||
77 | protected $isMigratingUp = true; |
||
78 | |||
79 | /** |
||
80 | * List of all the table objects created by this migration |
||
81 | * |
||
82 | 406 | * @var array |
|
83 | */ |
||
84 | 406 | protected $tables = []; |
|
85 | 406 | ||
86 | 384 | /** |
|
87 | 384 | * Class Constructor. |
|
88 | 406 | * |
|
89 | 384 | * @param string $environment Environment Detected |
|
90 | 384 | * @param int $version Migration Version |
|
91 | * @param \Symfony\Component\Console\Input\InputInterface|null $input |
||
92 | 406 | * @param \Symfony\Component\Console\Output\OutputInterface|null $output |
|
93 | 406 | */ |
|
94 | final public function __construct($environment, $version, InputInterface $input = null, OutputInterface $output = null) |
||
109 | 1 | ||
110 | /** |
||
111 | * Initialize method. |
||
112 | * |
||
113 | * @return void |
||
114 | 1 | */ |
|
115 | protected function init() |
||
118 | |||
119 | /** |
||
120 | * {@inheritdoc} |
||
121 | 21 | */ |
|
122 | public function setAdapter(AdapterInterface $adapter) |
||
128 | |||
129 | /** |
||
130 | 13 | * {@inheritdoc} |
|
131 | */ |
||
132 | 13 | public function getAdapter() |
|
136 | |||
137 | /** |
||
138 | 384 | * {@inheritdoc} |
|
139 | */ |
||
140 | 384 | public function setInput(InputInterface $input) |
|
141 | 384 | { |
|
142 | $this->input = $input; |
||
143 | |||
144 | return $this; |
||
145 | } |
||
146 | |||
147 | 2 | /** |
|
148 | * {@inheritdoc} |
||
149 | 2 | */ |
|
150 | public function getInput() |
||
151 | { |
||
152 | return $this->input; |
||
153 | } |
||
154 | |||
155 | 385 | /** |
|
156 | * {@inheritdoc} |
||
157 | 385 | */ |
|
158 | 385 | public function setOutput(OutputInterface $output) |
|
164 | 3 | ||
165 | /** |
||
166 | 3 | * {@inheritdoc} |
|
167 | */ |
||
168 | public function getOutput() |
||
172 | 140 | ||
173 | /** |
||
174 | 140 | * {@inheritdoc} |
|
175 | */ |
||
176 | public function getName() |
||
180 | 1 | ||
181 | /** |
||
182 | 1 | * {@inheritdoc} |
|
183 | 1 | */ |
|
184 | public function getEnvironment() |
||
188 | |||
189 | 279 | /** |
|
190 | * {@inheritdoc} |
||
191 | 279 | */ |
|
192 | public function setVersion($version) |
||
198 | |||
199 | 10 | /** |
|
200 | 10 | * {@inheritdoc} |
|
201 | */ |
||
202 | public function getVersion() |
||
206 | 2 | ||
207 | /** |
||
208 | 2 | * {@inheritdoc} |
|
209 | */ |
||
210 | public function setMigratingUp($isMigratingUp) |
||
216 | 3 | ||
217 | /** |
||
218 | * {@inheritdoc} |
||
219 | */ |
||
220 | public function isMigratingUp() |
||
224 | 1 | ||
225 | /** |
||
226 | * {@inheritdoc} |
||
227 | */ |
||
228 | public function execute($sql) |
||
232 | 1 | ||
233 | /** |
||
234 | * {@inheritdoc} |
||
235 | */ |
||
236 | public function query($sql) |
||
240 | 1 | ||
241 | /** |
||
242 | * {@inheritdoc} |
||
243 | */ |
||
244 | public function getQueryBuilder() |
||
248 | |||
249 | 3 | /** |
|
250 | 2 | * {@inheritdoc} |
|
251 | 2 | */ |
|
252 | 3 | public function fetchRow($sql) |
|
256 | |||
257 | /** |
||
258 | 1 | * {@inheritdoc} |
|
259 | */ |
||
260 | 1 | public function fetchAll($sql) |
|
264 | |||
265 | /** |
||
266 | 1 | * {@inheritdoc} |
|
267 | */ |
||
268 | 1 | public function insert($table, $data) |
|
269 | 1 | { |
|
270 | trigger_error('insert() is deprecated since 0.10.0. Use $this->table($tableName)->insert($data)->save() instead.', E_USER_DEPRECATED); |
||
271 | // convert to table object |
||
272 | if (is_string($table)) { |
||
273 | $table = new Table($table, [], $this->getAdapter()); |
||
274 | 1 | } |
|
275 | $table->insert($data)->save(); |
||
276 | 1 | } |
|
277 | |||
278 | /** |
||
279 | * {@inheritdoc} |
||
280 | */ |
||
281 | public function createDatabase($name, $options) |
||
285 | |||
286 | /** |
||
287 | * {@inheritdoc} |
||
288 | */ |
||
289 | public function dropDatabase($name) |
||
293 | 1 | ||
294 | /** |
||
295 | 1 | * {@inheritdoc} |
|
296 | 1 | */ |
|
297 | public function hasTable($tableName) |
||
301 | |||
302 | /** |
||
303 | * {@inheritdoc} |
||
304 | */ |
||
305 | public function table($tableName, $options = []) |
||
312 | |||
313 | /** |
||
314 | * A short-hand method to drop the given database table. |
||
315 | * |
||
316 | * @deprecated since 0.10.0. Use $this->table($tableName)->drop()->save() instead. |
||
317 | * @param string $tableName Table Name |
||
318 | * @return void |
||
319 | */ |
||
320 | public function dropTable($tableName) |
||
325 | |||
326 | /** |
||
327 | * Perform checks on the migration, print a warning |
||
328 | * if there are potential problems. |
||
329 | * |
||
330 | * Right now, the only check is if there is both a `change()` and |
||
331 | * an `up()` or a `down()` method. |
||
332 | * |
||
333 | * @param string|null $direction |
||
334 | * |
||
335 | * @return void |
||
336 | */ |
||
337 | public function preFlightCheck($direction = null) |
||
348 | |||
349 | /** |
||
350 | * Perform checks on the migration after completion |
||
351 | * |
||
352 | * Right now, the only check is whether all changes were committed |
||
353 | * |
||
354 | * @param string|null $direction direction of migration |
||
355 | * |
||
356 | * @return void |
||
357 | */ |
||
358 | public function postFlightCheck($direction = null) |
||
366 | } |
||
367 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.