1 | <?php |
||
14 | class MigrationManager |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * Migrations directory. |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | private $_migrationsDirectory; |
||
23 | |||
24 | /** |
||
25 | * Container. |
||
26 | * |
||
27 | * @var \ArrayAccess |
||
28 | */ |
||
29 | private $_container; |
||
30 | |||
31 | /** |
||
32 | * Migration manager context. |
||
33 | * |
||
34 | * @var MigrationContext |
||
35 | */ |
||
36 | private $_context; |
||
37 | |||
38 | /** |
||
39 | * Migration runners. |
||
40 | * |
||
41 | * @var AbstractMigrationRunner[] |
||
42 | */ |
||
43 | private $_migrationRunners = array(); |
||
44 | |||
45 | /** |
||
46 | * Creates migration manager instance. |
||
47 | * |
||
48 | * @param string $migrations_directory Migrations directory. |
||
49 | * @param \ArrayAccess $container Container. |
||
50 | * |
||
51 | * @throws \InvalidArgumentException When migrations directory does not exist. |
||
52 | */ |
||
53 | 16 | public function __construct($migrations_directory, \ArrayAccess $container) |
|
64 | |||
65 | /** |
||
66 | * Registers a migration runner. |
||
67 | * |
||
68 | * @param AbstractMigrationRunner $migration_runner Migration runner. |
||
69 | * |
||
70 | * @return void |
||
71 | */ |
||
72 | 13 | public function registerMigrationRunner(AbstractMigrationRunner $migration_runner) |
|
76 | |||
77 | /** |
||
78 | * Creates new migration. |
||
79 | * |
||
80 | * @param string $name Migration name. |
||
81 | * @param string $file_extension Migration file extension. |
||
82 | * |
||
83 | * @return string |
||
84 | * @throws \InvalidArgumentException When migration name/file extension is invalid. |
||
85 | * @throws \LogicException When new migration already exists. |
||
86 | */ |
||
87 | 6 | public function createMigration($name, $file_extension) |
|
111 | |||
112 | /** |
||
113 | * Returns supported migration file extensions. |
||
114 | * |
||
115 | * @return array |
||
116 | * @throws \LogicException When no migration runners added. |
||
117 | */ |
||
118 | 11 | public function getMigrationFileExtensions() |
|
126 | |||
127 | /** |
||
128 | * Executes outstanding migrations. |
||
129 | * |
||
130 | * @param MigrationContext $context Context. |
||
131 | * |
||
132 | * @return void |
||
133 | */ |
||
134 | 6 | public function run(MigrationContext $context) |
|
148 | |||
149 | /** |
||
150 | * Sets current context. |
||
151 | * |
||
152 | * @param MigrationContext $context Context. |
||
153 | * |
||
154 | * @return void |
||
155 | */ |
||
156 | 6 | protected function setContext(MigrationContext $context) |
|
161 | |||
162 | /** |
||
163 | * Creates migration table, when missing. |
||
164 | * |
||
165 | * @return void |
||
166 | */ |
||
167 | 6 | protected function createMigrationsTable() |
|
187 | |||
188 | /** |
||
189 | * Returns all migrations. |
||
190 | * |
||
191 | * @return array |
||
192 | */ |
||
193 | 6 | protected function getAllMigrations() |
|
211 | |||
212 | /** |
||
213 | * Returns executed migrations. |
||
214 | * |
||
215 | * @return array |
||
216 | */ |
||
217 | 6 | protected function getExecutedMigrations() |
|
224 | |||
225 | /** |
||
226 | * Executes migrations. |
||
227 | * |
||
228 | * @param array $migrations Migrations. |
||
229 | * |
||
230 | * @return void |
||
231 | */ |
||
232 | 6 | protected function executeMigrations(array $migrations) |
|
255 | |||
256 | /** |
||
257 | * Deletes migrations. |
||
258 | * |
||
259 | * @param array $migrations Migrations. |
||
260 | * |
||
261 | * @return void |
||
262 | */ |
||
263 | 6 | protected function deleteMigrations(array $migrations) |
|
273 | |||
274 | } |
||
275 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.