Passed
Push — master ( 8b3dbf...d47765 )
by Jean-Christophe
01:40
created

BaseHooksTrait::hookExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Ajax\common\html\traits;
4
5
trait BaseHooksTrait {
6
	protected $_hooks=[];
7
	
8
	/**
9
	 * @param string $hookKey
10
	 * @return boolean
11
	 */
12
	public function hookExists($hookKey){
13
		return isset($this->_hooks[$hookKey]);
14
	}
15
	
16
	/**
17
	 * @param string $hookKey
18
	 * @return callable|NULL
19
	 */
20
	public function getHook($hookKey){
21
		if(isset($this->_hooks[$hookKey])){
22
			return $this->_hooks[$hookKey];
23
		}
24
		return null;
25
	}
26
	
27
	/**
28
	 * Adds a new Hook
29
	 * @param String $hookKey
30
	 * @param callable $callable
31
	 */
32
	public function addHook($hookKey,$callable){
33
		$this->_hooks[$hookKey]=$callable;
34
	}
35
	
36
	/**
37
	 * Executes the hook with key $hookKey
38
	 * @param string $hookKey
39
	 * @param mixed|null $variable
40
	 * @return void|mixed
41
	 */
42
	public function execHook($hookKey,$variable=null){
43
		if(($hook=$this->getHook($hookKey))!=null){
44
			return $hook($variable);
45
		}
46
		return;
47
	}
48
}
49
50