| @@ -29,8 +29,8 @@ discard block | ||
| 29 | 29 | $ht = $this->http; | 
| 30 | 30 | |
| 31 | 31 | $this->http->writeStatus($ht::HTTP_UNAUTHORIZED); | 
| 32 | -            header('WWW-Authenticate: Basic realm="'.$this->realm.'"'); | |
| 33 | -            die('Error ' . $ht::HTTP_UNAUTHORIZED .' (' . $this->http->getStatusText($ht::HTTP_UNAUTHORIZED) . ')!!'); | |
| 32 | +            header('WWW-Authenticate: Basic realm="' . $this->realm . '"'); | |
| 33 | +            die('Error ' . $ht::HTTP_UNAUTHORIZED . ' (' . $this->http->getStatusText($ht::HTTP_UNAUTHORIZED) . ')!!'); | |
| 34 | 34 | } | 
| 35 | 35 | } | 
| 36 | 36 | |
| @@ -76,7 +76,7 @@ discard block | ||
| 76 | 76 | public function response() | 
| 77 | 77 |      { | 
| 78 | 78 | $status = http_response_code(); | 
| 79 | -        $this->response = 'Error ' . $status .' (' . $this->http->getStatusText($status) . ')!!'; | |
| 79 | +        $this->response = 'Error ' . $status . ' (' . $this->http->getStatusText($status) . ')!!'; | |
| 80 | 80 | echo $this->response; | 
| 81 | 81 | } | 
| 82 | 82 | } | 
| 83 | 83 | \ No newline at end of file | 
| @@ -29,8 +29,8 @@ discard block | ||
| 29 | 29 | $ht = $this->http; | 
| 30 | 30 | |
| 31 | 31 | $this->http->writeStatus($ht::HTTP_UNAUTHORIZED); | 
| 32 | -            header('WWW-Authenticate: Digest realm="'.$this->realm.'",qop="auth",nonce="'.uniqid().'",opaque="'.md5($this->realm).'"'); | |
| 33 | -            die('Error ' . $ht::HTTP_UNAUTHORIZED .' (' . $this->http->getStatusText($ht::HTTP_UNAUTHORIZED) . ')!!'); | |
| 32 | +            header('WWW-Authenticate: Digest realm="' . $this->realm . '",qop="auth",nonce="' . uniqid() . '",opaque="' . md5($this->realm) . '"'); | |
| 33 | +            die('Error ' . $ht::HTTP_UNAUTHORIZED . ' (' . $this->http->getStatusText($ht::HTTP_UNAUTHORIZED) . ')!!'); | |
| 34 | 34 | } | 
| 35 | 35 | } | 
| 36 | 36 | |
| @@ -50,8 +50,8 @@ discard block | ||
| 50 | 50 | } | 
| 51 | 51 | |
| 52 | 52 | $A1 = md5($data['username'] . ':' . $this->realm . ':' . $this->whiteList[$data['username']]); | 
| 53 | - $A2 = md5($_SERVER['REQUEST_METHOD'].':'.$data['uri']); | |
| 54 | - $valid_response = md5($A1.':'.$data['nonce'].':'.$data['nc'].':'.$data['cnonce'].':'.$data['qop'].':'.$A2); | |
| 53 | + $A2 = md5($_SERVER['REQUEST_METHOD'] . ':' . $data['uri']); | |
| 54 | + $valid_response = md5($A1 . ':' . $data['nonce'] . ':' . $data['nc'] . ':' . $data['cnonce'] . ':' . $data['qop'] . ':' . $A2); | |
| 55 | 55 | |
| 56 | 56 | if ($data['response'] != $valid_response) | 
| 57 | 57 |          { | 
| @@ -97,7 +97,7 @@ discard block | ||
| 97 | 97 | public function response() | 
| 98 | 98 |      { | 
| 99 | 99 | $status = http_response_code(); | 
| 100 | -        $this->response = 'Error ' . $status .' (' . $this->http->getStatusText($status) . ')!!'; | |
| 100 | +        $this->response = 'Error ' . $status . ' (' . $this->http->getStatusText($status) . ')!!'; | |
| 101 | 101 | echo $this->response; | 
| 102 | 102 | } | 
| 103 | 103 | } | 
| 104 | 104 | \ No newline at end of file | 
| @@ -156,8 +156,8 @@ | ||
| 156 | 156 |      { | 
| 157 | 157 | foreach ($options as $option => $value) | 
| 158 | 158 |          { | 
| 159 | - if (property_exists(__CLASS__, strtolower($option)) && method_exists($this, 'set'.$option)) | |
| 160 | -            $this->{'set'.$option}($value); | |
| 159 | + if (property_exists(__CLASS__, strtolower($option)) && method_exists($this, 'set' . $option)) | |
| 160 | +            $this->{'set' . $option}($value); | |
| 161 | 161 | } | 
| 162 | 162 | |
| 163 | 163 | # HTTP instance | 
| @@ -127,8 +127,9 @@ discard block | ||
| 127 | 127 | */ | 
| 128 | 128 | public function setWhiteList(array $whiteList) | 
| 129 | 129 |      { | 
| 130 | - if (empty($whiteList)) | |
| 131 | -            throw new \RuntimeException("Empty whitelist!"); | |
| 130 | +        if (empty($whiteList)) { | |
| 131 | +                    throw new \RuntimeException("Empty whitelist!"); | |
| 132 | + } | |
| 132 | 133 | |
| 133 | 134 | $this->whiteList = $whiteList; | 
| 134 | 135 | } | 
| @@ -156,8 +157,9 @@ discard block | ||
| 156 | 157 |      { | 
| 157 | 158 | foreach ($options as $option => $value) | 
| 158 | 159 |          { | 
| 159 | - if (property_exists(__CLASS__, strtolower($option)) && method_exists($this, 'set'.$option)) | |
| 160 | -            $this->{'set'.$option}($value); | |
| 160 | +            if (property_exists(__CLASS__, strtolower($option)) && method_exists($this, 'set'.$option)) { | |
| 161 | +                        $this->{'set'.$option}($value); | |
| 162 | + } | |
| 161 | 163 | } | 
| 162 | 164 | |
| 163 | 165 | # HTTP instance | 
| @@ -64,11 +64,13 @@ | ||
| 64 | 64 | */ | 
| 65 | 65 | public static function getClientIP() | 
| 66 | 66 |      { | 
| 67 | - if (!empty($_SERVER['HTTP_CLIENT_IP'])) | |
| 68 | - return $_SERVER['HTTP_CLIENT_IP']; | |
| 67 | +        if (!empty($_SERVER['HTTP_CLIENT_IP'])) { | |
| 68 | + return $_SERVER['HTTP_CLIENT_IP']; | |
| 69 | + } | |
| 69 | 70 | |
| 70 | - if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) | |
| 71 | - return $_SERVER['HTTP_X_FORWARDED_FOR']; | |
| 71 | +        if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { | |
| 72 | + return $_SERVER['HTTP_X_FORWARDED_FOR']; | |
| 73 | + } | |
| 72 | 74 | |
| 73 | 75 | return $_SERVER['REMOTE_ADDR']; | 
| 74 | 76 | } | 
| @@ -131,7 +131,7 @@ | ||
| 131 | 131 | if (\PEAR::isError($mail)) | 
| 132 | 132 |          { | 
| 133 | 133 | $this->error( | 
| 134 | - $mail->getCode(), $mail->getMessage() | |
| 134 | + $mail->getCode(), $mail->getMessage() | |
| 135 | 135 | ); | 
| 136 | 136 | |
| 137 | 137 | return false; | 
| @@ -114,7 +114,7 @@ discard block | ||
| 114 | 114 | */ | 
| 115 | 115 | public function send($from, $to, $subject, $body) | 
| 116 | 116 |      { | 
| 117 | - $headers = array ( | |
| 117 | + $headers = array( | |
| 118 | 118 | 'From' => $from, | 
| 119 | 119 | 'To' => $to, | 
| 120 | 120 | 'Subject' => $subject, | 
| @@ -123,7 +123,7 @@ discard block | ||
| 123 | 123 | |
| 124 | 124 | $smtp = \Mail::factory( | 
| 125 | 125 | 'smtp', | 
| 126 | -            array ('host' => $this->host, 'auth' => false) | |
| 126 | +            array('host' => $this->host, 'auth' => false) | |
| 127 | 127 | ); | 
| 128 | 128 | |
| 129 | 129 | $mail = $smtp->send($to, $headers, $body); | 
| @@ -74,18 +74,21 @@ discard block | ||
| 74 | 74 |      { | 
| 75 | 75 | @include_once 'System.php'; | 
| 76 | 76 | |
| 77 | -        if (!class_exists('System', false)) | |
| 78 | -            throw new \RuntimeException("PEAR is not installed in your system!"); | |
| 77 | +        if (!class_exists('System', false)) { | |
| 78 | +                    throw new \RuntimeException("PEAR is not installed in your system!"); | |
| 79 | + } | |
| 79 | 80 | |
| 80 | 81 | include_once 'Net/SMTP.php'; | 
| 81 | 82 | |
| 82 | -        if (!class_exists('\Net_SMTP', false)) | |
| 83 | -            throw new \RuntimeException("PEAR::Net_SMTP is not installed!"); | |
| 83 | +        if (!class_exists('\Net_SMTP', false)) { | |
| 84 | +                    throw new \RuntimeException("PEAR::Net_SMTP is not installed!"); | |
| 85 | + } | |
| 84 | 86 | |
| 85 | 87 | @include_once 'Mail.php'; | 
| 86 | 88 | |
| 87 | -        if (!class_exists('\Mail', false)) | |
| 88 | -            throw new \RuntimeException("PEAR::Mail is not installed!"); | |
| 89 | +        if (!class_exists('\Mail', false)) { | |
| 90 | +                    throw new \RuntimeException("PEAR::Mail is not installed!"); | |
| 91 | + } | |
| 89 | 92 | } | 
| 90 | 93 | |
| 91 | 94 | /** | 
| @@ -98,8 +101,9 @@ discard block | ||
| 98 | 101 | */ | 
| 99 | 102 | protected function error($code, $message = null) | 
| 100 | 103 |      { | 
| 101 | - if (!array_key_exists($code, $this->errors)) | |
| 102 | - $this->errors[$message] = (is_null($message) && array_key_exists($code, $this->errors)) ? $this->errors[$code] : $message; | |
| 104 | +        if (!array_key_exists($code, $this->errors)) { | |
| 105 | + $this->errors[$message] = (is_null($message) && array_key_exists($code, $this->errors)) ? $this->errors[$code] : $message; | |
| 106 | + } | |
| 103 | 107 | } | 
| 104 | 108 | |
| 105 | 109 | /** | 
| @@ -70,8 +70,9 @@ | ||
| 70 | 70 |      { | 
| 71 | 71 | $parameters = $this->getParams(); | 
| 72 | 72 | |
| 73 | - if (array_key_exists($param, $parameters)) | |
| 74 | - return true; | |
| 73 | +        if (array_key_exists($param, $parameters)) { | |
| 74 | + return true; | |
| 75 | + } | |
| 75 | 76 | |
| 76 | 77 | return false; | 
| 77 | 78 | } | 
| @@ -60,7 +60,7 @@ | ||
| 60 | 60 | |
| 61 | 61 | if (!empty($string)) | 
| 62 | 62 |              { | 
| 63 | - $data = json_decode($string, true); | |
| 63 | + $data = json_decode($string, true); | |
| 64 | 64 | |
| 65 | 65 | # json_encode can return TRUE, FALSE or NULL (http://php.net/manual/en/function.json-decode.php) | 
| 66 | 66 | if (is_null($data) || $data === false) | 
| @@ -76,17 +76,20 @@ | ||
| 76 | 76 | "object" => serialize($exception) | 
| 77 | 77 | ]; | 
| 78 | 78 | |
| 79 | -        if (!function_exists('mb_detect_encoding')) | |
| 80 | -            throw new \RuntimeException("mbstring library is not installed!"); | |
| 79 | +        if (!function_exists('mb_detect_encoding')) { | |
| 80 | +                    throw new \RuntimeException("mbstring library is not installed!"); | |
| 81 | + } | |
| 81 | 82 | |
| 82 | 83 | /* | 
| 83 | 84 | * Encodes to UTF8 all messages. It ensures JSON encoding. | 
| 84 | 85 | */ | 
| 85 | - if (!mb_detect_encoding($data[$id]["message"], 'UTF-8', true)) | |
| 86 | - $data[$id]["message"] = utf8_encode($data[$id]["message"]); | |
| 86 | +        if (!mb_detect_encoding($data[$id]["message"], 'UTF-8', true)) { | |
| 87 | + $data[$id]["message"] = utf8_encode($data[$id]["message"]); | |
| 88 | + } | |
| 87 | 89 | |
| 88 | - if (!mb_detect_encoding($data[$id]["object"], 'UTF-8', true)) | |
| 89 | - $data[$id]["object"] = utf8_decode($data[$id]["object"]); | |
| 90 | +        if (!mb_detect_encoding($data[$id]["object"], 'UTF-8', true)) { | |
| 91 | + $data[$id]["object"] = utf8_decode($data[$id]["object"]); | |
| 92 | + } | |
| 90 | 93 | |
| 91 | 94 | if (($encoded_data = json_encode($data)) === false) | 
| 92 | 95 |          { | 
| @@ -145,8 +145,9 @@ discard block | ||
| 145 | 145 | $module = (is_null($this->identifiers["module"]) || empty($this->identifiers["module"])) | 
| 146 | 146 | ? $this->routes["defaults"]["module"] : $this->identifiers["module"]; | 
| 147 | 147 | |
| 148 | - if (!array_key_exists($module, $this->routes)) | |
| 149 | -            throw new Exception\ModuleNotFoundException("The key '$module' does not exists in routes!"); | |
| 148 | +        if (!array_key_exists($module, $this->routes)) { | |
| 149 | +                    throw new Exception\ModuleNotFoundException("The key '$module' does not exists in routes!"); | |
| 150 | + } | |
| 150 | 151 | |
| 151 | 152 | $controller = (is_null($this->identifiers["controller"]) || empty($this->identifiers["controller"])) | 
| 152 | 153 | ? $this->routes[$module]["controller"] : $this->identifiers["controller"]; | 
| @@ -156,10 +157,11 @@ discard block | ||
| 156 | 157 | |
| 157 | 158 | $fqn_controller = '\\' . $module . "\Controller\\" . $controller; | 
| 158 | 159 | |
| 159 | - if (class_exists($fqn_controller)) | |
| 160 | - $this->controller = new $fqn_controller($module, $view, $this->basePath); | |
| 161 | - else | |
| 162 | -            throw new Exception\ControllerNotFoundException("The control class '$fqn_controller' does not exists!"); | |
| 160 | +        if (class_exists($fqn_controller)) { | |
| 161 | + $this->controller = new $fqn_controller($module, $view, $this->basePath); | |
| 162 | +        } else { | |
| 163 | +                    throw new Exception\ControllerNotFoundException("The control class '$fqn_controller' does not exists!"); | |
| 164 | + } | |
| 163 | 165 | } | 
| 164 | 166 | |
| 165 | 167 | /** | 
| @@ -176,8 +178,9 @@ discard block | ||
| 176 | 178 | $key = array_keys($route); | 
| 177 | 179 | $key = array_shift($key); | 
| 178 | 180 | |
| 179 | - if (array_key_exists($key, $this->routes)) | |
| 180 | -            throw new \LogicException("The key '$key' was already defined as route"); | |
| 181 | +        if (array_key_exists($key, $this->routes)) { | |
| 182 | +                    throw new \LogicException("The key '$key' was already defined as route"); | |
| 183 | + } | |
| 181 | 184 | |
| 182 | 185 | $this->routes = array_merge($this->routes, $route); | 
| 183 | 186 | } | 
| @@ -132,8 +132,8 @@ | ||
| 132 | 132 | * This instruction include each module declared in application.config.php | 
| 133 | 133 | * Each module has an autoloader to load its classes (controllers and models) | 
| 134 | 134 | */ | 
| 135 | -                if (file_exists("module/".$module."/Module.php")) | |
| 136 | -                    include("module/".$module."/Module.php"); | |
| 135 | +                if (file_exists("module/" . $module . "/Module.php")) | |
| 136 | +                    include("module/" . $module . "/Module.php"); | |
| 137 | 137 | |
| 138 | 138 | spl_autoload_register($module . "\Module::loader"); | 
| 139 | 139 | } | 
| @@ -58,8 +58,9 @@ discard block | ||
| 58 | 58 | public function prepare() | 
| 59 | 59 |      { | 
| 60 | 60 | # start sessions | 
| 61 | - if (!isset($_SESSION)) | |
| 62 | - session_start(); | |
| 61 | +        if (!isset($_SESSION)) { | |
| 62 | + session_start(); | |
| 63 | + } | |
| 63 | 64 | } | 
| 64 | 65 | |
| 65 | 66 | /** | 
| @@ -91,8 +92,7 @@ discard block | ||
| 91 | 92 | |
| 92 | 93 | // Best way to view all possible errors | 
| 93 | 94 | error_reporting(-1); | 
| 94 | - } | |
| 95 | -        else { | |
| 95 | +        } else { | |
| 96 | 96 |              ini_set('display_errors', 0); | 
| 97 | 97 | error_reporting(-1); | 
| 98 | 98 | } | 
| @@ -109,10 +109,11 @@ discard block | ||
| 109 | 109 | |
| 110 | 110 | foreach ($app_config_file["router"]["routes"] as $name => $route) | 
| 111 | 111 |              { | 
| 112 | - if ($route instanceof \Zend\Router\Http\RouteInterface) | |
| 113 | - $this->getRouter()->addZendRoute($name, $route); | |
| 114 | - else | |
| 115 | - $this->getRouter()->addRoute($route); | |
| 112 | +                if ($route instanceof \Zend\Router\Http\RouteInterface) { | |
| 113 | + $this->getRouter()->addZendRoute($name, $route); | |
| 114 | +                } else { | |
| 115 | + $this->getRouter()->addRoute($route); | |
| 116 | + } | |
| 116 | 117 | } | 
| 117 | 118 | } | 
| 118 | 119 | |
| @@ -146,14 +147,15 @@ discard block | ||
| 146 | 147 | * This instruction include each module declared in application.config.php | 
| 147 | 148 | * Each module has an autoloader to load its classes (controllers and models) | 
| 148 | 149 | */ | 
| 149 | -                if (file_exists("module/".$module."/Module.php")) | |
| 150 | -                    include("module/".$module."/Module.php"); | |
| 150 | +                if (file_exists("module/".$module."/Module.php")) { | |
| 151 | +                                    include("module/".$module."/Module.php"); | |
| 152 | + } | |
| 151 | 153 | |
| 152 | 154 | spl_autoload_register($module . "\Module::loader"); | 
| 153 | 155 | } | 
| 156 | +        } else { | |
| 157 | +                    throw new \RuntimeException("The application must have at least one module"); | |
| 154 | 158 | } | 
| 155 | - else | |
| 156 | -            throw new \RuntimeException("The application must have at least one module"); | |
| 157 | 159 | } | 
| 158 | 160 | |
| 159 | 161 | /** | 
| @@ -175,8 +177,9 @@ discard block | ||
| 175 | 177 | $uri .= !empty($controller) ? '/' . $controller : ""; | 
| 176 | 178 | $uri .= !empty($view) ? '/' . $view : ""; | 
| 177 | 179 | |
| 178 | - if (empty($uri)) | |
| 179 | - $uri = "/"; | |
| 180 | +        if (empty($uri)) { | |
| 181 | + $uri = "/"; | |
| 182 | + } | |
| 180 | 183 | |
| 181 | 184 | $request->setUri($uri); | 
| 182 | 185 | |
| @@ -191,9 +194,9 @@ discard block | ||
| 191 | 194 | $view = $params["action"]; | 
| 192 | 195 | |
| 193 | 196 | $this->router->setIdentifiers($module, $controller, $view); | 
| 197 | +        } else { | |
| 198 | + $this->router->setIdentifiers($module, $controller, $view); | |
| 194 | 199 | } | 
| 195 | - else | |
| 196 | - $this->router->setIdentifiers($module, $controller, $view); | |
| 197 | 200 | |
| 198 | 201 | $this->router->run(); | 
| 199 | 202 | } |