Completed
Push — master ( f61c24...77e5da )
by Sudar
15:19
created

UILoader::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php namespace EmailLog\Core\UI;
2
3
/**
4
 * Admin UI Loader.
5
 * Loads and initializes all admin pages and components.
6
 *
7
 * @since 2.0
8
 */
9
class UILoader {
10
11
	/**
12
	 * Plugin filename.
13
	 *
14
	 * @var string
15
	 */
16
	protected $plugin_file;
17
18
	/**
19
	 * UI Component List.
20
	 *
21
	 * @var array
22
	 */
23
	protected $components = array();
24
25
	/**
26
	 * List of Admin pages.
27
	 * @var array
28
	 */
29
	protected $pages = array();
30
31
	/**
32
	 * Setup UI Loader.
33
	 *
34
	 * @param string $file Plugin main file.
35
	 */
36
	public function __construct( $file ) {
37
		$this->plugin_file = $file;
38
	}
39
40
	/**
41
	 * Load all components and setup hooks.
42
	 */
43
	public function load() {
44
		$this->initialize_components();
45
		$this->initialize_pages();
46
47
		foreach ( $this->components as $component ) {
48
			$component->load();
49
		}
50
51
		foreach ( $this->pages as $page ) {
52
			$page->load();
53
		}
54
	}
55
56
	/**
57
	 * Initialize UI component Objects.
58
	 *
59
	 * This method may be overwritten in tests.
60
	 *
61
	 * @access protected
62
	 */
63
	protected function initialize_components() {
64
		$this->components['plugin_list_enhancer'] = new Component\PluginListEnhancer( $this->plugin_file );
65
	}
66
67
	/**
68
	 * Initialize Admin page Objects.
69
	 *
70
	 * This method may be overwritten in tests.
71
	 *
72
	 * @access protected
73
	 */
74
	protected function initialize_pages() {
75
		$this->pages['log_list_page']   = new Page\LogListPage( $this->plugin_file );
76
		$this->pages['addon_list_page'] = new Page\AddonListPage( $this->plugin_file );
77
		$this->pages['settings_page']   = new Page\SettingsPage( $this->plugin_file );
78
	}
79
}
80