| @@ -41,9 +41,9 @@ discard block | ||
| 41 | 41 |          if (file_exists($controller)) { | 
| 42 | 42 | require_once($controller); | 
| 43 | 43 | |
| 44 | - $function_name = $route . '_' . $action; | |
| 44 | + $function_name = $route . '_' . $action; | |
| 45 | 45 |              if (!function_exists($function_name)) { | 
| 46 | - return $this->notFound($request, $response, $return_type, 'Controller '. $route . '/' . $action . " has not ".$function_name." function"); | |
| 46 | + return $this->notFound($request, $response, $return_type, 'Controller ' . $route . '/' . $action . " has not " . $function_name . " function"); | |
| 47 | 47 | } | 
| 48 | 48 |              if ($return_type == 'json') { | 
| 49 | 49 | $status = 500; | 
| @@ -52,14 +52,14 @@ discard block | ||
| 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)) { | |
| 62 | +                if (!file_exists($this->config['base_dir'] . $template)) { | |
| 63 | 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); | 
| @@ -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'] . '/' . $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'; | 
| @@ -111,23 +111,23 @@ discard block | ||
| 111 | 111 | $main_template = '/' . $this->config['app_dir'] . '/templates/_' . $main_template_name . '.html'; | 
| 112 | 112 | |
| 113 | 113 |                  if (!file_exists($this->config['base_dir'] . $main_template)) { | 
| 114 | -                    throw new \Exception("<strong>Main emplate file not found!</strong> ".$route . '/' . $action . | |
| 114 | +                    throw new \Exception("<strong>Main emplate file not found!</strong> " . $route . '/' . $action . | |
| 115 | 115 | " 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 |          } else { | 
| 123 | - return $this->notFound($request, $response, $return_type, 'Controller '. $route . '/' . $action." not found"); | |
| 123 | + return $this->notFound($request, $response, $return_type, 'Controller ' . $route . '/' . $action . " not found"); | |
| 124 | 124 | } | 
| 125 | 125 | } | 
| 126 | 126 | |
| 127 | 127 | public function notFound($request, $response, $return_type = 'html', $message = "") | 
| 128 | 128 |      { | 
| 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 | 132 | $response->getBody()->write(json_encode(['status'=>404, 'message'=>$message])); | 
| 133 | 133 |              return $response->withHeader('Content-Type', 'application/json;charset=utf-8') | 
| @@ -141,16 +141,16 @@ 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']->runRoute($req, $res, $route, $action, $args['return_type'], $args); | 
| 147 | 147 | })->setArguments(['controller'=>$controller, 'return_type'=>$return_type, 'RSlim'=>$this]); | 
| 148 | 148 | } | 
| 149 | 149 | |
| 150 | 150 | public function run() | 
| 151 | 151 |      { | 
| 152 | -        $this->container['notFoundHandler'] = function ($c) { | |
| 153 | -            return function (Request $req, Response $res) use ($c) { | |
| 152 | +        $this->container['notFoundHandler'] = function($c) { | |
| 153 | +            return function(Request $req, Response $res) use ($c) { | |
| 154 | 154 | return $c['response'] | 
| 155 | 155 | ->withStatus(404) | 
| 156 | 156 |                      ->withHeader('Content-Type', 'text/html')->withHeader('X-Powered-By', "reformo/rslim") | 
| @@ -158,16 +158,16 @@ discard block | ||
| 158 | 158 | }; | 
| 159 | 159 | }; | 
| 160 | 160 |          if ($this->config['bypass_error_handlers'] === true) { | 
| 161 | -            $this->container['errorHandler'] = function ($container) { | |
| 162 | -                return function ($request, $response, $exception) use ($container) { | |
| 161 | +            $this->container['errorHandler'] = function($container) { | |
| 162 | +                return function($request, $response, $exception) use ($container) { | |
| 163 | 163 | $response->getBody()->rewind(); | 
| 164 | 164 | return $response->withStatus(500) | 
| 165 | 165 |                          ->withHeader('Content-Type', 'text/html') | 
| 166 | 166 | ->write($exception->getMessage()); | 
| 167 | 167 | }; | 
| 168 | 168 | }; | 
| 169 | -            $this->container['phpErrorHandler'] = function ($container) { | |
| 170 | -                return function ($request, $response, $error) use ($container) { | |
| 169 | +            $this->container['phpErrorHandler'] = function($container) { | |
| 170 | +                return function($request, $response, $error) use ($container) { | |
| 171 | 171 | $response->getBody()->rewind(); | 
| 172 | 172 | return $response->withStatus(500) | 
| 173 | 173 |                          ->withHeader('Content-Type', 'text/html') |