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
|
|
|
protected $requirements; |
16
|
|
|
protected $routes; |
17
|
|
|
protected $admin_routes; |
18
|
|
|
protected $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
|
|
|
* @param bool $include_admin |
34
|
|
|
* @return array of routes |
35
|
|
|
*/ |
36
|
|
|
public function get_routes($include_admin = FALSE) { |
|
|
|
|
37
|
|
|
//if ($include_admin === FALSE && $GLOBALS['tf']->ima === 'admin') |
|
|
|
|
38
|
|
|
//$include_admin = TRUE; |
|
|
|
|
39
|
|
|
$routes = array_merge($this->public_routes, $this->routes); |
40
|
|
|
if ($include_admin === TRUE) |
41
|
|
|
$routes = array_merge($this->admin_routes, $routes); |
42
|
|
|
uksort($routes, function($a, $b) { |
43
|
|
|
if (strlen($a) == strlen($b)) { |
44
|
|
|
if ($a == $b) |
45
|
|
|
return 0; |
46
|
|
|
return ($a > $b) ? -1 : 1; |
47
|
|
|
} else |
48
|
|
|
return (strlen($a) > strlen($b)) ? -1 : 1; |
49
|
|
|
}); |
50
|
|
|
//myadmin_log('route', 'debug', json_encode($routes), __LINE__, __FILE__); |
|
|
|
|
51
|
|
|
return $routes; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* gets the admin page routes |
56
|
|
|
* |
57
|
|
|
* @return array of routes |
58
|
|
|
*/ |
59
|
|
|
public function get_admin_routes() { |
60
|
|
|
return $this->admin_routes; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* gets the public page routes |
65
|
|
|
* |
66
|
|
|
* @return array of routes |
67
|
|
|
*/ |
68
|
|
|
public function get_public_routes() { |
69
|
|
|
return $this->public_routes; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* returns the value of a setting |
74
|
|
|
* |
75
|
|
|
* @param string $setting |
76
|
|
|
* @return mixed the value of the setting |
77
|
|
|
*/ |
78
|
|
|
public function get_setting($setting) { |
79
|
|
|
return constant($setting); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* adds a requirement into the loader and registers it as a page with the router |
84
|
|
|
* |
85
|
|
|
* @param string $function php function name or class.class_name |
86
|
|
|
* @param string $source php source file |
87
|
|
|
* @param string $namespace optional php namespace |
88
|
|
|
*/ |
89
|
|
|
public function add_page_requirement($function, $source, $namespace = '') { |
90
|
|
|
$this->routes['/'.$function] = $namespace.$function; |
91
|
|
|
$this->routes['/admin/'.$function] = $namespace.$function; |
92
|
|
|
$this->add_requirement($function, $source, $namespace); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* adds a requirement into the loader and registers it as a page with the router |
97
|
|
|
* |
98
|
|
|
* @param string $function php function name or class.class_name |
99
|
|
|
* @param string $source php source file |
100
|
|
|
* @param string $namespace optional php namespace |
101
|
|
|
*/ |
102
|
|
|
public function add_root_page_requirement($function, $source, $namespace = '') { |
103
|
|
|
$this->routes['/'.$function] = $namespace.$function; |
104
|
|
|
$this->add_requirement($function, $source, $namespace); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* adds a requirement into the loader and registers it as a page with the router |
109
|
|
|
* |
110
|
|
|
* @param string $function php function name or class.class_name |
|
|
|
|
111
|
|
|
* @param string $path source file path |
|
|
|
|
112
|
|
|
*/ |
113
|
|
|
public function add_public_path($page, $source) { |
114
|
|
|
$this->public_routes['/'.$page] = $source; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* adds a requirement into the loader and registers it as a page with the router |
119
|
|
|
* |
120
|
|
|
* @param string $function php function name or class.class_name |
121
|
|
|
* @param string $source php source file |
122
|
|
|
* @param string $namespace optional php namespace |
123
|
|
|
*/ |
124
|
|
|
public function add_ajax_page_requirement($function, $source, $namespace = '') { |
125
|
|
|
$this->routes['/ajax/'.$function] = $namespace.$function; |
126
|
|
|
$this->add_requirement($function, $source, $namespace); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* adds a requirement into the loader and registers it as a page with the router |
131
|
|
|
* |
132
|
|
|
* @param string $function php function name or class.class_name |
133
|
|
|
* @param string $source php source file |
134
|
|
|
* @param string $namespace optional php namespace |
135
|
|
|
*/ |
136
|
|
|
public function add_admin_page_requirement($function, $source, $namespace = '') { |
137
|
|
|
$this->admin_routes['/admin/'.$function] = $namespace.$function; |
138
|
|
|
$this->add_requirement($function, $source, $namespace); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* adds a requirement into the loader |
143
|
|
|
* |
144
|
|
|
* @param string $function php function name or class.class_name |
145
|
|
|
* @param string $source php source file |
146
|
|
|
* @param string $namespace optional php namespace |
147
|
|
|
*/ |
148
|
|
|
public function add_requirement($function, $source, $namespace = '') { |
149
|
|
|
$this->requirements[$function] = $namespace.$source; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* gets an array of requirements for loading |
154
|
|
|
* |
155
|
|
|
* @return array the array of requirements |
156
|
|
|
*/ |
157
|
|
|
public function get_requirements() { |
158
|
|
|
return $this->requirements; |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
|
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
.