AbstractDispatcherAdapter::get()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 1
ccs 0
cts 0
cp 0
nc 1
1
<?php
2
/**
3
 * This file is part of the bee4/events package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 *
7
 * @copyright Bee4 2014
8
 * @author Stephane HULARD <[email protected]>
9
 * @package Bee4\Events\Adapters
10
 */
11
12
namespace Bee4\Events\Adapters;
13
14
use Bee4\Events\DispatcherInterface;
15
use Bee4\Events\EventInterface;
16
17
/**
18
 * Bridge to the Symfony EventDispatcher implementation
19
 * @package BeeBot\Event\Adapters
20
 */
21
abstract class AbstractDispatcherAdapter implements DispatcherInterface
22
{
23
    /**
24
     * Adapted instance
25
     */
26
    protected $dispatcher;
27
28
    /**
29
     * @param string $name
30
     * @param EventInterface $event
31
     * @return EventInterface
32
     */
33
    public function dispatch($name, EventInterface $event)
34
    {
35 1
        $listeners = $this->get($name);
36 1
        foreach ($listeners as $listener) {
37 1
            call_user_func($listener, $event, $name, $this);
38 1
        }
39
40 1
        return $event;
41
    }
42
43
    /**
44
     * Add a listener for the given event
45
     * @param string $name
46
     * @param Callable $listener
47
     * @param int $priority
48
     * @return DispatcherInterface
49
     */
50
    abstract public function add($name, callable $listener, $priority = 0);
51
52
    /**
53
     * Add a listener for the given event
54
     * @param string $name
55
     * @param Callable $listener
56
     * @return DispatcherInterface
57
     */
58
    abstract public function remove($name, callable $listener);
59
60
    /**
61
     * Retrieve the listeners for a given event name
62
     * @param string $name
63
     * @return array
64
     */
65
    abstract public function get($name);
66
}
67