1 | <?php |
||
13 | class FileDateMigrator implements Migrator |
||
14 | { |
||
15 | use Filesystem, Loggable; |
||
16 | |||
17 | /** |
||
18 | * Yarak config. |
||
19 | * |
||
20 | * @var Config |
||
21 | */ |
||
22 | protected $config; |
||
23 | |||
24 | /** |
||
25 | * Database connection resolver. |
||
26 | * |
||
27 | * @var ConnectionResolver |
||
28 | */ |
||
29 | protected $resolver; |
||
30 | |||
31 | /** |
||
32 | * Repository for logging migration activity. |
||
33 | * |
||
34 | * @var MigrationRepository |
||
35 | */ |
||
36 | protected $repository; |
||
37 | |||
38 | /** |
||
39 | * The active database connection. |
||
40 | * |
||
41 | * @var \Phalcon\Db\Adapter\Pdo |
||
42 | */ |
||
43 | protected $connection = null; |
||
44 | |||
45 | /** |
||
46 | * Construct. |
||
47 | * |
||
48 | * @param Config $config |
||
49 | * @param ConnectionResolver $resolver |
||
50 | * @param MigrationRepository $repository |
||
51 | */ |
||
52 | public function __construct( |
||
61 | |||
62 | /** |
||
63 | * Run migrations. |
||
64 | * |
||
65 | * @return array |
||
66 | */ |
||
67 | public function run() |
||
75 | |||
76 | /** |
||
77 | * Get all migration filenames that have not been run. |
||
78 | * |
||
79 | * @return array |
||
80 | */ |
||
81 | protected function getPendingMigrations() |
||
88 | |||
89 | /** |
||
90 | * Get array of migration file names from directory listed in config. |
||
91 | * |
||
92 | * @return array |
||
93 | */ |
||
94 | protected function getMigrationFiles() |
||
108 | |||
109 | /** |
||
110 | * Run pending migrations. |
||
111 | * |
||
112 | * @param array $migrations |
||
113 | * |
||
114 | * @return array |
||
115 | */ |
||
116 | protected function runPending(array $migrations) |
||
136 | |||
137 | /** |
||
138 | * Run the migration. |
||
139 | * |
||
140 | * @param string $migration |
||
141 | * @param int $batch |
||
142 | */ |
||
143 | protected function runUp($migration, $batch) |
||
151 | |||
152 | /** |
||
153 | * Perform a migration run operation. |
||
154 | * |
||
155 | * @param string $migration |
||
156 | * @param string $method |
||
157 | * |
||
158 | * @return bool |
||
159 | */ |
||
160 | protected function performRun($migration, $method) |
||
174 | |||
175 | /** |
||
176 | * Resolve the migration class from the file name. |
||
177 | * |
||
178 | * @param string $migration |
||
179 | * |
||
180 | * @return Yarak\Migrations\Migration |
||
181 | */ |
||
182 | protected function resolveMigrationClass($migration) |
||
190 | |||
191 | /** |
||
192 | * Rollback migrations. |
||
193 | * |
||
194 | * @param int $steps |
||
195 | * |
||
196 | * @return array |
||
197 | */ |
||
198 | public function rollback($steps = 1) |
||
206 | |||
207 | /** |
||
208 | * Rollback given migrations. |
||
209 | * |
||
210 | * @param array $migrations |
||
211 | * |
||
212 | * @return array |
||
213 | */ |
||
214 | protected function runRollback(array $migrations) |
||
232 | |||
233 | /** |
||
234 | * Rollback the migration. |
||
235 | * |
||
236 | * @param string $migration |
||
237 | */ |
||
238 | protected function runDown($migration) |
||
246 | |||
247 | /** |
||
248 | * Reset the database by rolling back all migrations. |
||
249 | * |
||
250 | * @return array |
||
251 | */ |
||
252 | public function reset() |
||
260 | |||
261 | /** |
||
262 | * Reset the database and run all migrations. |
||
263 | * |
||
264 | * @return array |
||
265 | */ |
||
266 | public function refresh() |
||
278 | |||
279 | /** |
||
280 | * Perform setup procedures for migrations. |
||
281 | */ |
||
282 | protected function setUp() |
||
292 | |||
293 | /** |
||
294 | * Set connection to database on object. |
||
295 | * |
||
296 | * @return $this |
||
297 | */ |
||
298 | public function setConnection() |
||
308 | |||
309 | /** |
||
310 | * Return the connection. |
||
311 | * |
||
312 | * @return \Phalcon\Db\Adapter\Pdo |
||
313 | */ |
||
314 | public function getConnection() |
||
318 | |||
319 | /** |
||
320 | * Create the migrations table if it doesn't exist. |
||
321 | */ |
||
322 | protected function createMigrationsRepository() |
||
330 | } |
||
331 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.