Completed
Push — master ( b1744c...51aee2 )
by Matze
04:34
created

EventDispatcherTrait::dispatchEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace BrainExe\Core\Traits;
4
5
use BrainExe\Annotations\Annotations\Inject;
6
use BrainExe\Core\EventDispatcher\AbstractEvent;
7
use BrainExe\Core\EventDispatcher\EventDispatcher;
8
use BrainExe\Core\MessageQueue\Job;
9
10
/**
11
 * @api
12
 */
13
trait EventDispatcherTrait
14
{
15
16
    /**
17
     * @var EventDispatcher
18
     */
19
    private $dispatcher;
20
21
    /**
22
     * @Inject("@EventDispatcher")
23
     * @param EventDispatcher $dispatcher
24
     */
25 7
    public function setEventDispatcher(EventDispatcher $dispatcher)
26
    {
27 7
        $this->dispatcher = $dispatcher;
28 7
    }
29
30
    /**
31
     * @return EventDispatcher
32
     */
33
    public function getDispatcher() : EventDispatcher
34
    {
35
        return $this->dispatcher;
36
    }
37
38
    /**
39
     * @param AbstractEvent $event
40
     */
41 4
    public function dispatchEvent(AbstractEvent $event)
42
    {
43 4
        $this->dispatcher->dispatchEvent($event);
44 3
    }
45
46
    /**
47
     * @param AbstractEvent $event
48
     * @param int|null $timestamp
49
     * @return Job
50
     */
51 1
    public function dispatchInBackground(AbstractEvent $event, int $timestamp = 0)
52
    {
53 1
        return $this->dispatcher->dispatchInBackground($event, $timestamp);
54
    }
55
}
56