Completed
Push — master ( f42a52...0a9499 )
by Thierry
02:50 queued 01:16
created

Event::getEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * EventListener.php - Trait for event listener and dispatcher.
5
 *
6
 * @package jaxon-core
7
 * @author Thierry Feuzeu <[email protected]>
8
 * @copyright 2016 Thierry Feuzeu <[email protected]>
9
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
10
 * @link https://github.com/jaxon-php/jaxon-core
11
 */
12
13
namespace Jaxon\Features;
14
15
use Jaxon\Contracts\Event\Listener as EventListener;
16
17
trait Event
18
{
19
    /**
20
     * Register an event listener.
21
     *
22
     * @return void
23
     */
24
    public function addEventListener(EventListener $xEventListener)
25
    {
26
        jaxon()->di()->getEventDispatcher()->addSubscriber($xEventListener);
27
    }
28
29
    /**
30
     * Trigger an event.
31
     *
32
     * @param string        $sEvent            The event name
33
     *
34
     * @return void
35
     */
36
    public function triggerEvent($sEvent)
37
    {
38
        jaxon()->di()->getEventDispatcher()->dispatch($sEvent);
39
    }
40
41
    /**
42
     * Return an array of events to listen to.
43
     *
44
     * This is the default implementation on the EventListener interface.
45
     *
46
     * @return array An empty array
47
     */
48
    public function getEvents()
49
    {
50
        return [];
51
    }
52
53
    /**
54
     * Return an array of events to listen to.
55
     *
56
     * This is the implementation of the Lemon\Event\EventSubscriberInterface interface.
57
     *
58
     * @return array The event names to listen to
59
     */
60
    public function getSubscribedEvents()
61
    {
62
        return $this->getEvents();
63
    }
64
}
65