Skip to content

Commit 436b32b

Browse files
committed
updates to teh page loader class
1 parent 57769e1 commit 436b32b

1 file changed

Lines changed: 74 additions & 38 deletions

File tree

src/Loader.php

Lines changed: 74 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,11 @@ public function __construct()
3232
/**
3333
* gets the page routes
3434
*
35-
* @param bool $include_admin
3635
* @return array of routes
3736
*/
38-
public function get_routes($include_admin = false)
37+
public function get_routes()
3938
{
40-
//if ($include_admin === FALSE && $GLOBALS['tf']->ima === 'admin')
41-
//$include_admin = TRUE;
42-
$routes = array_merge($this->public_routes, $this->routes);
43-
if ($include_admin === true) {
44-
$routes = array_merge($this->admin_routes, $routes);
45-
}
39+
$routes = $this->routes;
4640
uksort($routes, function ($a, $b) {
4741
if (strlen($a) == strlen($b)) {
4842
if ($a == $b) {
@@ -58,34 +52,48 @@ public function get_routes($include_admin = false)
5852
}
5953

6054
/**
61-
* gets the admin page routes
55+
* returns the value of a setting
6256
*
63-
* @return array of routes
57+
* @param string $setting
58+
* @return mixed the value of the setting
6459
*/
65-
public function get_admin_routes()
60+
public function get_setting($setting)
6661
{
67-
return $this->admin_routes;
62+
return constant($setting);
6863
}
6964

7065
/**
71-
* gets the public page routes
66+
* adds a requirement into the loader and registers it as a page with the router
7267
*
73-
* @return array of routes
68+
* @param string $type route type client,admin,public,public_file,client_ajax,public_ajax,admin_ajax
69+
* @param string $function php function name or class.class_name
70+
* @param string $source php source file
71+
* @param string $namespace optional php namespace
72+
* @param string $base base path
73+
* @param mixed $methods request methods, string or array including get post put head patch etc..
7474
*/
75-
public function get_public_routes()
75+
public function add_route_requirement($type, $function, $source, $namespace = '', $path = false, $methods = false)
7676
{
77-
return $this->public_routes;
77+
if ($path === false)
78+
$path = '/'.$function;
79+
if ($methods === false)
80+
$methods = ['GET', 'POST'];
81+
$this->routes[$path] = [$type, $namespace.$function, $methods];
82+
$this->add_requirement($function, $source, $namespace);
7883
}
7984

8085
/**
81-
* returns the value of a setting
86+
* adds a requirement into the loader and registers it as a page with the router
8287
*
83-
* @param string $setting
84-
* @return mixed the value of the setting
88+
* @param string $function php function name or class.class_name
89+
* @param string $source php source file
90+
* @param string $namespace optional php namespace
91+
* @param mixed $methods request methods, string or array including get post put head patch etc..
8592
*/
86-
public function get_setting($setting)
93+
public function add_page_requirement($function, $source, $namespace = '', $methods = false)
8794
{
88-
return constant($setting);
95+
$this->add_route_requirement('client', $function, $source, $namespace, '/'.$function, $methods);
96+
$this->add_route_requirement('client', $function, $source, $namespace, '/admin/'.$function, $methods);
8997
}
9098

9199
/**
@@ -94,12 +102,35 @@ public function get_setting($setting)
94102
* @param string $function php function name or class.class_name
95103
* @param string $source php source file
96104
* @param string $namespace optional php namespace
105+
* @param mixed $methods request methods, string or array including get post put head patch etc..
97106
*/
98-
public function add_page_requirement($function, $source, $namespace = '')
107+
public function add_root_page_requirement($function, $source, $namespace = '', $methods = false)
99108
{
100-
$this->routes['/'.$function] = $namespace.$function;
101-
$this->routes['/admin/'.$function] = $namespace.$function;
102-
$this->add_requirement($function, $source, $namespace);
109+
$this->add_route_requirement('client', $function, $source, $namespace, '/'.$function, $methods);
110+
}
111+
112+
/**
113+
* adds a requirement into the loader and registers it as a page with the router
114+
*
115+
* @param string $function php function name or class.class_name
116+
* @param string $path source file path
117+
* @param mixed $methods request methods, string or array including get post put head patch etc..
118+
*/
119+
public function add_public_requirement($function, $source, $namespace = '', $methods = false)
120+
{
121+
$this->add_route_requirement('public', $function, $source, $namespace, '/'.$function, $methods);
122+
}
123+
124+
/**
125+
* adds a requirement into the loader and registers it as a page with the router
126+
*
127+
* @param string $function php function name or class.class_name
128+
* @param string $source source file path
129+
* @param mixed $methods request methods, string or array including get post put head patch etc..
130+
*/
131+
public function add_public_file($function, $source, $methods = false)
132+
{
133+
$this->add_route_requirement('public_file', $function, $source, '', '/'.$function, $methods);
103134
}
104135

105136
/**
@@ -108,22 +139,26 @@ public function add_page_requirement($function, $source, $namespace = '')
108139
* @param string $function php function name or class.class_name
109140
* @param string $source php source file
110141
* @param string $namespace optional php namespace
142+
* @param mixed $methods request methods, string or array including get post put head patch etc..
111143
*/
112-
public function add_root_page_requirement($function, $source, $namespace = '')
144+
public function add_ajax_page_requirement($function, $source, $namespace = '', $methods = false)
113145
{
114-
$this->routes['/'.$function] = $namespace.$function;
115-
$this->add_requirement($function, $source, $namespace);
146+
$this->add_route_requirement('client_ajax', $function, $source, $namespace, '/ajax/'.$function, $methods);
147+
$this->add_route_requirement('client_ajax', $function, $source, $namespace, '/admin/ajax/'.$function, $methods);
116148
}
117149

118150
/**
119151
* adds a requirement into the loader and registers it as a page with the router
120152
*
121153
* @param string $function php function name or class.class_name
122-
* @param string $path source file path
154+
* @param string $source php source file
155+
* @param string $namespace optional php namespace
156+
* @param mixed $methods request methods, string or array including get post put head patch etc..
123157
*/
124-
public function add_public_path($page, $source)
158+
public function add_api_page_requirement($function, $source, $namespace = '', $methods = false)
125159
{
126-
$this->public_routes['/'.$page] = $source;
160+
$this->add_route_requirement('client_api', $function, $source, $namespace, '/apiv2/'.$function, $methods);
161+
$this->add_route_requirement('client_api', $function, $source, $namespace, '/admin/apiv2/'.$function, $methods);
127162
}
128163

129164
/**
@@ -132,11 +167,11 @@ public function add_public_path($page, $source)
132167
* @param string $function php function name or class.class_name
133168
* @param string $source php source file
134169
* @param string $namespace optional php namespace
170+
* @param mixed $methods request methods, string or array including get post put head patch etc..
135171
*/
136-
public function add_ajax_page_requirement($function, $source, $namespace = '')
172+
public function add_apmin_api_page_requirement($function, $source, $namespace = '', $methods = false)
137173
{
138-
$this->routes['/ajax/'.$function] = $namespace.$function;
139-
$this->add_requirement($function, $source, $namespace);
174+
$this->add_route_requirement('admin_api', $function, $source, $namespace, '/admin/ajax/'.$function, $methods);
140175
}
141176

142177
/**
@@ -145,11 +180,11 @@ public function add_ajax_page_requirement($function, $source, $namespace = '')
145180
* @param string $function php function name or class.class_name
146181
* @param string $source php source file
147182
* @param string $namespace optional php namespace
183+
* @param mixed $methods request methods, string or array including get post put head patch etc..
148184
*/
149-
public function add_admin_page_requirement($function, $source, $namespace = '')
185+
public function add_admin_page_requirement($function, $source, $namespace = '', $methods = false)
150186
{
151-
$this->admin_routes['/admin/'.$function] = $namespace.$function;
152-
$this->add_requirement($function, $source, $namespace);
187+
$this->add_route_requirement('admin', $function, $source, $namespace, '/admin/'.$function, $methods);
153188
}
154189

155190
/**
@@ -158,8 +193,9 @@ public function add_admin_page_requirement($function, $source, $namespace = '')
158193
* @param string $function php function name or class.class_name
159194
* @param string $source php source file
160195
* @param string $namespace optional php namespace
196+
* @param mixed $methods request methods, string or array including get post put head patch etc..
161197
*/
162-
public function add_requirement($function, $source, $namespace = '')
198+
public function add_requirement($function, $source, $namespace = '', $methods = false)
163199
{
164200
$this->requirements[$function] = $namespace.$source;
165201
}

0 commit comments

Comments
 (0)