summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/src/MediaWiki/Hooks/HookHandler.php
blob: 477220f56dbcc6d7fe2de1041dc62aa0a1afa854 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php

namespace SMW\MediaWiki\Hooks;

use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;
use SMW\Options;

/**
 * @license GNU GPL v2+
 * @since 2.5
 *
 * @author mwjames
 */
class HookHandler {

	use LoggerAwareTrait;

	/**
	 * @var Options
	 */
	private $options;

	/**
	 * @since 2.5
	 */
	public function __construct() {
		$this->options = new Options();
	}

	/**
	 * @since 3.0
	 *
	 * @param array $options
	 */
	public function setOptions( array $options ) {
		$this->options = new Options( $options );
	}

	/**
	 * @since 3.0
	 *
	 * @param string $key
	 * @param mixed $default
	 *
	 * @return mixed
	 */
	public function getOption( $key, $default = null ) {

		if ( $this->options === null ) {
			$this->setOptions( [] );
		}

		return $this->options->safeGet( $key, $default );
	}

	/**
	 * @since 3.0
	 *
	 * @param string $key
	 * @param mixed $flag
	 *
	 * @return boolean
	 */
	public function isFlagSet( $key, $flag ) {
		return $this->options->isFlagSet( $key, $flag );
	}

	protected function log( $message, $context = [] ) {
		if ( $this->logger instanceof LoggerInterface ) {
			$this->logger->info( $message, $context );
		}
	}

}