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 \ArrayAccess |
||
30 | */ |
||
31 | private $_container; |
||
32 | |||
33 | /** |
||
34 | * Migration manager context. |
||
35 | * |
||
36 | * @var MigrationContext |
||
37 | */ |
||
38 | private $_context; |
||
39 | |||
40 | /** |
||
41 | * Migration runners. |
||
42 | * |
||
43 | * @var AbstractMigrationRunner[] |
||
44 | */ |
||
45 | private $_migrationRunners = array(); |
||
46 | |||
47 | /** |
||
48 | * Creates migration manager instance. |
||
49 | * |
||
50 | * @param string $migrations_directory Migrations directory. |
||
51 | * @param \ArrayAccess $container Container. |
||
52 | * |
||
53 | * @throws \InvalidArgumentException When migrations directory does not exist. |
||
54 | */ |
||
55 | 161 | public function __construct($migrations_directory, \ArrayAccess $container) |
|
66 | |||
67 | /** |
||
68 | * Registers a migration runner. |
||
69 | * |
||
70 | * @param AbstractMigrationRunner $migration_runner Migration runner. |
||
71 | * |
||
72 | * @return void |
||
73 | */ |
||
74 | 153 | public function registerMigrationRunner(AbstractMigrationRunner $migration_runner) |
|
78 | |||
79 | /** |
||
80 | * Creates new migration. |
||
81 | * |
||
82 | * @param string $name Migration name. |
||
83 | * @param string $file_extension Migration file extension. |
||
84 | * |
||
85 | * @return string |
||
86 | * @throws \InvalidArgumentException When migration name/file extension is invalid. |
||
87 | * @throws \LogicException When new migration already exists. |
||
88 | */ |
||
89 | public function createMigration($name, $file_extension) |
||
113 | |||
114 | /** |
||
115 | * Returns supported migration file extensions. |
||
116 | * |
||
117 | * @return array |
||
118 | * @throws \LogicException When no migration runners added. |
||
119 | */ |
||
120 | 151 | public function getMigrationFileExtensions() |
|
128 | |||
129 | /** |
||
130 | * Executes outstanding migrations. |
||
131 | * |
||
132 | * @param MigrationContext $context Context. |
||
133 | * |
||
134 | * @return void |
||
135 | */ |
||
136 | 151 | public function run(MigrationContext $context) |
|
150 | |||
151 | /** |
||
152 | * Sets current context. |
||
153 | * |
||
154 | * @param MigrationContext $context Context. |
||
155 | * |
||
156 | * @return void |
||
157 | */ |
||
158 | 151 | protected function setContext(MigrationContext $context) |
|
163 | |||
164 | /** |
||
165 | * Creates migration table, when missing. |
||
166 | * |
||
167 | * @return void |
||
168 | */ |
||
169 | 151 | protected function createMigrationsTable() |
|
189 | |||
190 | /** |
||
191 | * Returns all migrations. |
||
192 | * |
||
193 | * @return array |
||
194 | */ |
||
195 | 151 | protected function getAllMigrations() |
|
213 | |||
214 | /** |
||
215 | * Returns executed migrations. |
||
216 | * |
||
217 | * @return array |
||
218 | */ |
||
219 | 151 | protected function getExecutedMigrations() |
|
226 | |||
227 | /** |
||
228 | * Executes migrations. |
||
229 | * |
||
230 | * @param array $migrations Migrations. |
||
231 | * |
||
232 | * @return void |
||
233 | */ |
||
234 | 151 | protected function executeMigrations(array $migrations) |
|
257 | |||
258 | /** |
||
259 | * Deletes migrations. |
||
260 | * |
||
261 | * @param array $migrations Migrations. |
||
262 | * |
||
263 | * @return void |
||
264 | */ |
||
265 | 151 | protected function deleteMigrations(array $migrations) |
|
275 | |||
276 | } |
||
277 |