|
@@ -37,30 +37,30 @@ discard block |
|
|
block discarded – undo |
|
37
|
37
|
$controller = $this->config['base_dir'] . '/' . $this->config['app_dir'] . '/controllers/' . $route . '/' . $action . '.php'; |
|
38
|
38
|
$template = '/' . $this->config['app_dir'] . '/templates/' . $route . '/' . $action . '.html'; |
|
39
|
39
|
|
|
40
|
|
- if(file_exists($controller)){ |
|
|
40
|
+ if (file_exists($controller)) { |
|
41
|
41
|
|
|
42
|
42
|
require_once($controller); |
|
43
|
43
|
|
|
44
|
|
- $function_name = $route . '_' . $action; |
|
45
|
|
- if(!function_exists($function_name)){ |
|
46
|
|
- return $this->not_found($request, $response, $return_type, 'Controller '. $route . '/' . $action . " has not app_content function"); |
|
|
44
|
+ $function_name = $route . '_' . $action; |
|
|
45
|
+ if (!function_exists($function_name)) { |
|
|
46
|
+ return $this->not_found($request, $response, $return_type, 'Controller ' . $route . '/' . $action . " has not app_content function"); |
|
47
|
47
|
} |
|
48
|
|
- if ($return_type == 'json'){ |
|
|
48
|
+ if ($return_type == 'json') { |
|
49
|
49
|
$status = 500; |
|
50
|
50
|
$function_output = call_user_func($function_name, $request, $args); |
|
51
|
|
- if (!is_array( $function_output) ) { |
|
|
51
|
+ if (!is_array($function_output)) { |
|
52
|
52
|
$function_output = ["status" => 500, "error" => "Internal Server Error"]; |
|
53
|
53
|
} else { |
|
54
|
54
|
if (!isset($function_output['status'])) { |
|
55
|
|
- $function_output['status']=200; |
|
|
55
|
+ $function_output['status'] = 200; |
|
56
|
56
|
} |
|
57
|
57
|
$status = (int) $function_output['status']; |
|
58
|
58
|
} |
|
59
|
59
|
$response->getBody()->write(json_encode($function_output)); |
|
60
|
60
|
$newResponse = $response->withHeader('Content-Type', 'application/json;charset=utf-8')->withHeader('X-Powered-By', "reformo/rslim")->withStatus($status); |
|
61
|
61
|
} else { |
|
62
|
|
- if (!file_exists($this->config['base_dir'].$template)) { |
|
63
|
|
- throw new \Exception("<strong>Template file not found!</strong> " . $route . '/' . $action . " needs a template file at:" . $template ); |
|
|
62
|
+ if (!file_exists($this->config['base_dir'] . $template)) { |
|
|
63
|
+ throw new \Exception("<strong>Template file not found!</strong> " . $route . '/' . $action . " needs a template file at:" . $template); |
|
64
|
64
|
} |
|
65
|
65
|
$function_output = call_user_func($function_name, $request, $args); |
|
66
|
66
|
if (!isset($function_output['data'])) { |
|
@@ -74,7 +74,7 @@ discard block |
|
|
block discarded – undo |
|
74
|
74
|
]); |
|
75
|
75
|
$filter = new \Twig_SimpleFunction( |
|
76
|
76
|
'rwidget_*_*', |
|
77
|
|
- function ($widget_name, $widget_action, $args = []) { |
|
|
77
|
+ function($widget_name, $widget_action, $args = []) { |
|
78
|
78
|
|
|
79
|
79
|
$widget_file = $this->config['base_dir'] . '/' . $this->config['app_dir'] . '/widgets/' . $widget_name . '/' . $widget_action . ".php"; |
|
80
|
80
|
$widget_template = '/' . $this->config['app_dir'] . '/templates/_widgets/' . $widget_name . '/' . $widget_action . '.html'; |
|
@@ -110,24 +110,24 @@ discard block |
|
|
block discarded – undo |
|
110
|
110
|
$main_template = '/' . $this->config['app_dir'] . '/templates/_' . $main_template_name . '.html'; |
|
111
|
111
|
|
|
112
|
112
|
if (!file_exists($this->config['base_dir'] . $main_template)) { |
|
113
|
|
- throw new \Exception("<strong>Main emplate file not found!</strong> " . $route . '/' . $action . " needs a main template file at:" . $main_template ); |
|
|
113
|
+ throw new \Exception("<strong>Main emplate file not found!</strong> " . $route . '/' . $action . " needs a main template file at:" . $main_template); |
|
114
|
114
|
} |
|
115
|
|
- $app_content = $this->twig->render( $main_template, $function_output); |
|
116
|
|
- $newResponse=$response->withHeader('X-Powered-By', "reformo/rslim"); |
|
|
115
|
+ $app_content = $this->twig->render($main_template, $function_output); |
|
|
116
|
+ $newResponse = $response->withHeader('X-Powered-By', "reformo/rslim"); |
|
117
|
117
|
$newResponse->write($app_content); |
|
118
|
118
|
} |
|
119
|
119
|
return $newResponse; |
|
120
|
120
|
} |
|
121
|
121
|
else { |
|
122
|
|
- return $this->not_found($request, $response, $return_type, 'Controller '. $route . '/' . $action." not found"); |
|
|
122
|
+ return $this->not_found($request, $response, $return_type, 'Controller ' . $route . '/' . $action . " not found"); |
|
123
|
123
|
} |
|
124
|
124
|
} |
|
125
|
125
|
|
|
126
|
|
- public function not_found($request, $response, $return_type = 'html', $message = ""){ |
|
|
126
|
+ public function not_found($request, $response, $return_type = 'html', $message = "") { |
|
127
|
127
|
|
|
128
|
|
- $not_found_template = '/apps/' . $this->config['app_name'] . '/templates/_404.html'; |
|
|
128
|
+ $not_found_template = '/apps/' . $this->config['app_name'] . '/templates/_404.html'; |
|
129
|
129
|
if ($return_type == 'json') { |
|
130
|
|
- $response->getBody()->write( json_encode(['status'=>404, 'message'=>$message])); |
|
|
130
|
+ $response->getBody()->write(json_encode(['status'=>404, 'message'=>$message])); |
|
131
|
131
|
return $response->withHeader('Content-Type', 'application/json;charset=utf-8')->withHeader('X-Powered-By', "reformo/rslim")->withStatus(404); |
|
132
|
132
|
} |
|
133
|
133
|
else { |
|
@@ -139,8 +139,8 @@ discard block |
|
|
block discarded – undo |
|
139
|
139
|
|
|
140
|
140
|
public function register($request_method, $pattern, $controller, $return_type = 'html') |
|
141
|
141
|
{ |
|
142
|
|
- $this->app->map([strtoupper($request_method)], $pattern, function(Request $req, Response $res, $args ){ |
|
143
|
|
- list($route,$action) = explode("/",$args['controller']); |
|
|
142
|
+ $this->app->map([strtoupper($request_method)], $pattern, function(Request $req, Response $res, $args) { |
|
|
143
|
+ list($route, $action) = explode("/", $args['controller']); |
|
144
|
144
|
return $args['RSlim']->run_route($req, $res, $route, $action, $args['return_type'], $args); |
|
145
|
145
|
})->setArguments(['controller'=>$controller, 'return_type'=>$return_type, 'RSlim'=>$this]); |
|
146
|
146
|
} |