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