1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WebComplete\core\utils\migration; |
4
|
|
|
|
5
|
|
|
class MigrationService |
6
|
|
|
{ |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @var MigrationRegistryInterface |
10
|
|
|
*/ |
11
|
|
|
protected $registry; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* MigrationService constructor. |
15
|
|
|
* |
16
|
|
|
* @param MigrationRegistryInterface $registry |
17
|
|
|
*/ |
18
|
|
|
public function __construct(MigrationRegistryInterface $registry) |
19
|
|
|
{ |
20
|
|
|
$this->registry = $registry; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param array $classes |
25
|
|
|
* |
26
|
|
|
* @throws \Exception |
27
|
|
|
* @throws \Psr\Container\ContainerExceptionInterface |
28
|
|
|
* @throws \Psr\Container\NotFoundExceptionInterface |
29
|
|
|
*/ |
30
|
|
|
public function upAll(array $classes) |
31
|
|
|
{ |
32
|
|
|
foreach ($classes as $class) { |
33
|
|
|
$this->up($class); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @throws \Exception |
39
|
|
|
* @throws \Psr\Container\ContainerExceptionInterface |
40
|
|
|
* @throws \Psr\Container\NotFoundExceptionInterface |
41
|
|
|
*/ |
42
|
|
|
public function downAll() |
43
|
|
|
{ |
44
|
|
|
$classes = $this->registry->getRegistered(); |
45
|
|
|
foreach ($classes as $class) { |
46
|
|
|
$this->down($class); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param $class |
52
|
|
|
* |
53
|
|
|
* @throws \Exception |
54
|
|
|
* @throws \Psr\Container\ContainerExceptionInterface |
55
|
|
|
* @throws \Psr\Container\NotFoundExceptionInterface |
56
|
|
|
*/ |
57
|
|
|
public function up($class) |
58
|
|
|
{ |
59
|
|
|
$this->registry->register($class); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param $class |
64
|
|
|
* |
65
|
|
|
* @throws \Exception |
66
|
|
|
* @throws \Psr\Container\ContainerExceptionInterface |
67
|
|
|
* @throws \Psr\Container\NotFoundExceptionInterface |
68
|
|
|
*/ |
69
|
|
|
public function down($class) |
70
|
|
|
{ |
71
|
|
|
$this->registry->unregister($class); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return array |
76
|
|
|
*/ |
77
|
|
|
public function getRegistered(): array |
78
|
|
|
{ |
79
|
|
|
return $this->registry->getRegistered(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param string $class |
84
|
|
|
* |
85
|
|
|
* @return bool |
86
|
|
|
*/ |
87
|
|
|
public function isRegistered(string $class): bool |
88
|
|
|
{ |
89
|
|
|
return $this->registry->isRegistered($class); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|