1 | <?php |
||
22 | class Migrator extends Component implements SingletonInterface |
||
23 | { |
||
24 | /** |
||
25 | * @var MigrationsConfig |
||
26 | */ |
||
27 | private $config = null; |
||
28 | |||
29 | /** |
||
30 | * @invisible |
||
31 | * @var DatabaseManager |
||
32 | */ |
||
33 | protected $dbal = null; |
||
34 | |||
35 | /** |
||
36 | * @invisible |
||
37 | * @var RepositoryInterface |
||
38 | */ |
||
39 | protected $repository = null; |
||
40 | |||
41 | /** |
||
42 | * @param MigrationsConfig $config |
||
43 | * @param DatabaseManager $dbal |
||
44 | * @param RepositoryInterface $repository |
||
45 | */ |
||
46 | public function __construct( |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | public function isConfigured(): bool |
||
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | */ |
||
67 | public function configure() |
||
86 | |||
87 | /** |
||
88 | * @return RepositoryInterface |
||
89 | */ |
||
90 | public function getRepository(): RepositoryInterface |
||
94 | |||
95 | /** |
||
96 | * Get every available migration with valid meta information. |
||
97 | * |
||
98 | * @return MigrationInterface[] |
||
99 | */ |
||
100 | public function getMigrations(): array |
||
110 | |||
111 | /** |
||
112 | * Execute one migration and return it's instance. |
||
113 | * |
||
114 | * @param CapsuleInterface $capsule Default capsule to be used if none given. |
||
115 | * |
||
116 | * @return MigrationInterface|null |
||
117 | */ |
||
118 | public function run(CapsuleInterface $capsule = null) |
||
153 | |||
154 | /** |
||
155 | * Rollback last migration and return it's instance. |
||
156 | * |
||
157 | * @param CapsuleInterface $capsule Default capsule to be used if none given. |
||
158 | * |
||
159 | * @return MigrationInterface|null |
||
160 | */ |
||
161 | public function rollback(CapsuleInterface $capsule = null) |
||
195 | |||
196 | /** |
||
197 | * Migration table, all migration information will be stored in it. |
||
198 | * |
||
199 | * @return Table |
||
200 | */ |
||
201 | protected function stateTable(): Table |
||
209 | |||
210 | /** |
||
211 | * Clarify migration state with valid status and execution time |
||
212 | * |
||
213 | * @param State $meta |
||
214 | * |
||
215 | * @return State |
||
216 | */ |
||
217 | protected function resolveStatus(State $meta) |
||
238 | |||
239 | /** |
||
240 | * Run given code under transaction open for every driver. |
||
241 | * |
||
242 | * @param \Closure $closure |
||
243 | * |
||
244 | * @throws \Throwable |
||
245 | */ |
||
246 | protected function execute(\Closure $closure) |
||
258 | |||
259 | /** |
||
260 | * Begin transaction for every available driver (we don't know what database migration related |
||
261 | * to). |
||
262 | */ |
||
263 | protected function beginTransactions() |
||
269 | |||
270 | /** |
||
271 | * Rollback transaction for every available driver. |
||
272 | */ |
||
273 | protected function rollbackTransactions() |
||
279 | |||
280 | /** |
||
281 | * Commit transaction for every available driver. |
||
282 | */ |
||
283 | protected function commitTransactions() |
||
289 | |||
290 | /** |
||
291 | * Get all available drivers. |
||
292 | * |
||
293 | * @return Driver[] |
||
294 | */ |
||
295 | protected function getDrivers(): array |
||
307 | } |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: