1 | <?php |
||
16 | class MigrationManager |
||
17 | { |
||
18 | |||
19 | /** |
||
20 | * Migrations directory. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | private $_migrationsDirectory; |
||
25 | |||
26 | /** |
||
27 | * Container. |
||
28 | * |
||
29 | * @var Container |
||
30 | */ |
||
31 | private $_container; |
||
32 | |||
33 | /** |
||
34 | * Migration manager context. |
||
35 | * |
||
36 | * @var MigrationManagerContext |
||
37 | */ |
||
38 | private $_context; |
||
39 | |||
40 | /** |
||
41 | * Creates migration manager instance. |
||
42 | * |
||
43 | * @param string $migrations_directory Migrations directory. |
||
44 | * @param Container $container Container. |
||
45 | * |
||
46 | * @throws \InvalidArgumentException When migrations directory does not exist. |
||
47 | */ |
||
48 | 8 | public function __construct($migrations_directory, Container $container) |
|
59 | |||
60 | /** |
||
61 | * Executes outstanding migrations. |
||
62 | * |
||
63 | * @param MigrationManagerContext $context Context. |
||
64 | * |
||
65 | * @return void |
||
66 | */ |
||
67 | 6 | public function run(MigrationManagerContext $context) |
|
81 | |||
82 | /** |
||
83 | * Sets current context. |
||
84 | * |
||
85 | * @param MigrationManagerContext $context Context. |
||
86 | * |
||
87 | * @return void |
||
88 | */ |
||
89 | 6 | protected function setContext(MigrationManagerContext $context) |
|
94 | |||
95 | /** |
||
96 | * Creates migration table, when missing. |
||
97 | * |
||
98 | * @return void |
||
99 | */ |
||
100 | 6 | protected function createMigrationsTable() |
|
120 | |||
121 | /** |
||
122 | * Returns all migrations. |
||
123 | * |
||
124 | * @return array |
||
125 | */ |
||
126 | 6 | protected function getAllMigrations() |
|
134 | |||
135 | /** |
||
136 | * Returns executed migrations. |
||
137 | * |
||
138 | * @return array |
||
139 | */ |
||
140 | 6 | protected function getExecutedMigrations() |
|
147 | |||
148 | /** |
||
149 | * Executes migrations. |
||
150 | * |
||
151 | * @param array $migrations Migrations. |
||
152 | * |
||
153 | * @return void |
||
154 | */ |
||
155 | 6 | protected function executeMigrations(array $migrations) |
|
180 | |||
181 | /** |
||
182 | * Executes SQL migration. |
||
183 | * |
||
184 | * @param string $migration Migration. |
||
185 | * |
||
186 | * @return void |
||
187 | * @throws \LogicException When an empty migration is discovered. |
||
188 | */ |
||
189 | 4 | protected function executeSQLMigration($migration) |
|
204 | |||
205 | /** |
||
206 | * Executes PHP migration. |
||
207 | * |
||
208 | * @param string $migration Migration. |
||
209 | * |
||
210 | * @return void |
||
211 | * @throws \LogicException When migration doesn't contain a closure. |
||
212 | */ |
||
213 | 2 | protected function executePHPMigration($migration) |
|
223 | |||
224 | /** |
||
225 | * Deletes migrations. |
||
226 | * |
||
227 | * @param array $migrations Migrations. |
||
228 | * |
||
229 | * @return void |
||
230 | */ |
||
231 | 4 | protected function deleteMigrations(array $migrations) |
|
241 | |||
242 | } |
||
243 |