1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
5
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
6
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
7
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
8
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
9
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
10
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
11
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
12
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
13
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
14
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
15
|
|
|
* |
16
|
|
|
* The software is based on the Axon Framework project which is |
17
|
|
|
* licensed under the Apache 2.0 license. For more information on the Axon Framework |
18
|
|
|
* see <http://www.axonframework.org/>. |
19
|
|
|
* |
20
|
|
|
* This software consists of voluntary contributions made by many individuals |
21
|
|
|
* and is licensed under the MIT license. For more information, see |
22
|
|
|
* <http://www.governor-framework.org/>. |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
namespace Governor\Framework\EventHandling\Replay; |
26
|
|
|
|
27
|
|
|
use Psr\Log\LoggerInterface; |
28
|
|
|
use Psr\Log\LoggerAwareInterface; |
29
|
|
|
use Governor\Framework\Common\Logging\NullLogger; |
30
|
|
|
use Governor\Framework\EventHandling\EventBusInterface; |
31
|
|
|
use Governor\Framework\Domain\DomainEventMessageInterface; |
32
|
|
|
use Governor\Framework\EventStore\EventVisitorInterface; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Description of ReplayingEventVisitor |
36
|
|
|
* |
37
|
|
|
* @author "David Kalosi" <[email protected]> |
38
|
|
|
* @license <a href="http://www.opensource.org/licenses/mit-license.php">MIT License</a> |
39
|
|
|
*/ |
40
|
|
|
class ReplayingEventVisitor implements EventVisitorInterface, LoggerAwareInterface |
41
|
|
|
{ |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var EventBusInterface |
45
|
|
|
*/ |
46
|
|
|
private $delegate; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var LoggerInterface |
50
|
|
|
*/ |
51
|
|
|
private $logger; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param EventBusInterface $delegate |
55
|
|
|
*/ |
56
|
5 |
|
function __construct(EventBusInterface $delegate) |
|
|
|
|
57
|
|
|
{ |
58
|
5 |
|
$this->delegate = $delegate; |
59
|
5 |
|
$this->logger = new NullLogger(); |
60
|
5 |
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param DomainEventMessageInterface $domainEvent |
64
|
|
|
*/ |
65
|
3 |
|
public function doWithEvent(DomainEventMessageInterface $domainEvent) |
66
|
|
|
{ |
67
|
3 |
|
$this->logger->debug( |
68
|
3 |
|
sprintf( |
69
|
3 |
|
"Visiting event %s with payload %s", |
70
|
3 |
|
$domainEvent->getIdentifier(), |
71
|
3 |
|
$domainEvent->getPayloadType() |
72
|
3 |
|
) |
73
|
3 |
|
); |
74
|
|
|
|
75
|
3 |
|
$this->delegate->publish(array($domainEvent)); |
76
|
3 |
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Sets a logger instance on the object |
80
|
|
|
* |
81
|
|
|
* @param LoggerInterface $logger |
82
|
|
|
* @return null |
83
|
|
|
*/ |
84
|
5 |
|
public function setLogger(LoggerInterface $logger) |
85
|
|
|
{ |
86
|
5 |
|
$this->logger = $logger; |
87
|
5 |
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
} |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.