1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Migrations; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\EventArgs; |
8
|
|
|
use Doctrine\Common\EventManager; |
9
|
|
|
use Doctrine\Migrations\Configuration\Configuration; |
10
|
|
|
use Doctrine\Migrations\Event\MigrationsEventArgs; |
11
|
|
|
use Doctrine\Migrations\Event\MigrationsVersionEventArgs; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @internal |
15
|
|
|
*/ |
16
|
|
|
final class EventDispatcher |
17
|
|
|
{ |
18
|
|
|
/** @var Configuration */ |
19
|
|
|
private $configuration; |
20
|
|
|
|
21
|
|
|
/** @var EventManager */ |
22
|
|
|
private $eventManager; |
23
|
|
|
|
24
|
52 |
|
public function __construct(Configuration $configuration, EventManager $eventManager) |
25
|
|
|
{ |
26
|
52 |
|
$this->configuration = $configuration; |
27
|
52 |
|
$this->eventManager = $eventManager; |
28
|
52 |
|
} |
29
|
|
|
|
30
|
26 |
|
public function dispatchMigrationEvent(string $eventName, string $direction, bool $dryRun) : void |
31
|
|
|
{ |
32
|
26 |
|
$event = $this->createMigrationEventArgs($direction, $dryRun); |
33
|
|
|
|
34
|
26 |
|
$this->dispatchEvent($eventName, $event); |
35
|
26 |
|
} |
36
|
|
|
|
37
|
51 |
|
public function dispatchVersionEvent( |
38
|
|
|
Version $version, |
39
|
|
|
string $eventName, |
40
|
|
|
string $direction, |
41
|
|
|
bool $dryRun |
42
|
|
|
) : void { |
43
|
51 |
|
$event = $this->createMigrationsVersionEventArgs( |
44
|
51 |
|
$version, |
45
|
51 |
|
$direction, |
46
|
51 |
|
$dryRun |
47
|
|
|
); |
48
|
|
|
|
49
|
51 |
|
$this->dispatchEvent($eventName, $event); |
50
|
51 |
|
} |
51
|
|
|
|
52
|
52 |
|
public function dispatchEvent(string $eventName, ?EventArgs $args = null) : void |
53
|
|
|
{ |
54
|
52 |
|
$this->eventManager->dispatchEvent($eventName, $args); |
55
|
52 |
|
} |
56
|
|
|
|
57
|
26 |
|
private function createMigrationEventArgs(string $direction, bool $dryRun) : MigrationsEventArgs |
58
|
|
|
{ |
59
|
26 |
|
return new MigrationsEventArgs($this->configuration, $direction, $dryRun); |
60
|
|
|
} |
61
|
|
|
|
62
|
51 |
|
private function createMigrationsVersionEventArgs( |
63
|
|
|
Version $version, |
64
|
|
|
string $direction, |
65
|
|
|
bool $dryRun |
66
|
|
|
) : MigrationsVersionEventArgs { |
67
|
51 |
|
return new MigrationsVersionEventArgs( |
68
|
51 |
|
$version, |
69
|
51 |
|
$this->configuration, |
70
|
51 |
|
$direction, |
71
|
51 |
|
$dryRun |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|