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
|
|
|
private $public_routes; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Loader constructor. |
22
|
|
|
*/ |
23
|
|
|
public function __construct() { |
24
|
|
|
$this->requirements = []; |
25
|
|
|
$this->routes = []; |
26
|
|
|
$this->admin_routes = []; |
27
|
|
|
$this->public_routes = []; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* gets the page routes |
32
|
|
|
* |
33
|
|
|
* @return array of routes |
34
|
|
|
*/ |
35
|
|
|
public function get_routes() { |
36
|
|
|
return $this->routes; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* gets the admin page routes |
41
|
|
|
* |
42
|
|
|
* @return array of routes |
43
|
|
|
*/ |
44
|
|
|
public function get_admin_routes() { |
45
|
|
|
return $this->admin_routes; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* gets the public page routes |
50
|
|
|
* |
51
|
|
|
* @return array of routes |
52
|
|
|
*/ |
53
|
|
|
public function get_public_routes() { |
54
|
|
|
return $this->public_routes; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* returns the value of a setting |
59
|
|
|
* |
60
|
|
|
* @param string $setting |
61
|
|
|
* @return mixed the value of the setting |
62
|
|
|
*/ |
63
|
|
|
public function get_setting($setting) { |
64
|
|
|
return constant($setting); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* adds a requirement into the loader and registers it as a page with the router |
69
|
|
|
* |
70
|
|
|
* @param string $function php function name or class.class_name |
71
|
|
|
* @param string $source php source file |
72
|
|
|
* @param string $namespace optional php namespace |
73
|
|
|
*/ |
74
|
|
|
public function add_page_requirement($function, $source, $namespace = '') { |
75
|
|
|
$this->routes['/'.$function] = $namespace.$function; |
76
|
|
|
$this->admin_routes['/'.$function] = $namespace.$function; |
77
|
|
|
$this->add_requirement($function, $source, $namespace); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* adds a requirement into the loader and registers it as a page with the router |
82
|
|
|
* |
83
|
|
|
* @param string $function php function name or class.class_name |
84
|
|
|
* @param string $source php source file |
85
|
|
|
* @param string $namespace optional php namespace |
86
|
|
|
*/ |
87
|
|
|
public function add_root_page_requirement($function, $source, $namespace = '') { |
88
|
|
|
$this->routes['/'.$function] = $namespace.$function; |
89
|
|
|
$this->add_requirement($function, $source, $namespace); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* adds a requirement into the loader and registers it as a page with the router |
94
|
|
|
* |
95
|
|
|
* @param string $function php function name or class.class_name |
|
|
|
|
96
|
|
|
* @param string $path source file path |
|
|
|
|
97
|
|
|
*/ |
98
|
|
|
public function add_public_path($page, $source) { |
99
|
|
|
$this->public_routes['/'.$page] = $source; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* adds a requirement into the loader and registers it as a page with the router |
104
|
|
|
* |
105
|
|
|
* @param string $function php function name or class.class_name |
106
|
|
|
* @param string $source php source file |
107
|
|
|
* @param string $namespace optional php namespace |
108
|
|
|
*/ |
109
|
|
|
public function add_ajax_page_requirement($function, $source, $namespace = '') { |
110
|
|
|
$this->routes['/ajax/'.$function] = $namespace.$function; |
111
|
|
|
$this->add_requirement($function, $source, $namespace); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* adds a requirement into the loader and registers it as a page with the router |
116
|
|
|
* |
117
|
|
|
* @param string $function php function name or class.class_name |
118
|
|
|
* @param string $source php source file |
119
|
|
|
* @param string $namespace optional php namespace |
120
|
|
|
*/ |
121
|
|
|
public function add_admin_page_requirement($function, $source, $namespace = '') { |
122
|
|
|
$this->admin_routes['/'.$function] = $namespace.$function; |
123
|
|
|
$this->add_requirement($function, $source, $namespace); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* adds a requirement into the loader |
128
|
|
|
* |
129
|
|
|
* @param string $function php function name or class.class_name |
130
|
|
|
* @param string $source php source file |
131
|
|
|
* @param string $namespace optional php namespace |
132
|
|
|
*/ |
133
|
|
|
public function add_requirement($function, $source, $namespace = '') { |
134
|
|
|
$this->requirements[$function] = $namespace.$source; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* gets an array of requirements for loading |
139
|
|
|
* |
140
|
|
|
* @return array the array of requirements |
141
|
|
|
*/ |
142
|
|
|
public function get_requirements() { |
143
|
|
|
return $this->requirements; |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
|
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
.