Newer
Older
<?php
namespace Breyta;
class Migrations
{
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/** @var string */
protected $path;
/** @var array */
protected $migrations;
public function __construct(\PDO $db, string $path)
{
if (!file_exists($path) || !is_dir($path)) {
throw new \InvalidArgumentException('The path to migrations is not valid');
}
$this->db = $db;
$this->path = $path;
}
public function getStatus(): \stdClass
{
return (object)[
'migrations' => $this->getMigrations(),
'count' => 0,
];
}
protected function getMigrations(): array
{
if (!$this->migrations) {
$this->migrations = $this->findMigrations();
}
return $this->migrations;
}
protected function findMigrations(): array
{
$migrations = [(object)[
'file' => '@breyta/CreateMigrationTable.php',
'status' => 'new',
]];
$migrations = array_merge($migrations, array_map(function ($path) {
return (object)[
'file' => basename($path),
'status' => 'new',
];
}, array_filter(scandir($this->path), function ($path) {
return $path !== '..' && $path !== '.';
})));
return $migrations;
}