Completed
Push — develop ( 8a0307...d86f0d )
by David
03:49
created

Wordlift_Configuration_Service::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Get WordLift's configuration settings stored in WordPress database.
5
 *
6
 * @since 3.6.0
7
 */
8
class Wordlift_Configuration_Service {
9
10
	const ENTITY_BASE_PATH_KEY = 'wl_entity_base_path';
11
12
	/**
13
	 * The Wordlift_Configuration_Service's singleton instance.
14
	 *
15
	 * @since 3.6.0
16
	 *
17
	 * @access private
18
	 * @var \Wordlift_Configuration_Service $instance Wordlift_Configuration_Service's singleton instance.
19
	 */
20
	private static $instance;
21
22
	/**
23
	 * Create a Wordlift_Configuration_Service's instance.
24
	 *
25
	 * @since 3.6.0
26
	 */
27
	public function __construct() {
28
29
		self::$instance = $this;
30
31
	}
32
33
	/**
34
	 * Get the singleton instance.
35
	 *
36
	 * @since 3.6.0
37
	 *
38
	 * @return \Wordlift_Configuration_Service
39
	 */
40
	public static function get_instance() {
41
42
		return self::$instance;
43
	}
44
45
	/**
46
	 * Get a configuration given the option name and a key. The option value is
47
	 * expected to be an array.
48
	 *
49
	 * @since 3.6.0
50
	 *
51
	 * @param string $option The option name.
52
	 * @param string $key A key in the option value array.
53
	 * @param string $default The default value in case the key is not found (by default an empty string).
54
	 *
55
	 * @return mixed The configuration value or the default value if not found.
56
	 */
57
	private function get( $option, $key, $default = '' ) {
58
59
		$options = get_option( $option, array() );
60
61
		return isset( $options[ $key ] ) ? $options[ $key ] : $default;
62
	}
63
64
	/**
65
	 * Get the entity base path, by default 'entity'.
66
	 *
67
	 * @since 3.6.0
68
	 *
69
	 * @return string The entity base path.
70
	 */
71
	public function get_entity_base_path() {
72
73
		return $this->get( 'wl_general_settings', self::ENTITY_BASE_PATH_KEY, 'entity' );
74
	}
75
76
}
77