@@ 56-69 (lines=14) @@ | ||
53 | * @param StoredEvent $storedEvent |
|
54 | * @param Version $version |
|
55 | */ |
|
56 | public function upgrade(StoredEvent $storedEvent, $version = null) |
|
57 | { |
|
58 | if (isset($this->upgrades[$storedEvent->type()])) { |
|
59 | /** @var UpgradeInterface $upgrade */ |
|
60 | foreach ($this->upgrades[$storedEvent->type()] as $upgrade) { |
|
61 | if ($storedEvent->version()->equalTo($upgrade->from())) { |
|
62 | $upgrade->upgrade($storedEvent); |
|
63 | $storedEvent->setVersion($upgrade->to()); |
|
64 | if (!is_null($version) && $upgrade->to()->equalTo($version)) { |
|
65 | return; |
|
66 | } |
|
67 | } |
|
68 | } |
|
69 | } |
|
70 | } |
|
71 | ||
72 | /** |
|
@@ 76-90 (lines=15) @@ | ||
73 | * @param StoredEvent $storedEvent |
|
74 | * @param Version $version |
|
75 | */ |
|
76 | public function downgrade(StoredEvent $storedEvent, $version = null) |
|
77 | { |
|
78 | if (isset($this->upgrades[$storedEvent->type()])) { |
|
79 | $upgrades = array_reverse($this->upgrades[$storedEvent->type()]); |
|
80 | /** @var UpgradeInterface $upgrade */ |
|
81 | foreach ($upgrades as $upgrade) { |
|
82 | if ($storedEvent->version()->equalTo($upgrade->to())) { |
|
83 | $upgrade->downgrade($storedEvent); |
|
84 | $storedEvent->setVersion($upgrade->from()); |
|
85 | if (!is_null($version) && $upgrade->to()->equalTo($version)) { |
|
86 | return; |
|
87 | } |
|
88 | } |
|
89 | } |
|
90 | } |
|
91 | } |
|
92 | } |
|
93 |