Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
DomainEvent
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 3
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 getEventType
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getEventTimestamp
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\DomainEvent;
4
5use MediaWiki\Utils\MWTimestamp;
6use Wikimedia\Timestamp\ConvertibleTimestamp;
7
8/**
9 * Base class for domain event objects to be used with DomainEventDispatcher.
10 *
11 * Domain events are used to notify other parts of the code (oder "domains")
12 * about a change to the persistent state of the local wiki.
13 *
14 * The idea of domain events is borrowed from the Domain Driven Design paradigm.
15 * For a thorough explanation, see
16 * <https://learn.microsoft.com/en-us/dotnet/architecture/microservices/microservice-ddd-cqrs-patterns/domain-events-design-implementation>.
17 * Also compare <https://martinfowler.com/eaaDev/DomainEvent.html>.
18 *
19 * Domain event objects must be immutable.
20 *
21 * An event object should contain all information that was used to affect that
22 * change (the command parameters) as well as information representing the
23 * outcome of the change.
24 *
25 * @since 1.44
26 * @unstable until 1.45, should become stable to extend
27 */
28abstract class DomainEvent {
29
30    private string $type;
31    private ConvertibleTimestamp $timestamp;
32
33    /**
34     * @stable to call
35     * @param string $type
36     * @param string|ConvertibleTimestamp|false $timestamp
37     */
38    public function __construct( string $type, $timestamp = false ) {
39        $this->type = $type;
40
41        $this->timestamp = $timestamp instanceof ConvertibleTimestamp
42            ? $timestamp
43            : MWTimestamp::getInstance( $timestamp );
44    }
45
46    /**
47     * @return string
48     */
49    public function getEventType(): string {
50        return $this->type;
51    }
52
53    /**
54     * @return ConvertibleTimestamp
55     */
56    public function getEventTimestamp(): string {
57        return $this->timestamp;
58    }
59
60}