Completed
Push — master ( 489a99...99d7d3 )
by Ryan
07:23
created

Hookable::hook()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php namespace Anomaly\Streams\Platform\Traits;
2
3
use Illuminate\Contracts\Bus\SelfHandling;
4
5
/**
6
 * Class Hookable
7
 *
8
 * @link          http://anomaly.is/streams-platform
9
 * @author        AnomalyLabs, Inc. <[email protected]>
10
 * @author        Ryan Thompson <[email protected]>
11
 * @package       Anomaly\Streams\Platform\Traits
12
 */
13
trait Hookable
14
{
15
16
    /**
17
     * The registered hooks.
18
     *
19
     * @var array
20
     */
21
    protected static $hooks = [];
22
23
    /**
24
     * Register a new hook.
25
     *
26
     * @param $hook
27
     * @param $callback
28
     * @return $this
29
     */
30
    public function hook($hook, $callback)
31
    {
32
        self::$hooks[$hook] = $callback;
33
34
        return $this;
35
    }
36
37
    /**
38
     * Fire a set of closures by trigger.
39
     *
40
     * @param       $hook
41
     * @param array $parameters
42
     * @return mixed
43
     */
44
    public function call($hook, array $parameters = [])
45
    {
46
        return app()->call(self::$hooks[$hook], $parameters);
47
    }
48
49
    /**
50
     * Return if the hook exists.
51
     *
52
     * @param $hook
53
     * @return bool
54
     */
55
    public function hasHook($hook)
56
    {
57
        return isset(self::$hooks[$hook]);
58
    }
59
}
60