1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MyAdmin\Plugins; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class Loader |
7
|
|
|
* |
8
|
|
|
* Here are some of the regexes ive used to change code to using this class: |
9
|
|
|
* ('[^']*') *=> *('[^']*'), |
10
|
|
|
* $loader->add_requirement(\1, \2); |
11
|
|
|
* |
12
|
|
|
* @package MyAdmin |
13
|
|
|
*/ |
14
|
|
|
class Loader { |
|
|
|
|
15
|
|
|
private $requirements; |
16
|
|
|
private $routes; |
17
|
|
|
private $admin_routes; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Loader constructor. |
21
|
|
|
*/ |
22
|
|
|
public function __construct() { |
23
|
|
|
$this->requirements = []; |
24
|
|
|
$this->routes = []; |
25
|
|
|
$this->admin_routes = []; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* gets the page routes |
30
|
|
|
* |
31
|
|
|
* @return array of routes |
32
|
|
|
*/ |
33
|
|
|
public function get_routes() { |
34
|
|
|
return $this->routes; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* gets the admin page routes |
39
|
|
|
* |
40
|
|
|
* @return array of routes |
41
|
|
|
*/ |
42
|
|
|
public function get_admin_routes() { |
43
|
|
|
return $this->admin_routes; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* returns the value of a setting |
48
|
|
|
* |
49
|
|
|
* @param string $setting |
50
|
|
|
* @return mixed the value of the setting |
51
|
|
|
*/ |
52
|
|
|
public function get_setting($setting) { |
53
|
|
|
return constant($setting); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* adds a requirement into the loader and registers it as a page with the router |
58
|
|
|
* |
59
|
|
|
* @param string $function php function name or class.class_name |
60
|
|
|
* @param string $source php source file |
61
|
|
|
* @param string $namespace optional php namespace |
62
|
|
|
*/ |
63
|
|
|
public function add_page_requirement($function, $source, $namespace = '') { |
64
|
|
|
$this->routes['/'.$function] = $namespace.$function; |
65
|
|
|
$this->admin_routes['/'.$function] = $namespace.$function; |
66
|
|
|
$this->add_requirement($function, $source, $namespace); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* adds a requirement into the loader and registers it as a page with the router |
71
|
|
|
* |
72
|
|
|
* @param string $function php function name or class.class_name |
73
|
|
|
* @param string $source php source file |
74
|
|
|
* @param string $namespace optional php namespace |
75
|
|
|
*/ |
76
|
|
|
public function add_root_page_requirement($function, $source, $namespace = '') { |
77
|
|
|
$this->routes['/'.$function] = $namespace.$function; |
78
|
|
|
$this->add_requirement($function, $source, $namespace); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* adds a requirement into the loader and registers it as a page with the router |
83
|
|
|
* |
84
|
|
|
* @param string $function php function name or class.class_name |
85
|
|
|
* @param string $source php source file |
86
|
|
|
* @param string $namespace optional php namespace |
87
|
|
|
*/ |
88
|
|
|
public function add_ajax_page_requirement($function, $source, $namespace = '') { |
89
|
|
|
$this->routes['/ajax/'.$function] = $namespace.$function; |
90
|
|
|
$this->add_requirement($function, $source, $namespace); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* adds a requirement into the loader and registers it as a page with the router |
95
|
|
|
* |
96
|
|
|
* @param string $function php function name or class.class_name |
97
|
|
|
* @param string $source php source file |
98
|
|
|
* @param string $namespace optional php namespace |
99
|
|
|
*/ |
100
|
|
|
public function add_admin_page_requirement($function, $source, $namespace = '') { |
101
|
|
|
$this->admin_routes['/'.$function] = $namespace.$function; |
102
|
|
|
$this->add_requirement($function, $source, $namespace); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* adds a requirement into the loader |
107
|
|
|
* |
108
|
|
|
* @param string $function php function name or class.class_name |
109
|
|
|
* @param string $source php source file |
110
|
|
|
* @param string $namespace optional php namespace |
111
|
|
|
*/ |
112
|
|
|
public function add_requirement($function, $source, $namespace = '') { |
113
|
|
|
$this->requirements[$function] = $namespace.$source; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* gets an array of requirements for loading |
118
|
|
|
* |
119
|
|
|
* @return array the array of requirements |
120
|
|
|
*/ |
121
|
|
|
public function get_requirements() { |
122
|
|
|
return $this->requirements; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
|
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString
.