HookRegistry::addCallbackHandlers()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace SEQL;
4
5
use Hooks;
6
use SMW\Store;
7
8
/**
9
 * @license GNU GPL v2+
10
 * @since 1.0
11
 *
12
 * @author mwjames
13
 */
14
class HookRegistry {
15
16
	/**
17
	 * @var array
18
	 */
19
	private $handlers = array();
20
21
	/**
22
	 * @since 1.0
23
	 *
24
	 * @param array $options
25
	 */
26 10
	public function __construct( array $options ) {
27 10
		$this->addCallbackHandlers( $options );
28 10
	}
29
30
	/**
31
	 * @since  1.0
32
	 */
33 9
	public function register() {
34 9
		foreach ( $this->handlers as $name => $callback ) {
35 9
			Hooks::register( $name, $callback );
36 9
		}
37 9
	}
38
39
	/**
40
	 * @since  1.0
41
	 *
42
	 * @param string $name
43
	 *
44
	 * @return boolean
45
	 */
46 1
	public function isRegistered( $name ) {
47 1
		return Hooks::isRegistered( $name );
48
	}
49
50
	/**
51
	 * @since  1.0
52
	 *
53
	 * @param string $name
54
	 *
55
	 * @return Callable|false
56
	 */
57 1
	public function getHandlerFor( $name ) {
58 1
		return isset( $this->handlers[$name] ) ? $this->handlers[$name] : false;
59
	}
60
61 10
	private function addCallbackHandlers( $options ) {
62
63 10
		$dynamicInterwikiPrefixLoader = new DynamicInterwikiPrefixLoader(
64 10
			$options['externalRepositoryEndpoints']
65 10
		);
66
67
		$this->handlers['InterwikiLoadPrefix'] = function( $prefix, &$interwiki ) use( $dynamicInterwikiPrefixLoader ) {
68 2
			return $dynamicInterwikiPrefixLoader->tryToLoadIwMapForExternalRepository( $prefix, $interwiki );
69
		};
70 10
	}
71
72
}
73