EventableExtensionAbstract::bootExtension()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Event
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Event;
16
17
use Phossa2\Shared\Extension\ExtensionAbstract;
18
use Phossa2\Event\Interfaces\ListenerInterface;
19
20
/**
21
 * EventableExtensionAbstract
22
 *
23
 * Extension with support for handling server's events.
24
 *
25
 * @property ListenerInterface $server
26
 *
27
 * @package Phossa2\Event
28
 * @author  Hong Zhang <[email protected]>
29
 * @see     ExtensionAbstract
30
 * @version 2.1.5
31
 * @since   2.1.5 added
32
 */
33
abstract class EventableExtensionAbstract extends ExtensionAbstract
34
{
35
    /**
36
     * Constructor
37
     *
38
     * @param  array $properties
39
     * @access public
40
     */
41
    public function __construct(array $properties = [])
42
    {
43
        $this->setProperties($properties);
44
    }
45
46
    /**
47
     * register handlers in the extension with $this->server's evt manager
48
     *
49
     * {@inheritDoc}
50
     */
51
    protected function bootExtension()
52
    {
53
        foreach ($this->extensionHandles() as $evt) {
54
            $this->server->registerEvent($evt['event'], $evt['handler']);
55
        }
56
    }
57
58
    /**
59
     * Return event handlers of this extension handling
60
     *
61
     * ```php
62
     * protected function extensionHandles()
63
     * {
64
     *     return [
65
     *         ['event' => 'cache.*', 'handler' => ['byPassCache', 100]],
66
     *     ];
67
     * }
68
     * ```
69
     *
70
     * @return array
71
     * @access protected
72
     */
73
    abstract protected function extensionHandles()/*# : array */;
74
}
75