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 up() |
||
118 | |||
119 | /** |
||
120 | * {@inheritdoc} |
||
121 | 21 | */ |
|
122 | public function down() |
||
125 | |||
126 | /** |
||
127 | * {@inheritdoc} |
||
128 | */ |
||
129 | public function setAdapter(AdapterInterface $adapter) |
||
135 | |||
136 | /** |
||
137 | * {@inheritdoc} |
||
138 | 384 | */ |
|
139 | public function getAdapter() |
||
143 | |||
144 | /** |
||
145 | * {@inheritdoc} |
||
146 | */ |
||
147 | 2 | public function setInput(InputInterface $input) |
|
148 | { |
||
149 | 2 | $this->input = $input; |
|
150 | |||
151 | return $this; |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | 385 | * {@inheritdoc} |
|
156 | */ |
||
157 | 385 | public function getInput() |
|
158 | 385 | { |
|
159 | return $this->input; |
||
160 | } |
||
161 | |||
162 | /** |
||
163 | * {@inheritdoc} |
||
164 | 3 | */ |
|
165 | public function setOutput(OutputInterface $output) |
||
171 | |||
172 | 140 | /** |
|
173 | * {@inheritdoc} |
||
174 | 140 | */ |
|
175 | public function getOutput() |
||
179 | |||
180 | 1 | /** |
|
181 | * {@inheritdoc} |
||
182 | 1 | */ |
|
183 | 1 | public function getName() |
|
187 | |||
188 | /** |
||
189 | 279 | * {@inheritdoc} |
|
190 | */ |
||
191 | 279 | public function getEnvironment() |
|
195 | |||
196 | /** |
||
197 | 10 | * {@inheritdoc} |
|
198 | */ |
||
199 | 10 | public function setVersion($version) |
|
200 | 10 | { |
|
201 | $this->version = $version; |
||
202 | |||
203 | return $this; |
||
204 | } |
||
205 | |||
206 | 2 | /** |
|
207 | * {@inheritdoc} |
||
208 | 2 | */ |
|
209 | public function getVersion() |
||
210 | { |
||
211 | return $this->version; |
||
212 | } |
||
213 | |||
214 | 3 | /** |
|
215 | * {@inheritdoc} |
||
216 | 3 | */ |
|
217 | public function setMigratingUp($isMigratingUp) |
||
218 | { |
||
219 | $this->isMigratingUp = $isMigratingUp; |
||
220 | |||
221 | return $this; |
||
222 | 1 | } |
|
223 | |||
224 | 1 | /** |
|
225 | * {@inheritdoc} |
||
226 | */ |
||
227 | public function isMigratingUp() |
||
228 | { |
||
229 | return $this->isMigratingUp; |
||
230 | 1 | } |
|
231 | |||
232 | 1 | /** |
|
233 | * {@inheritdoc} |
||
234 | */ |
||
235 | public function execute($sql) |
||
236 | { |
||
237 | return $this->getAdapter()->execute($sql); |
||
238 | 1 | } |
|
239 | |||
240 | 1 | /** |
|
241 | * {@inheritdoc} |
||
242 | */ |
||
243 | public function query($sql) |
||
244 | { |
||
245 | return $this->getAdapter()->query($sql); |
||
246 | 3 | } |
|
247 | |||
248 | /** |
||
249 | 3 | * {@inheritdoc} |
|
250 | 2 | */ |
|
251 | 2 | public function getQueryBuilder() |
|
252 | 3 | { |
|
253 | 3 | return $this->getAdapter()->getQueryBuilder(); |
|
254 | } |
||
255 | |||
256 | /** |
||
257 | * {@inheritdoc} |
||
258 | 1 | */ |
|
259 | public function fetchRow($sql) |
||
263 | |||
264 | /** |
||
265 | * {@inheritdoc} |
||
266 | 1 | */ |
|
267 | public function fetchAll($sql) |
||
271 | |||
272 | /** |
||
273 | * {@inheritdoc} |
||
274 | 1 | */ |
|
275 | public function insert($table, $data) |
||
276 | 1 | { |
|
277 | trigger_error('insert() is deprecated since 0.10.0. Use $this->table($tableName)->insert($data)->save() instead.', E_USER_DEPRECATED); |
||
278 | // convert to table object |
||
279 | if (is_string($table)) { |
||
280 | $table = new Table($table, [], $this->getAdapter()); |
||
281 | } |
||
282 | 5 | $table->insert($data)->save(); |
|
283 | } |
||
284 | 5 | ||
285 | /** |
||
286 | * {@inheritdoc} |
||
287 | */ |
||
288 | public function createDatabase($name, $options) |
||
292 | |||
293 | 1 | /** |
|
294 | * {@inheritdoc} |
||
295 | 1 | */ |
|
296 | 1 | public function dropDatabase($name) |
|
300 | |||
301 | /** |
||
302 | * {@inheritdoc} |
||
303 | */ |
||
304 | public function hasTable($tableName) |
||
308 | |||
309 | /** |
||
310 | * {@inheritdoc} |
||
311 | */ |
||
312 | public function table($tableName, $options = []) |
||
316 | |||
317 | /** |
||
318 | * A short-hand method to drop the given database table. |
||
319 | * |
||
320 | * @deprecated since 0.10.0. Use $this->table($tableName)->drop()->save() instead. |
||
321 | * @param string $tableName Table Name |
||
322 | * @return void |
||
323 | */ |
||
324 | public function dropTable($tableName) |
||
329 | |||
330 | /** |
||
331 | * Perform checks on the migration, print a warning |
||
332 | * if there are potential problems. |
||
333 | * |
||
334 | * Right now, the only check is if there is both a `change()` and |
||
335 | * an `up()` or a `down()` method. |
||
336 | * |
||
337 | * @return void |
||
338 | */ |
||
339 | public function preFlightCheck() |
||
350 | } |
||
351 |
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.