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 | * Class Constructor. |
||
81 | * |
||
82 | 406 | * @param string $environment Environment Detected |
|
83 | * @param int $version Migration Version |
||
84 | 406 | * @param \Symfony\Component\Console\Input\InputInterface|null $input |
|
85 | 406 | * @param \Symfony\Component\Console\Output\OutputInterface|null $output |
|
86 | 384 | */ |
|
87 | 384 | final public function __construct($environment, $version, InputInterface $input = null, OutputInterface $output = null) |
|
102 | 406 | ||
103 | /** |
||
104 | * Initialize method. |
||
105 | * |
||
106 | * @return void |
||
107 | 1 | */ |
|
108 | protected function init() |
||
111 | |||
112 | /** |
||
113 | * {@inheritdoc} |
||
114 | 1 | */ |
|
115 | public function setAdapter(AdapterInterface $adapter) |
||
121 | 21 | ||
122 | /** |
||
123 | 21 | * {@inheritdoc} |
|
124 | 21 | */ |
|
125 | public function getAdapter() |
||
129 | |||
130 | 13 | /** |
|
131 | * {@inheritdoc} |
||
132 | 13 | */ |
|
133 | public function setInput(InputInterface $input) |
||
134 | { |
||
135 | $this->input = $input; |
||
136 | |||
137 | return $this; |
||
138 | 384 | } |
|
139 | |||
140 | 384 | /** |
|
141 | 384 | * {@inheritdoc} |
|
142 | */ |
||
143 | public function getInput() |
||
144 | { |
||
145 | return $this->input; |
||
146 | } |
||
147 | 2 | ||
148 | /** |
||
149 | 2 | * {@inheritdoc} |
|
150 | */ |
||
151 | public function setOutput(OutputInterface $output) |
||
157 | 385 | ||
158 | 385 | /** |
|
159 | * {@inheritdoc} |
||
160 | */ |
||
161 | public function getOutput() |
||
165 | |||
166 | 3 | /** |
|
167 | * {@inheritdoc} |
||
168 | */ |
||
169 | public function getName() |
||
173 | |||
174 | 140 | /** |
|
175 | * {@inheritdoc} |
||
176 | */ |
||
177 | public function getEnvironment() |
||
181 | |||
182 | 1 | /** |
|
183 | 1 | * {@inheritdoc} |
|
184 | */ |
||
185 | public function setVersion($version) |
||
191 | 279 | ||
192 | /** |
||
193 | * {@inheritdoc} |
||
194 | */ |
||
195 | public function getVersion() |
||
199 | 10 | ||
200 | 10 | /** |
|
201 | * {@inheritdoc} |
||
202 | */ |
||
203 | public function setMigratingUp($isMigratingUp) |
||
209 | |||
210 | /** |
||
211 | * {@inheritdoc} |
||
212 | */ |
||
213 | public function isMigratingUp() |
||
217 | |||
218 | /** |
||
219 | * {@inheritdoc} |
||
220 | */ |
||
221 | public function execute($sql) |
||
225 | |||
226 | /** |
||
227 | * {@inheritdoc} |
||
228 | */ |
||
229 | public function query($sql) |
||
233 | |||
234 | /** |
||
235 | * {@inheritdoc} |
||
236 | */ |
||
237 | public function getQueryBuilder() |
||
241 | |||
242 | /** |
||
243 | * {@inheritdoc} |
||
244 | */ |
||
245 | public function fetchRow($sql) |
||
249 | 3 | ||
250 | 2 | /** |
|
251 | 2 | * {@inheritdoc} |
|
252 | 3 | */ |
|
253 | 3 | public function fetchAll($sql) |
|
257 | |||
258 | 1 | /** |
|
259 | * {@inheritdoc} |
||
260 | 1 | */ |
|
261 | 1 | public function insert($table, $data) |
|
262 | { |
||
263 | trigger_error('insert() is deprecated since 0.10.0. Use $this->table($tableName)->insert($data)->save() instead.', E_USER_DEPRECATED); |
||
264 | // convert to table object |
||
265 | if (is_string($table)) { |
||
266 | 1 | $table = new Table($table, [], $this->getAdapter()); |
|
267 | } |
||
268 | 1 | $table->insert($data)->save(); |
|
269 | 1 | } |
|
270 | |||
271 | /** |
||
272 | * {@inheritdoc} |
||
273 | */ |
||
274 | 1 | public function createDatabase($name, $options) |
|
278 | |||
279 | /** |
||
280 | * {@inheritdoc} |
||
281 | */ |
||
282 | 5 | public function dropDatabase($name) |
|
286 | |||
287 | /** |
||
288 | * {@inheritdoc} |
||
289 | */ |
||
290 | public function hasTable($tableName) |
||
294 | |||
295 | 1 | /** |
|
296 | 1 | * {@inheritdoc} |
|
297 | */ |
||
298 | public function table($tableName, $options = []) |
||
302 | |||
303 | /** |
||
304 | * A short-hand method to drop the given database table. |
||
305 | * |
||
306 | * @deprecated since 0.10.0. Use $this->table($tableName)->drop()->save() instead. |
||
307 | * @param string $tableName Table Name |
||
308 | * @return void |
||
309 | */ |
||
310 | public function dropTable($tableName) |
||
315 | |||
316 | /** |
||
317 | * Perform checks on the migration, print a warning |
||
318 | * if there are potential problems. |
||
319 | * |
||
320 | * Right now, the only check is if there is both a `change()` and |
||
321 | * an `up()` or a `down()` method. |
||
322 | * |
||
323 | * @return void |
||
324 | */ |
||
325 | public function preFlightCheck() |
||
336 | } |
||
337 |
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.