@@ -36,22 +36,22 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -48,8 +48,7 @@ discard block |
||
| 48 | 48 | $function_output = app_content($request, $args); |
| 49 | 49 | if (!is_array( $function_output) ) { |
| 50 | 50 | $function_output = ["status" => 500, "error" => "Internal Server Error"]; |
| 51 | - } |
|
| 52 | - else { |
|
| 51 | + } else { |
|
| 53 | 52 | if (!isset($function_output['status'])) { |
| 54 | 53 | $function_output['status']=200; |
| 55 | 54 | } |
@@ -57,8 +56,7 @@ discard block |
||
| 57 | 56 | } |
| 58 | 57 | $response->getBody()->write(json_encode($function_output)); |
| 59 | 58 | $newResponse = $response->withHeader('Content-Type', 'application/json;charset=utf-8')->withHeader('X-Powered-By', "reformo/rslim")->withStatus($status); |
| 60 | - } |
|
| 61 | - else { |
|
| 59 | + } else { |
|
| 62 | 60 | if (!file_exists($this->config['base_dir'].$template)) { |
| 63 | 61 | throw new \Exception("<strong>Template file not found!</strong> " . $route . '/' . $action . " needs a template file at:" . $template ); |
| 64 | 62 | } |
@@ -88,15 +86,13 @@ discard block |
||
| 88 | 86 | if (!file_exists($this->config['base_dir'] . $widget_template)) { |
| 89 | 87 | if (is_string($widget_content)) { |
| 90 | 88 | return $widget_content; |
| 91 | - } |
|
| 92 | - else { |
|
| 89 | + } else { |
|
| 93 | 90 | throw new \Exception("<strong>Widget should return string:</strong> " . $widget_name . '/' . $widget_action . "!"); |
| 94 | 91 | } |
| 95 | 92 | } else { |
| 96 | 93 | return $this->twig->render($widget_template, $widget_content); |
| 97 | 94 | } |
| 98 | - } |
|
| 99 | - else { |
|
| 95 | + } else { |
|
| 100 | 96 | throw new \Exception("<strong>Widget function not found!</strong> " . $widget_name . '/' . $widget_action . "!"); |
| 101 | 97 | } |
| 102 | 98 | }, |
@@ -119,8 +115,7 @@ discard block |
||
| 119 | 115 | $newResponse->write($app_content); |
| 120 | 116 | } |
| 121 | 117 | return $newResponse; |
| 122 | - } |
|
| 123 | - else { |
|
| 118 | + } else { |
|
| 124 | 119 | return $this->not_found($request, $response, $return_type, 'Controller '. $route . '/' . $action." not found"); |
| 125 | 120 | } |
| 126 | 121 | } |
@@ -131,8 +126,7 @@ discard block |
||
| 131 | 126 | if ($return_type == 'json') { |
| 132 | 127 | $response->getBody()->write( json_encode(['status'=>404, 'message'=>$message])); |
| 133 | 128 | return $response->withHeader('Content-Type', 'application/json;charset=utf-8')->withHeader('X-Powered-By', "reformo/rslim")->withStatus(404); |
| 134 | - } |
|
| 135 | - else { |
|
| 129 | + } else { |
|
| 136 | 130 | return $response->withStatus(404) |
| 137 | 131 | ->withHeader('Content-Type', 'text/html')->withHeader('X-Powered-By', "reformo/rslim") |
| 138 | 132 | ->write($this->twig->render($not_found_template, ['message'=>$message])); |