@@ -111,12 +111,10 @@ |
||
| 111 | 111 | |
| 112 | 112 | try { |
| 113 | 113 | $router->run(); |
| 114 | - } |
|
| 115 | - catch (\Exception $e) |
|
| 114 | + } catch (\Exception $e) |
|
| 116 | 115 | { |
| 117 | 116 | $errorObject = ($e instanceof MethodExecutionNotAllowedException); |
| 118 | - } |
|
| 119 | - finally |
|
| 117 | + } finally |
|
| 120 | 118 | { |
| 121 | 119 | $this->assertTrue($errorObject, $e->getMessage()); |
| 122 | 120 | } |
@@ -29,11 +29,13 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | public static function create($module, Array $module_settings = []) |
| 31 | 31 | { |
| 32 | - if (empty($module)) |
|
| 33 | - throw new \RuntimeException("The module name must be specified"); |
|
| 32 | + if (empty($module)) { |
|
| 33 | + throw new \RuntimeException("The module name must be specified"); |
|
| 34 | + } |
|
| 34 | 35 | |
| 35 | - if (!is_string($module)) |
|
| 36 | - throw new \InvalidArgumentException("Invalid type given. string expected"); |
|
| 36 | + if (!is_string($module)) { |
|
| 37 | + throw new \InvalidArgumentException("Invalid type given. string expected"); |
|
| 38 | + } |
|
| 37 | 39 | |
| 38 | 40 | /* |
| 39 | 41 | * Module class instantiation |
@@ -44,22 +46,27 @@ discard block |
||
| 44 | 46 | */ |
| 45 | 47 | $fqn_module = "\\" . $module . "\\Module"; |
| 46 | 48 | |
| 47 | - if (!class_exists($fqn_module)) |
|
| 48 | - throw new Exception\ModuleNotFoundException("The module class '$fqn_module' does not exists!"); |
|
| 49 | + if (!class_exists($fqn_module)) { |
|
| 50 | + throw new Exception\ModuleNotFoundException("The module class '$fqn_module' does not exists!"); |
|
| 51 | + } |
|
| 49 | 52 | |
| 50 | 53 | $module = new $fqn_module($module); |
| 51 | 54 | |
| 52 | - if (array_key_exists('path', $module_settings)) |
|
| 53 | - $module->setModulePath($module_settings["path"]); |
|
| 55 | + if (array_key_exists('path', $module_settings)) { |
|
| 56 | + $module->setModulePath($module_settings["path"]); |
|
| 57 | + } |
|
| 54 | 58 | |
| 55 | - if (array_key_exists('classes', $module_settings)) |
|
| 56 | - $module->setClassPath($module_settings["classes"]); |
|
| 59 | + if (array_key_exists('classes', $module_settings)) { |
|
| 60 | + $module->setClassPath($module_settings["classes"]); |
|
| 61 | + } |
|
| 57 | 62 | |
| 58 | - if (array_key_exists('views', $module_settings)) |
|
| 59 | - $module->setViewPath($module_settings["views"]); |
|
| 63 | + if (array_key_exists('views', $module_settings)) { |
|
| 64 | + $module->setViewPath($module_settings["views"]); |
|
| 65 | + } |
|
| 60 | 66 | |
| 61 | - if (array_key_exists('config', $module_settings) && !is_null($module_settings["config"])) |
|
| 62 | - $module->setConfigFile($module_settings["config"]); |
|
| 67 | + if (array_key_exists('config', $module_settings) && !is_null($module_settings["config"])) { |
|
| 68 | + $module->setConfigFile($module_settings["config"]); |
|
| 69 | + } |
|
| 63 | 70 | |
| 64 | 71 | return $module; |
| 65 | 72 | } |
@@ -204,13 +204,13 @@ discard block |
||
| 204 | 204 | */ |
| 205 | 205 | public function setConfigFile($configFile) |
| 206 | 206 | { |
| 207 | - $_file = $this->basePath .'/'. $this->modulePath .'/'. $this->moduleName .'/'. $configFile; |
|
| 207 | + $_file = $this->basePath . '/' . $this->modulePath . '/' . $this->moduleName . '/' . $configFile; |
|
| 208 | 208 | |
| 209 | 209 | if (!file_exists($_file)) |
| 210 | 210 | throw new \RuntimeException("The file '$_file' does not exists"); |
| 211 | 211 | |
| 212 | 212 | $this->configFile = |
| 213 | - $this->basePath .'/'. $this->modulePath .'/'. $this->moduleName .'/'. $configFile; |
|
| 213 | + $this->basePath . '/' . $this->modulePath . '/' . $this->moduleName . '/' . $configFile; |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | /** |
@@ -286,15 +286,15 @@ discard block |
||
| 286 | 286 | $class = ""; |
| 287 | 287 | |
| 288 | 288 | if (!empty($this->basePath)) |
| 289 | - $class .= $this->basePath .'/'; |
|
| 289 | + $class .= $this->basePath . '/'; |
|
| 290 | 290 | |
| 291 | 291 | if (!empty($this->modulePath)) |
| 292 | - $class .= $this->modulePath .'/'; |
|
| 292 | + $class .= $this->modulePath . '/'; |
|
| 293 | 293 | |
| 294 | - $class .= $module ."/"; |
|
| 294 | + $class .= $module . "/"; |
|
| 295 | 295 | |
| 296 | 296 | if (!empty($this->classPath)) |
| 297 | - $class .= $this->classPath .'/'; |
|
| 297 | + $class .= $this->classPath . '/'; |
|
| 298 | 298 | |
| 299 | 299 | $class .= implode("/", $nm) . ".php"; |
| 300 | 300 | |
@@ -206,8 +206,9 @@ discard block |
||
| 206 | 206 | { |
| 207 | 207 | $_file = $this->basePath .'/'. $this->modulePath .'/'. $this->moduleName .'/'. $configFile; |
| 208 | 208 | |
| 209 | - if (!file_exists($_file)) |
|
| 210 | - throw new \RuntimeException("The file '$_file' does not exists"); |
|
| 209 | + if (!file_exists($_file)) { |
|
| 210 | + throw new \RuntimeException("The file '$_file' does not exists"); |
|
| 211 | + } |
|
| 211 | 212 | |
| 212 | 213 | $this->configFile = |
| 213 | 214 | $this->basePath .'/'. $this->modulePath .'/'. $this->moduleName .'/'. $configFile; |
@@ -285,20 +286,24 @@ discard block |
||
| 285 | 286 | |
| 286 | 287 | $class = ""; |
| 287 | 288 | |
| 288 | - if (!empty($this->basePath)) |
|
| 289 | - $class .= $this->basePath .'/'; |
|
| 289 | + if (!empty($this->basePath)) { |
|
| 290 | + $class .= $this->basePath .'/'; |
|
| 291 | + } |
|
| 290 | 292 | |
| 291 | - if (!empty($this->modulePath)) |
|
| 292 | - $class .= $this->modulePath .'/'; |
|
| 293 | + if (!empty($this->modulePath)) { |
|
| 294 | + $class .= $this->modulePath .'/'; |
|
| 295 | + } |
|
| 293 | 296 | |
| 294 | 297 | $class .= $module ."/"; |
| 295 | 298 | |
| 296 | - if (!empty($this->classPath)) |
|
| 297 | - $class .= $this->classPath .'/'; |
|
| 299 | + if (!empty($this->classPath)) { |
|
| 300 | + $class .= $this->classPath .'/'; |
|
| 301 | + } |
|
| 298 | 302 | |
| 299 | 303 | $class .= implode("/", $nm) . ".php"; |
| 300 | 304 | |
| 301 | - if (file_exists($class)) |
|
| 302 | - include $class; |
|
| 305 | + if (file_exists($class)) { |
|
| 306 | + include $class; |
|
| 307 | + } |
|
| 303 | 308 | } |
| 304 | 309 | } |
| 305 | 310 | \ No newline at end of file |
@@ -93,9 +93,9 @@ |
||
| 93 | 93 | |
| 94 | 94 | if ($controller->getShowView()) |
| 95 | 95 | $this->view = |
| 96 | - $controller->getModule()->getModulePath() .'/'. $controller->getModule()->getModuleName() .'/'. |
|
| 97 | - $controller->getModule()->getViewPath() .'/'. |
|
| 98 | - basename(str_replace('\\','/',get_class($controller))) .'/'. |
|
| 96 | + $controller->getModule()->getModulePath() . '/' . $controller->getModule()->getModuleName() . '/' . |
|
| 97 | + $controller->getModule()->getViewPath() . '/' . |
|
| 98 | + basename(str_replace('\\', '/', get_class($controller))) . '/' . |
|
| 99 | 99 | $controller->getMethod() . '.phtml'; |
| 100 | 100 | |
| 101 | 101 | if ($controller->getTerminal()) |
@@ -68,8 +68,9 @@ discard block |
||
| 68 | 68 | { |
| 69 | 69 | $config = $module->getConfig(); |
| 70 | 70 | |
| 71 | - if (!array_key_exists($view, $config["view_manager"]["view_map"]) || !file_exists($config["view_manager"]["view_map"][$view])) |
|
| 72 | - throw new Exception\ViewNotFoundException("The 'view' template " . $view . " does not exists"); |
|
| 71 | + if (!array_key_exists($view, $config["view_manager"]["view_map"]) || !file_exists($config["view_manager"]["view_map"][$view])) { |
|
| 72 | + throw new Exception\ViewNotFoundException("The 'view' template " . $view . " does not exists"); |
|
| 73 | + } |
|
| 73 | 74 | |
| 74 | 75 | $this->view = $config["view_manager"]["view_map"][$view]; |
| 75 | 76 | } |
@@ -88,36 +89,41 @@ discard block |
||
| 88 | 89 | $this->setParams($controller->getParams()); |
| 89 | 90 | $this->controller = $controller; |
| 90 | 91 | |
| 91 | - if (is_null($controller->getModule())) |
|
| 92 | - throw new \RuntimeException("No module instance found in controller '" . get_class($controller) . "'"); |
|
| 92 | + if (is_null($controller->getModule())) { |
|
| 93 | + throw new \RuntimeException("No module instance found in controller '" . get_class($controller) . "'"); |
|
| 94 | + } |
|
| 93 | 95 | |
| 94 | - if ($controller->getShowView()) |
|
| 95 | - $this->view = |
|
| 96 | + if ($controller->getShowView()) { |
|
| 97 | + $this->view = |
|
| 96 | 98 | $controller->getModule()->getModulePath() .'/'. $controller->getModule()->getModuleName() .'/'. |
| 97 | 99 | $controller->getModule()->getViewPath() .'/'. |
| 98 | 100 | basename(str_replace('\\','/',get_class($controller))) .'/'. |
| 99 | 101 | $controller->getMethod() . '.phtml'; |
| 102 | + } |
|
| 100 | 103 | |
| 101 | 104 | if ($controller->getTerminal()) |
| 102 | 105 | { |
| 103 | - if (file_exists($this->view)) |
|
| 104 | - include $this->view; |
|
| 105 | - } |
|
| 106 | - else |
|
| 106 | + if (file_exists($this->view)) { |
|
| 107 | + include $this->view; |
|
| 108 | + } |
|
| 109 | + } else |
|
| 107 | 110 | { |
| 108 | - if (!is_null($this->view) && !file_exists($this->view)) |
|
| 109 | - throw new Exception\ViewNotFoundException("The 'view' template " . $this->view . " does not exists"); |
|
| 111 | + if (!is_null($this->view) && !file_exists($this->view)) { |
|
| 112 | + throw new Exception\ViewNotFoundException("The 'view' template " . $this->view . " does not exists"); |
|
| 113 | + } |
|
| 110 | 114 | |
| 111 | 115 | $config = $controller->getModule()->getConfig(); |
| 112 | 116 | $layout = $controller->getLayout(); |
| 113 | 117 | |
| 114 | - if (!array_key_exists($controller->getLayout(), $config["view_manager"]["template_map"])) |
|
| 115 | - throw new Exception\PageNotFoundException("The 'template' " . $layout . " was not defined in module.config.php"); |
|
| 118 | + if (!array_key_exists($controller->getLayout(), $config["view_manager"]["template_map"])) { |
|
| 119 | + throw new Exception\PageNotFoundException("The 'template' " . $layout . " was not defined in module.config.php"); |
|
| 120 | + } |
|
| 116 | 121 | |
| 117 | 122 | $template = $config["view_manager"]["template_map"][$controller->getLayout()]; |
| 118 | 123 | |
| 119 | - if (!file_exists($template)) |
|
| 120 | - throw new Exception\PageNotFoundException("The 'template' " . $template . " does not exists"); |
|
| 124 | + if (!file_exists($template)) { |
|
| 125 | + throw new Exception\PageNotFoundException("The 'template' " . $template . " does not exists"); |
|
| 126 | + } |
|
| 121 | 127 | |
| 122 | 128 | include $template; |
| 123 | 129 | } |
@@ -146,8 +152,9 @@ discard block |
||
| 146 | 152 | */ |
| 147 | 153 | public function content() |
| 148 | 154 | { |
| 149 | - if (!file_exists($this->view)) |
|
| 150 | - throw new Exception\ViewNotFoundException("The 'view' template " . $this->view . " does not exists"); |
|
| 155 | + if (!file_exists($this->view)) { |
|
| 156 | + throw new Exception\ViewNotFoundException("The 'view' template " . $this->view . " does not exists"); |
|
| 157 | + } |
|
| 151 | 158 | |
| 152 | 159 | include $this->view; |
| 153 | 160 | } |
@@ -83,8 +83,9 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | public function getController() |
| 85 | 85 | { |
| 86 | - if (is_null($this->controller)) |
|
| 87 | - throw new \RuntimeException("No controller matched, try to match first."); |
|
| 86 | + if (is_null($this->controller)) { |
|
| 87 | + throw new \RuntimeException("No controller matched, try to match first."); |
|
| 88 | + } |
|
| 88 | 89 | |
| 89 | 90 | return $this->controller; |
| 90 | 91 | } |
@@ -172,8 +173,9 @@ discard block |
||
| 172 | 173 | */ |
| 173 | 174 | public function match() |
| 174 | 175 | { |
| 175 | - if (!is_callable($this->classNameBuilder)) |
|
| 176 | - throw \LogicException("No class name builder found"); |
|
| 176 | + if (!is_callable($this->classNameBuilder)) { |
|
| 177 | + throw \LogicException("No class name builder found"); |
|
| 178 | + } |
|
| 177 | 179 | |
| 178 | 180 | /* |
| 179 | 181 | * Key value pairs builder: |
@@ -195,8 +197,9 @@ discard block |
||
| 195 | 197 | $module = (is_null($this->identifiers["module"]) || empty($this->identifiers["module"])) |
| 196 | 198 | ? $this->routes["defaults"]["module"] : $this->identifiers["module"]; |
| 197 | 199 | |
| 198 | - if (!array_key_exists($module, $this->routes)) |
|
| 199 | - throw new Exception\ModuleNotFoundException("The key '$module' does not exists in routes!"); |
|
| 200 | + if (!array_key_exists($module, $this->routes)) { |
|
| 201 | + throw new Exception\ModuleNotFoundException("The key '$module' does not exists in routes!"); |
|
| 202 | + } |
|
| 200 | 203 | |
| 201 | 204 | $controller = (is_null($this->identifiers["controller"]) || empty($this->identifiers["controller"])) |
| 202 | 205 | ? $this->routes[$module]["controller"] : $this->identifiers["controller"]; |
@@ -216,17 +219,16 @@ discard block |
||
| 216 | 219 | catch (Exception\MethodNotFoundException $e) |
| 217 | 220 | { |
| 218 | 221 | throw new Exception\PageNotFoundException($e->getMessage(), $e->getCode(), $e); |
| 219 | - } |
|
| 220 | - catch (Exception\PrivateMethodExecutionException $e) |
|
| 222 | + } catch (Exception\PrivateMethodExecutionException $e) |
|
| 221 | 223 | { |
| 222 | 224 | throw new Exception\PageNotFoundException($e->getMessage(), $e->getCode(), $e); |
| 223 | 225 | } |
| 224 | 226 | |
| 225 | 227 | # in controller terms, a view is a method |
| 226 | 228 | $this->controller->setMethod($view); |
| 229 | + } else { |
|
| 230 | + throw new Exception\ControllerNotFoundException("The control class '$fqn_controller' does not exists!"); |
|
| 227 | 231 | } |
| 228 | - else |
|
| 229 | - throw new Exception\ControllerNotFoundException("The control class '$fqn_controller' does not exists!"); |
|
| 230 | 232 | } |
| 231 | 233 | |
| 232 | 234 | /** |
@@ -253,8 +255,9 @@ discard block |
||
| 253 | 255 | $key = array_keys($route); |
| 254 | 256 | $key = array_shift($key); |
| 255 | 257 | |
| 256 | - if (array_key_exists($key, $this->routes)) |
|
| 257 | - throw new \LogicException("The key '$key' was already defined as route"); |
|
| 258 | + if (array_key_exists($key, $this->routes)) { |
|
| 259 | + throw new \LogicException("The key '$key' was already defined as route"); |
|
| 260 | + } |
|
| 258 | 261 | |
| 259 | 262 | $this->routes = array_merge($this->routes, $route); |
| 260 | 263 | } |
@@ -295,10 +298,11 @@ discard block |
||
| 295 | 298 | $i = 1; |
| 296 | 299 | foreach ($params as $item) |
| 297 | 300 | { |
| 298 | - if ($i % 2 != 0) |
|
| 299 | - $vars[] = $item; |
|
| 300 | - else |
|
| 301 | - $values[] = $item; |
|
| 301 | + if ($i % 2 != 0) { |
|
| 302 | + $vars[] = $item; |
|
| 303 | + } else { |
|
| 304 | + $values[] = $item; |
|
| 305 | + } |
|
| 302 | 306 | $i++; |
| 303 | 307 | } |
| 304 | 308 | |
@@ -308,10 +312,11 @@ discard block |
||
| 308 | 312 | |
| 309 | 313 | for ($i = 0; $i < $vars_count; $i++) |
| 310 | 314 | { |
| 311 | - if (array_key_exists($i, $values)) |
|
| 312 | - $result[$vars[$i]] = $values[$i]; |
|
| 313 | - else |
|
| 314 | - $result[$vars[$i]] = ''; |
|
| 315 | + if (array_key_exists($i, $values)) { |
|
| 316 | + $result[$vars[$i]] = $values[$i]; |
|
| 317 | + } else { |
|
| 318 | + $result[$vars[$i]] = ''; |
|
| 319 | + } |
|
| 315 | 320 | } |
| 316 | 321 | |
| 317 | 322 | return $result; |
@@ -175,13 +175,14 @@ discard block |
||
| 175 | 175 | { |
| 176 | 176 | $method = $this->method; |
| 177 | 177 | |
| 178 | - if (is_null($method)) |
|
| 179 | - # This error is thrown because of 'setMethod' method has not been executed |
|
| 178 | + if (is_null($method)) { |
|
| 179 | + # This error is thrown because of 'setMethod' method has not been executed |
|
| 180 | 180 | throw new \LogicException("No method has been setted to execute!"); |
| 181 | + } |
|
| 181 | 182 | |
| 182 | - if (!is_null($this->module) && !$this->module->executionIsAllowed()) |
|
| 183 | - throw new Exception\MethodExecutionNotAllowedException("Method execution is not allowed"); |
|
| 184 | - else |
|
| 183 | + if (!is_null($this->module) && !$this->module->executionIsAllowed()) { |
|
| 184 | + throw new Exception\MethodExecutionNotAllowedException("Method execution is not allowed"); |
|
| 185 | + } else |
|
| 185 | 186 | { |
| 186 | 187 | if (method_exists($this, $method)) |
| 187 | 188 | { |
@@ -189,8 +190,9 @@ discard block |
||
| 189 | 190 | |
| 190 | 191 | $reflection = new \ReflectionMethod($this, $method); |
| 191 | 192 | |
| 192 | - if (!$reflection->isPublic()) |
|
| 193 | - throw new Exception\PrivateMethodExecutionException("The method '$method' is not public in the control class '$class'"); |
|
| 193 | + if (!$reflection->isPublic()) { |
|
| 194 | + throw new Exception\PrivateMethodExecutionException("The method '$method' is not public in the control class '$class'"); |
|
| 195 | + } |
|
| 194 | 196 | |
| 195 | 197 | # Get the returned value of the method to send to the view |
| 196 | 198 | $this->params = $this->$method(); |
@@ -206,8 +208,7 @@ discard block |
||
| 206 | 208 | $layout->setParams($layout_params); |
| 207 | 209 | $layout->fromController($this); |
| 208 | 210 | } |
| 209 | - } |
|
| 210 | - else |
|
| 211 | + } else |
|
| 211 | 212 | { |
| 212 | 213 | $class = __CLASS__; |
| 213 | 214 | throw new Exception\MethodNotFoundException("The method '$method' doesn't exists in the control class '$class'"); |
@@ -232,8 +233,9 @@ discard block |
||
| 232 | 233 | */ |
| 233 | 234 | public function getPost() |
| 234 | 235 | { |
| 235 | - if ($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST)) |
|
| 236 | - $_POST = json_decode(file_get_contents('php://input'), true); |
|
| 236 | + if ($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST)) { |
|
| 237 | + $_POST = json_decode(file_get_contents('php://input'), true); |
|
| 238 | + } |
|
| 237 | 239 | |
| 238 | 240 | return (array) $_POST; |
| 239 | 241 | } |
@@ -247,8 +249,9 @@ discard block |
||
| 247 | 249 | */ |
| 248 | 250 | public function getJson() |
| 249 | 251 | { |
| 250 | - if ($_SERVER['REQUEST_METHOD'] != 'JSON') |
|
| 251 | - throw new \LogicException("Request method is not JSON"); |
|
| 252 | + if ($_SERVER['REQUEST_METHOD'] != 'JSON') { |
|
| 253 | + throw new \LogicException("Request method is not JSON"); |
|
| 254 | + } |
|
| 252 | 255 | |
| 253 | 256 | $input = file_get_contents('php://input'); |
| 254 | 257 | $array = explode("&", $input); |
@@ -272,8 +275,9 @@ discard block |
||
| 272 | 275 | public function isXmlHttpRequest() |
| 273 | 276 | { |
| 274 | 277 | # non standard (HTTP_X_REQUESTED_WITH is not a part of PHP) |
| 275 | - if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) |
|
| 276 | - return true; |
|
| 278 | + if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) { |
|
| 279 | + return true; |
|
| 280 | + } |
|
| 277 | 281 | return false; |
| 278 | 282 | } |
| 279 | 283 | |
@@ -284,8 +288,9 @@ discard block |
||
| 284 | 288 | */ |
| 285 | 289 | public function isPost() |
| 286 | 290 | { |
| 287 | - if ($_SERVER["REQUEST_METHOD"] == "POST") |
|
| 288 | - return true; |
|
| 291 | + if ($_SERVER["REQUEST_METHOD"] == "POST") { |
|
| 292 | + return true; |
|
| 293 | + } |
|
| 289 | 294 | return false; |
| 290 | 295 | } |
| 291 | 296 | |
@@ -296,8 +301,9 @@ discard block |
||
| 296 | 301 | */ |
| 297 | 302 | public function isGet() |
| 298 | 303 | { |
| 299 | - if ($_SERVER["REQUEST_METHOD"] == "GET") |
|
| 300 | - return true; |
|
| 304 | + if ($_SERVER["REQUEST_METHOD"] == "GET") { |
|
| 305 | + return true; |
|
| 306 | + } |
|
| 301 | 307 | return false; |
| 302 | 308 | } |
| 303 | 309 | } |
| 304 | 310 | \ No newline at end of file |
@@ -92,19 +92,23 @@ discard block |
||
| 92 | 92 | public function __construct(Array $config) |
| 93 | 93 | { |
| 94 | 94 | # start sessions |
| 95 | - if (!isset($_SESSION)) |
|
| 96 | - session_start(); |
|
| 95 | + if (!isset($_SESSION)) { |
|
| 96 | + session_start(); |
|
| 97 | + } |
|
| 97 | 98 | |
| 98 | - if (!array_key_exists('environment', $config)) |
|
| 99 | - throw new \InvalidArgumentException("The 'environment' key was not defined"); |
|
| 99 | + if (!array_key_exists('environment', $config)) { |
|
| 100 | + throw new \InvalidArgumentException("The 'environment' key was not defined"); |
|
| 101 | + } |
|
| 100 | 102 | |
| 101 | - if (!array_key_exists('dev_mode', $config['environment'])) |
|
| 102 | - throw new \InvalidArgumentException("The 'dev_mode' key was not defined"); |
|
| 103 | + if (!array_key_exists('dev_mode', $config['environment'])) { |
|
| 104 | + throw new \InvalidArgumentException("The 'dev_mode' key was not defined"); |
|
| 105 | + } |
|
| 103 | 106 | |
| 104 | 107 | $this->devMode = $config["environment"]["dev_mode"]; |
| 105 | 108 | |
| 106 | - if (!array_key_exists('modules', $config)) |
|
| 107 | - throw new \InvalidArgumentException("The 'modules' key was not defined"); |
|
| 109 | + if (!array_key_exists('modules', $config)) { |
|
| 110 | + throw new \InvalidArgumentException("The 'modules' key was not defined"); |
|
| 111 | + } |
|
| 108 | 112 | |
| 109 | 113 | $this->modules = $config["modules"]; |
| 110 | 114 | |
@@ -118,8 +122,7 @@ discard block |
||
| 118 | 122 | { |
| 119 | 123 | ini_set('display_errors', 1); |
| 120 | 124 | error_reporting(-1); |
| 121 | - } |
|
| 122 | - else |
|
| 125 | + } else |
|
| 123 | 126 | { |
| 124 | 127 | ini_set('display_errors', 0); |
| 125 | 128 | error_reporting(0); |
@@ -128,26 +131,30 @@ discard block |
||
| 128 | 131 | # register autoloading functions for each module |
| 129 | 132 | $this->autoload($this->modules); |
| 130 | 133 | |
| 131 | - if (!array_key_exists('router', $config)) |
|
| 132 | - throw new \InvalidArgumentException("The 'router' key was not defined"); |
|
| 134 | + if (!array_key_exists('router', $config)) { |
|
| 135 | + throw new \InvalidArgumentException("The 'router' key was not defined"); |
|
| 136 | + } |
|
| 133 | 137 | |
| 134 | - if (!array_key_exists('routes', $config["router"])) |
|
| 135 | - throw new \InvalidArgumentException("The 'routes' key was not defined"); |
|
| 138 | + if (!array_key_exists('routes', $config["router"])) { |
|
| 139 | + throw new \InvalidArgumentException("The 'routes' key was not defined"); |
|
| 140 | + } |
|
| 136 | 141 | |
| 137 | 142 | $this->router = new Router($config["router"]["routes"]); |
| 138 | 143 | |
| 139 | - if (!array_key_exists('base_path', $config['environment'])) |
|
| 140 | - throw new \InvalidArgumentException("The 'base_path' key was not defined"); |
|
| 144 | + if (!array_key_exists('base_path', $config['environment'])) { |
|
| 145 | + throw new \InvalidArgumentException("The 'base_path' key was not defined"); |
|
| 146 | + } |
|
| 141 | 147 | |
| 142 | 148 | $this->router->setBasePath($config["environment"]["base_path"]); |
| 143 | 149 | |
| 144 | 150 | # load routes from config |
| 145 | 151 | foreach ($config["router"]["routes"] as $name => $route) |
| 146 | 152 | { |
| 147 | - if ($route instanceof \Zend\Router\Http\RouteInterface) |
|
| 148 | - $this->getRouter()->addZendRoute($name, $route); |
|
| 149 | - else |
|
| 150 | - $this->getRouter()->addRoute($route); |
|
| 153 | + if ($route instanceof \Zend\Router\Http\RouteInterface) { |
|
| 154 | + $this->getRouter()->addZendRoute($name, $route); |
|
| 155 | + } else { |
|
| 156 | + $this->getRouter()->addRoute($route); |
|
| 157 | + } |
|
| 151 | 158 | } |
| 152 | 159 | |
| 153 | 160 | # load routes from each module |
@@ -157,11 +164,13 @@ discard block |
||
| 157 | 164 | { |
| 158 | 165 | $module_config_file = require($this->modulePath . "/$module/config/module.config.php"); |
| 159 | 166 | |
| 160 | - if (!array_key_exists('router', $module_config_file)) |
|
| 161 | - throw new \RuntimeException("The 'router' key was not defined in the config file for module '$module'"); |
|
| 167 | + if (!array_key_exists('router', $module_config_file)) { |
|
| 168 | + throw new \RuntimeException("The 'router' key was not defined in the config file for module '$module'"); |
|
| 169 | + } |
|
| 162 | 170 | |
| 163 | - if (!array_key_exists('routes', $module_config_file["router"])) |
|
| 164 | - throw new \RuntimeException("The 'routes' key was not defined in the config file for module '$module'"); |
|
| 171 | + if (!array_key_exists('routes', $module_config_file["router"])) { |
|
| 172 | + throw new \RuntimeException("The 'routes' key was not defined in the config file for module '$module'"); |
|
| 173 | + } |
|
| 165 | 174 | |
| 166 | 175 | $this->getRouter()->addRoute($module_config_file["router"]["routes"]); |
| 167 | 176 | } |
@@ -190,14 +199,15 @@ discard block |
||
| 190 | 199 | * This instruction includes each module declared. |
| 191 | 200 | * Each module has an autoloader to load its classes (controllers and models) |
| 192 | 201 | */ |
| 193 | - if (file_exists($this->modulePath ."/". $module."/Module.php")) |
|
| 194 | - include($this->modulePath ."/". $module."/Module.php"); |
|
| 202 | + if (file_exists($this->modulePath ."/". $module."/Module.php")) { |
|
| 203 | + include($this->modulePath ."/". $module."/Module.php"); |
|
| 204 | + } |
|
| 195 | 205 | |
| 196 | 206 | spl_autoload_register($module . "\Module::loader"); |
| 197 | 207 | } |
| 208 | + } else { |
|
| 209 | + throw new \RuntimeException("The application must have at least one module"); |
|
| 198 | 210 | } |
| 199 | - else |
|
| 200 | - throw new \RuntimeException("The application must have at least one module"); |
|
| 201 | 211 | } |
| 202 | 212 | |
| 203 | 213 | /** |
@@ -219,8 +229,9 @@ discard block |
||
| 219 | 229 | $uri .= !empty($controller) ? '/' . $controller : ""; |
| 220 | 230 | $uri .= !empty($view) ? '/' . $view : ""; |
| 221 | 231 | |
| 222 | - if (empty($uri)) |
|
| 223 | - $uri = "/"; |
|
| 232 | + if (empty($uri)) { |
|
| 233 | + $uri = "/"; |
|
| 234 | + } |
|
| 224 | 235 | |
| 225 | 236 | $request->setUri($uri); |
| 226 | 237 | |
@@ -236,9 +247,9 @@ discard block |
||
| 236 | 247 | $view = $params["action"]; |
| 237 | 248 | |
| 238 | 249 | $this->router->setIdentifiers($module, $controller, $view); |
| 250 | + } else { |
|
| 251 | + $this->router->setIdentifiers($module, $controller, $view); |
|
| 239 | 252 | } |
| 240 | - else |
|
| 241 | - $this->router->setIdentifiers($module, $controller, $view); |
|
| 242 | 253 | |
| 243 | 254 | $this->router->match(); |
| 244 | 255 | |
@@ -249,7 +260,8 @@ discard block |
||
| 249 | 260 | "config" => 'config/module.config.php' |
| 250 | 261 | ])); |
| 251 | 262 | |
| 252 | - if ($this->getController()->getModule()->executionIsAllowed()) |
|
| 253 | - $this->router->run(); |
|
| 263 | + if ($this->getController()->getModule()->executionIsAllowed()) { |
|
| 264 | + $this->router->run(); |
|
| 265 | + } |
|
| 254 | 266 | } |
| 255 | 267 | } |
| 256 | 268 | \ No newline at end of file |