@@ -33,15 +33,17 @@ discard block |
||
| 33 | 33 | { |
| 34 | 34 | $this->driverName = 'Oci8'; |
| 35 | 35 | |
| 36 | - if (!array_key_exists("dbchar", $options)) |
|
| 37 | - $options["dbchar"] = "AL32UTF8"; |
|
| 36 | + if (!array_key_exists("dbchar", $options)) { |
|
| 37 | + $options["dbchar"] = "AL32UTF8"; |
|
| 38 | + } |
|
| 38 | 39 | |
| 39 | 40 | parent::__construct($options); |
| 40 | 41 | |
| 41 | 42 | $auto_connect = array_key_exists('auto_connect', $options) ? $options["auto_connect"] : true; |
| 42 | 43 | |
| 43 | - if ($auto_connect) |
|
| 44 | - $this->connect(); |
|
| 44 | + if ($auto_connect) { |
|
| 45 | + $this->connect(); |
|
| 46 | + } |
|
| 45 | 47 | } |
| 46 | 48 | |
| 47 | 49 | /** |
@@ -54,8 +56,9 @@ discard block |
||
| 54 | 56 | */ |
| 55 | 57 | public function connect() |
| 56 | 58 | { |
| 57 | - if (!extension_loaded('oci8')) |
|
| 58 | - throw new \RuntimeException("The Oci8 extension is not loaded"); |
|
| 59 | + if (!extension_loaded('oci8')) { |
|
| 60 | + throw new \RuntimeException("The Oci8 extension is not loaded"); |
|
| 61 | + } |
|
| 59 | 62 | |
| 60 | 63 | $connection_string = (is_null($this->dbhost) || empty($this->dbhost)) |
| 61 | 64 | ? $this->dbname |
@@ -108,14 +111,15 @@ discard block |
||
| 108 | 111 | ]; |
| 109 | 112 | |
| 110 | 113 | $this->error($error["message"]); |
| 114 | + } else { |
|
| 115 | + $this->error($error["code"], $error["message"]); |
|
| 111 | 116 | } |
| 112 | - else |
|
| 113 | - $this->error($error["code"], $error["message"]); |
|
| 114 | 117 | |
| 115 | - if (array_key_exists("code", $error)) |
|
| 116 | - throw new Exception\InvalidQueryException($error["message"], $error["code"]); |
|
| 117 | - else |
|
| 118 | - throw new Exception\InvalidQueryException($error["message"]); |
|
| 118 | + if (array_key_exists("code", $error)) { |
|
| 119 | + throw new Exception\InvalidQueryException($error["message"], $error["code"]); |
|
| 120 | + } else { |
|
| 121 | + throw new Exception\InvalidQueryException($error["message"]); |
|
| 122 | + } |
|
| 119 | 123 | } |
| 120 | 124 | |
| 121 | 125 | # Bound variables |
@@ -155,8 +159,9 @@ discard block |
||
| 155 | 159 | $this->numRows = count($rows); |
| 156 | 160 | $this->numFields = oci_num_fields($stid); |
| 157 | 161 | |
| 158 | - if ($this->transac_mode) |
|
| 159 | - $this->transac_result = is_null($this->transac_result) ? $stid: $this->transac_result && $stid; |
|
| 162 | + if ($this->transac_mode) { |
|
| 163 | + $this->transac_result = is_null($this->transac_result) ? $stid: $this->transac_result && $stid; |
|
| 164 | + } |
|
| 160 | 165 | |
| 161 | 166 | $this->result = $stid; |
| 162 | 167 | |
@@ -205,10 +210,10 @@ discard block |
||
| 205 | 210 | { |
| 206 | 211 | $data[] = $row; |
| 207 | 212 | } |
| 208 | - } |
|
| 209 | - else |
|
| 210 | - # This error is thrown because of 'execute' method has not been executed. |
|
| 213 | + } else { |
|
| 214 | + # This error is thrown because of 'execute' method has not been executed. |
|
| 211 | 215 | throw new \LogicException('There are not data in the buffer!'); |
| 216 | + } |
|
| 212 | 217 | |
| 213 | 218 | $this->arrayResult = $data; |
| 214 | 219 | |
@@ -222,7 +227,8 @@ discard block |
||
| 222 | 227 | */ |
| 223 | 228 | public function __destruct() |
| 224 | 229 | { |
| 225 | - if ($this->dbconn) |
|
| 226 | - oci_close($this->dbconn); |
|
| 230 | + if ($this->dbconn) { |
|
| 231 | + oci_close($this->dbconn); |
|
| 232 | + } |
|
| 227 | 233 | } |
| 228 | 234 | } |
| 229 | 235 | \ No newline at end of file |
@@ -33,15 +33,17 @@ discard block |
||
| 33 | 33 | { |
| 34 | 34 | $this->driverName = 'Mysqli'; |
| 35 | 35 | |
| 36 | - if (!array_key_exists("dbchar", $options)) |
|
| 37 | - $options["dbchar"] = "utf8"; |
|
| 36 | + if (!array_key_exists("dbchar", $options)) { |
|
| 37 | + $options["dbchar"] = "utf8"; |
|
| 38 | + } |
|
| 38 | 39 | |
| 39 | 40 | parent::__construct($options); |
| 40 | 41 | |
| 41 | 42 | $auto_connect = array_key_exists('auto_connect', $options) ? $options["auto_connect"] : true; |
| 42 | 43 | |
| 43 | - if ($auto_connect) |
|
| 44 | - $this->connect(); |
|
| 44 | + if ($auto_connect) { |
|
| 45 | + $this->connect(); |
|
| 46 | + } |
|
| 45 | 47 | } |
| 46 | 48 | |
| 47 | 49 | /** |
@@ -54,13 +56,15 @@ discard block |
||
| 54 | 56 | */ |
| 55 | 57 | public function connect() |
| 56 | 58 | { |
| 57 | - if (!extension_loaded('mysqli')) |
|
| 58 | - throw new \RuntimeException("The Mysqli extension is not loaded"); |
|
| 59 | + if (!extension_loaded('mysqli')) { |
|
| 60 | + throw new \RuntimeException("The Mysqli extension is not loaded"); |
|
| 61 | + } |
|
| 59 | 62 | |
| 60 | - if (!is_null($this->dbport) && !empty($this->dbport)) |
|
| 61 | - $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname, $this->dbport); |
|
| 62 | - else |
|
| 63 | - $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname); |
|
| 63 | + if (!is_null($this->dbport) && !empty($this->dbport)) { |
|
| 64 | + $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname, $this->dbport); |
|
| 65 | + } else { |
|
| 66 | + $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname); |
|
| 67 | + } |
|
| 64 | 68 | |
| 65 | 69 | if ($conn->connect_errno) |
| 66 | 70 | { |
@@ -70,8 +74,7 @@ discard block |
||
| 70 | 74 | * the warning message "Property access is not allowed yet". |
| 71 | 75 | */ |
| 72 | 76 | throw new Exception\ConnectionException(mysqli_connect_error(), mysqli_connect_errno()); |
| 73 | - } |
|
| 74 | - else |
|
| 77 | + } else |
|
| 75 | 78 | { |
| 76 | 79 | $this->dbconn = $conn; |
| 77 | 80 | $this->dbconn->set_charset($this->dbchar); |
@@ -118,13 +121,15 @@ discard block |
||
| 118 | 121 | |
| 119 | 122 | for ($i = 0; $i < $n_params; $i++) |
| 120 | 123 | { |
| 121 | - if (is_string($param_values[$i])) |
|
| 122 | - $bind_types .= 's'; |
|
| 123 | - else if(is_float($param_values[$i])) |
|
| 124 | - $bind_types .= 'd'; |
|
| 124 | + if (is_string($param_values[$i])) { |
|
| 125 | + $bind_types .= 's'; |
|
| 126 | + } else if(is_float($param_values[$i])) { |
|
| 127 | + $bind_types .= 'd'; |
|
| 128 | + } |
|
| 125 | 129 | # [POSSIBLE BUG] - To Future revision (What about non-string and non-decimal types ?) |
| 126 | - else |
|
| 127 | - $bind_types .= 's'; |
|
| 130 | + else { |
|
| 131 | + $bind_types .= 's'; |
|
| 132 | + } |
|
| 128 | 133 | |
| 129 | 134 | $bind_values[] = '$param_values[' . $i . ']'; |
| 130 | 135 | } |
@@ -133,8 +138,7 @@ discard block |
||
| 133 | 138 | eval('$stmt->bind_param(\'' . $bind_types . '\', ' . $values . ');'); |
| 134 | 139 | |
| 135 | 140 | $r = $stmt->execute(); |
| 136 | - } |
|
| 137 | - else |
|
| 141 | + } else |
|
| 138 | 142 | { |
| 139 | 143 | $prev_error_handler = set_error_handler(['\Drone\Error\ErrorHandler', 'errorControlOperator'], E_ALL); |
| 140 | 144 | |
@@ -163,28 +167,33 @@ discard block |
||
| 163 | 167 | * It is useful to prevent rollback transactions on insert statements because |
| 164 | 168 | * insert statement do not free results. |
| 165 | 169 | */ |
| 166 | - if ($res) |
|
| 167 | - $this->result = $res; |
|
| 170 | + if ($res) { |
|
| 171 | + $this->result = $res; |
|
| 172 | + } |
|
| 168 | 173 | } |
| 169 | 174 | |
| 170 | 175 | # identify SELECT, SHOW, DESCRIBE or EXPLAIN queries |
| 171 | - if (is_object($this->result) && property_exists($this->result, 'num_rows')) |
|
| 172 | - $this->numRows = $this->result->num_rows; |
|
| 173 | - else |
|
| 176 | + if (is_object($this->result) && property_exists($this->result, 'num_rows')) { |
|
| 177 | + $this->numRows = $this->result->num_rows; |
|
| 178 | + } else |
|
| 174 | 179 | { |
| 175 | - if (property_exists($this->dbconn, 'affected_rows') && !$is_stmt_result) |
|
| 176 | - $this->rowsAffected = $this->dbconn->affected_rows; |
|
| 180 | + if (property_exists($this->dbconn, 'affected_rows') && !$is_stmt_result) { |
|
| 181 | + $this->rowsAffected = $this->dbconn->affected_rows; |
|
| 182 | + } |
|
| 177 | 183 | } |
| 178 | 184 | |
| 179 | 185 | # affected_rows return the same of num_rows on select statements! |
| 180 | - if ($this->numRows > 0) |
|
| 181 | - $this->rowsAffected = 0; |
|
| 186 | + if ($this->numRows > 0) { |
|
| 187 | + $this->rowsAffected = 0; |
|
| 188 | + } |
|
| 182 | 189 | |
| 183 | - if (property_exists($this->dbconn, 'field_count')) |
|
| 184 | - $this->numFields = $this->dbconn->field_count; |
|
| 190 | + if (property_exists($this->dbconn, 'field_count')) { |
|
| 191 | + $this->numFields = $this->dbconn->field_count; |
|
| 192 | + } |
|
| 185 | 193 | |
| 186 | - if ($this->transac_mode) |
|
| 187 | - $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
| 194 | + if ($this->transac_mode) { |
|
| 195 | + $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
| 196 | + } |
|
| 188 | 197 | /* |
| 189 | 198 | * Because mysqli_query() returns FALSE on failure, a mysqli_result object for SELECT, SHOW, DESCRIBE or EXPLAIN queries, |
| 190 | 199 | * and TRUE for other successful queries, it should be handled to return only objects or resources. |
@@ -252,10 +261,10 @@ discard block |
||
| 252 | 261 | { |
| 253 | 262 | $data[] = $row; |
| 254 | 263 | } |
| 255 | - } |
|
| 256 | - else |
|
| 257 | - # This error is thrown because of 'execute' method has not been executed. |
|
| 264 | + } else { |
|
| 265 | + # This error is thrown because of 'execute' method has not been executed. |
|
| 258 | 266 | throw new \LogicException('There are not data in the buffer!'); |
| 267 | + } |
|
| 259 | 268 | |
| 260 | 269 | $this->arrayResult = $data; |
| 261 | 270 | |
@@ -270,7 +279,8 @@ discard block |
||
| 270 | 279 | public function __destruct() |
| 271 | 280 | { |
| 272 | 281 | # prevent "Property access is not allowed yet" with @ on failure connections |
| 273 | - if ($this->dbconn !== false && !is_null($this->dbconn)) |
|
| 274 | - @$this->dbconn->close(); |
|
| 282 | + if ($this->dbconn !== false && !is_null($this->dbconn)) { |
|
| 283 | + @$this->dbconn->close(); |
|
| 284 | + } |
|
| 275 | 285 | } |
| 276 | 286 | } |
| 277 | 287 | \ No newline at end of file |
@@ -69,9 +69,10 @@ discard block |
||
| 69 | 69 | */ |
| 70 | 70 | public function isValid() |
| 71 | 71 | { |
| 72 | - if (is_null($this->valid)) |
|
| 73 | - # This error is thrown because of 'setValid' method has not been executed. |
|
| 72 | + if (is_null($this->valid)) { |
|
| 73 | + # This error is thrown because of 'setValid' method has not been executed. |
|
| 74 | 74 | throw new \LogicException('No validation has been executed!'); |
| 75 | + } |
|
| 75 | 76 | |
| 76 | 77 | return $this->valid; |
| 77 | 78 | } |
@@ -98,8 +99,9 @@ discard block |
||
| 98 | 99 | { |
| 99 | 100 | $this->form = $form; |
| 100 | 101 | |
| 101 | - if (is_null($locale)) |
|
| 102 | - $locale = 'en'; |
|
| 102 | + if (is_null($locale)) { |
|
| 103 | + $locale = 'en'; |
|
| 104 | + } |
|
| 103 | 105 | |
| 104 | 106 | $i18nTranslator = \Zend\I18n\Translator\Translator::factory( |
| 105 | 107 | [ |
@@ -133,8 +135,9 @@ discard block |
||
| 133 | 135 | |
| 134 | 136 | foreach ($elements as $label => $element) |
| 135 | 137 | { |
| 136 | - if (!$element->isFormControl()) |
|
| 137 | - continue; |
|
| 138 | + if (!$element->isFormControl()) { |
|
| 139 | + continue; |
|
| 140 | + } |
|
| 138 | 141 | |
| 139 | 142 | $attribs = $element->getAttributes(); |
| 140 | 143 | |
@@ -203,19 +206,21 @@ discard block |
||
| 203 | 206 | |
| 204 | 207 | case 'min': |
| 205 | 208 | |
| 206 | - if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['number', 'range'])) |
|
| 207 | - $validator = new GreaterThan(['min' => $value, 'inclusive' => true]); |
|
| 208 | - else |
|
| 209 | - throw new \LogicException("The input type must be 'range' or 'number'"); |
|
| 209 | + if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['number', 'range'])) { |
|
| 210 | + $validator = new GreaterThan(['min' => $value, 'inclusive' => true]); |
|
| 211 | + } else { |
|
| 212 | + throw new \LogicException("The input type must be 'range' or 'number'"); |
|
| 213 | + } |
|
| 210 | 214 | |
| 211 | 215 | break; |
| 212 | 216 | |
| 213 | 217 | case 'max': |
| 214 | 218 | |
| 215 | - if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['number', 'range'])) |
|
| 216 | - $validator = new LessThan(['max' => $value, 'inclusive' => true]); |
|
| 217 | - else |
|
| 218 | - throw new \LogicException("The input type must be 'range' or 'number'"); |
|
| 219 | + if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['number', 'range'])) { |
|
| 220 | + $validator = new LessThan(['max' => $value, 'inclusive' => true]); |
|
| 221 | + } else { |
|
| 222 | + throw new \LogicException("The input type must be 'range' or 'number'"); |
|
| 223 | + } |
|
| 219 | 224 | |
| 220 | 225 | break; |
| 221 | 226 | |
@@ -223,17 +228,19 @@ discard block |
||
| 223 | 228 | |
| 224 | 229 | $baseValue = (array_key_exists('min', $all_attribs)) ? $all_attribs['min'] : 0; |
| 225 | 230 | |
| 226 | - if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['range'])) |
|
| 227 | - $validator = new Step(['baseValue' => $baseValue, 'step' => $value]); |
|
| 228 | - else |
|
| 229 | - throw new \LogicException("The input type must be 'range'"); |
|
| 231 | + if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['range'])) { |
|
| 232 | + $validator = new Step(['baseValue' => $baseValue, 'step' => $value]); |
|
| 233 | + } else { |
|
| 234 | + throw new \LogicException("The input type must be 'range'"); |
|
| 235 | + } |
|
| 230 | 236 | |
| 231 | 237 | break; |
| 232 | 238 | |
| 233 | 239 | case 'data-validators': |
| 234 | 240 | |
| 235 | - if (!is_array($value)) |
|
| 236 | - throw new \InvalidArgumentException("Invalid type given. Array expected in 'data-validators' attribute."); |
|
| 241 | + if (!is_array($value)) { |
|
| 242 | + throw new \InvalidArgumentException("Invalid type given. Array expected in 'data-validators' attribute."); |
|
| 243 | + } |
|
| 237 | 244 | |
| 238 | 245 | foreach ($value as $class => $params) |
| 239 | 246 | { |
@@ -243,8 +250,9 @@ discard block |
||
| 243 | 250 | { |
| 244 | 251 | $className = "\Zend\I18n\Validator\\" . $class; |
| 245 | 252 | |
| 246 | - if (!class_exists($className)) |
|
| 247 | - throw new \RuntimeException("The class '$userInputClass' or '$className' does not exists"); |
|
| 253 | + if (!class_exists($className)) { |
|
| 254 | + throw new \RuntimeException("The class '$userInputClass' or '$className' does not exists"); |
|
| 255 | + } |
|
| 248 | 256 | } |
| 249 | 257 | |
| 250 | 258 | $validator = new $className($params); |
@@ -291,8 +299,9 @@ discard block |
||
| 291 | 299 | $v->setTranslator($this->translator); |
| 292 | 300 | $notEmpty = $v->isValid($val); |
| 293 | 301 | |
| 294 | - if (!$required && !$notEmpty) |
|
| 295 | - return null; |
|
| 302 | + if (!$required && !$notEmpty) { |
|
| 303 | + return null; |
|
| 304 | + } |
|
| 296 | 305 | |
| 297 | 306 | $valid = $validator->isValid($val); |
| 298 | 307 | $this->setValid($valid); |
@@ -304,8 +313,7 @@ discard block |
||
| 304 | 313 | $this->error($label ."-~-". (count($this->getErrors()) + 1), $message); |
| 305 | 314 | } |
| 306 | 315 | } |
| 307 | - } |
|
| 308 | - else |
|
| 316 | + } else |
|
| 309 | 317 | { |
| 310 | 318 | foreach ($form_value as $val) |
| 311 | 319 | { |
@@ -330,8 +338,9 @@ discard block |
||
| 330 | 338 | $errorLbl = explode("-~-", $key); |
| 331 | 339 | $label = array_shift($errorLbl); |
| 332 | 340 | |
| 333 | - if (!array_key_exists($label, $errors)) |
|
| 334 | - $errors[$label] = []; |
|
| 341 | + if (!array_key_exists($label, $errors)) { |
|
| 342 | + $errors[$label] = []; |
|
| 343 | + } |
|
| 335 | 344 | |
| 336 | 345 | $errors[$label][] = $value; |
| 337 | 346 | } |
@@ -39,9 +39,9 @@ discard block |
||
| 39 | 39 | $again = true; |
| 40 | 40 | $new_config[$param . $glue . $key] = $value; |
| 41 | 41 | } |
| 42 | + } else { |
|
| 43 | + $new_config[$param] = $configure; |
|
| 42 | 44 | } |
| 43 | - else |
|
| 44 | - $new_config[$param] = $configure; |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | return (!$again) ? $new_config : self::toUnidimensional($new_config, $glue); |
@@ -64,15 +64,17 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | do |
| 66 | 66 | { |
| 67 | - if (array_key_exists($key, $haystack)) |
|
| 68 | - $haystack = $haystack[$key]; |
|
| 69 | - else |
|
| 70 | - return $value; |
|
| 67 | + if (array_key_exists($key, $haystack)) { |
|
| 68 | + $haystack = $haystack[$key]; |
|
| 69 | + } else { |
|
| 70 | + return $value; |
|
| 71 | + } |
|
| 71 | 72 | |
| 72 | 73 | $key = count($needle) ? array_shift($needle) : NULL; |
| 73 | 74 | |
| 74 | - if (is_null($key)) |
|
| 75 | - return $haystack; |
|
| 75 | + if (is_null($key)) { |
|
| 76 | + return $haystack; |
|
| 77 | + } |
|
| 76 | 78 | |
| 77 | 79 | } while (!is_null($key)); |
| 78 | 80 | } |
@@ -86,8 +88,9 @@ discard block |
||
| 86 | 88 | */ |
| 87 | 89 | public static function objectToArray($obj) |
| 88 | 90 | { |
| 89 | - if (is_object($obj)) |
|
| 90 | - $obj = (array) $obj; |
|
| 91 | + if (is_object($obj)) { |
|
| 92 | + $obj = (array) $obj; |
|
| 93 | + } |
|
| 91 | 94 | |
| 92 | 95 | if (is_array($obj)) |
| 93 | 96 | { |
@@ -97,9 +100,9 @@ discard block |
||
| 97 | 100 | { |
| 98 | 101 | $new[$key] = self::objectToArray($val); |
| 99 | 102 | } |
| 103 | + } else { |
|
| 104 | + $new = $obj; |
|
| 100 | 105 | } |
| 101 | - else |
|
| 102 | - $new = $obj; |
|
| 103 | 106 | |
| 104 | 107 | return $new; |
| 105 | 108 | } |
@@ -25,8 +25,7 @@ discard block |
||
| 25 | 25 | try |
| 26 | 26 | { |
| 27 | 27 | throw new ExceptionException("This is an storable exception"); |
| 28 | - } |
|
| 29 | - catch (ExceptionException $e) |
|
| 28 | + } catch (ExceptionException $e) |
|
| 30 | 29 | { |
| 31 | 30 | mkdir('exceptions'); |
| 32 | 31 | |
@@ -64,8 +63,7 @@ discard block |
||
| 64 | 63 | try |
| 65 | 64 | { |
| 66 | 65 | throw new ExceptionException("This is an storable exception too"); |
| 67 | - } |
|
| 68 | - catch (ExceptionException $e) |
|
| 66 | + } catch (ExceptionException $e) |
|
| 69 | 67 | { |
| 70 | 68 | $date = date('dmY'); |
| 71 | 69 | $file = 'nofolder/exception-' . $date . '.json'; |
@@ -95,8 +93,7 @@ discard block |
||
| 95 | 93 | try |
| 96 | 94 | { |
| 97 | 95 | throw new ExceptionException("This is an storable exception"); |
| 98 | - } |
|
| 99 | - catch (ExceptionException $e) |
|
| 96 | + } catch (ExceptionException $e) |
|
| 100 | 97 | { |
| 101 | 98 | $file = 'exceptions/exception-' . $date . '.json'; |
| 102 | 99 | $storage = new \Drone\Exception\Storage($file); |
@@ -106,8 +103,7 @@ discard block |
||
| 106 | 103 | try |
| 107 | 104 | { |
| 108 | 105 | throw new ExceptionException("This is an storable exception too"); |
| 109 | - } |
|
| 110 | - catch (ExceptionException $e) |
|
| 106 | + } catch (ExceptionException $e) |
|
| 111 | 107 | { |
| 112 | 108 | $file = 'exceptions/exception-' . $date . '.json'; |
| 113 | 109 | $storage = new \Drone\Exception\Storage($file); |
@@ -69,8 +69,7 @@ discard block |
||
| 69 | 69 | return false; |
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | - } |
|
| 73 | - else |
|
| 72 | + } else |
|
| 74 | 73 | { |
| 75 | 74 | $directory = strstr($this->outputFile, basename($this->outputFile), true); |
| 76 | 75 | |
@@ -86,17 +85,20 @@ discard block |
||
| 86 | 85 | "object" => serialize($exception) |
| 87 | 86 | ]; |
| 88 | 87 | |
| 89 | - if (!function_exists('mb_detect_encoding')) |
|
| 90 | - throw new \RuntimeException("mbstring library is not installed!"); |
|
| 88 | + if (!function_exists('mb_detect_encoding')) { |
|
| 89 | + throw new \RuntimeException("mbstring library is not installed!"); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | 92 | /* |
| 93 | 93 | * Encodes to UTF8 all messages. It ensures JSON encoding. |
| 94 | 94 | */ |
| 95 | - if (!mb_detect_encoding($data[$id]["message"], 'UTF-8', true)) |
|
| 96 | - $data[$id]["message"] = utf8_encode($data[$id]["message"]); |
|
| 95 | + if (!mb_detect_encoding($data[$id]["message"], 'UTF-8', true)) { |
|
| 96 | + $data[$id]["message"] = utf8_encode($data[$id]["message"]); |
|
| 97 | + } |
|
| 97 | 98 | |
| 98 | - if (!mb_detect_encoding($data[$id]["object"], 'UTF-8', true)) |
|
| 99 | - $data[$id]["object"] = utf8_decode($data[$id]["object"]); |
|
| 99 | + if (!mb_detect_encoding($data[$id]["object"], 'UTF-8', true)) { |
|
| 100 | + $data[$id]["object"] = utf8_decode($data[$id]["object"]); |
|
| 101 | + } |
|
| 100 | 102 | |
| 101 | 103 | if (($encoded_data = json_encode($data)) === false) |
| 102 | 104 | { |
@@ -141,8 +141,9 @@ discard block |
||
| 141 | 141 | */ |
| 142 | 142 | public function __construct(Array $routes = []) |
| 143 | 143 | { |
| 144 | - if (count($routes)) |
|
| 145 | - $this->routes = $routes; |
|
| 144 | + if (count($routes)) { |
|
| 145 | + $this->routes = $routes; |
|
| 146 | + } |
|
| 146 | 147 | |
| 147 | 148 | $this->zendRouter = new \Zend\Router\SimpleRouteStack(); |
| 148 | 149 | } |
@@ -165,8 +166,9 @@ discard block |
||
| 165 | 166 | $module = (is_null($this->identifiers["module"]) || empty($this->identifiers["module"])) |
| 166 | 167 | ? $this->routes["defaults"]["module"] : $this->identifiers["module"]; |
| 167 | 168 | |
| 168 | - if (!array_key_exists($module, $this->routes)) |
|
| 169 | - throw new Exception\ModuleNotFoundException("The key '$module' does not exists in routes!"); |
|
| 169 | + if (!array_key_exists($module, $this->routes)) { |
|
| 170 | + throw new Exception\ModuleNotFoundException("The key '$module' does not exists in routes!"); |
|
| 171 | + } |
|
| 170 | 172 | |
| 171 | 173 | $controller = (is_null($this->identifiers["controller"]) || empty($this->identifiers["controller"])) |
| 172 | 174 | ? $this->routes[$module]["controller"] : $this->identifiers["controller"]; |
@@ -176,10 +178,11 @@ discard block |
||
| 176 | 178 | |
| 177 | 179 | $fqn_controller = '\\' . $module . "\Controller\\" . $controller; |
| 178 | 180 | |
| 179 | - if (class_exists($fqn_controller)) |
|
| 180 | - $this->controller = new $fqn_controller($module, $view, $this->basePath); |
|
| 181 | - else |
|
| 182 | - throw new Exception\ControllerNotFoundException("The control class '$fqn_controller' does not exists!"); |
|
| 181 | + if (class_exists($fqn_controller)) { |
|
| 182 | + $this->controller = new $fqn_controller($module, $view, $this->basePath); |
|
| 183 | + } else { |
|
| 184 | + throw new Exception\ControllerNotFoundException("The control class '$fqn_controller' does not exists!"); |
|
| 185 | + } |
|
| 183 | 186 | } |
| 184 | 187 | |
| 185 | 188 | /** |
@@ -196,8 +199,9 @@ discard block |
||
| 196 | 199 | $key = array_keys($route); |
| 197 | 200 | $key = array_shift($key); |
| 198 | 201 | |
| 199 | - if (array_key_exists($key, $this->routes)) |
|
| 200 | - throw new \LogicException("The key '$key' was already defined as route"); |
|
| 202 | + if (array_key_exists($key, $this->routes)) { |
|
| 203 | + throw new \LogicException("The key '$key' was already defined as route"); |
|
| 204 | + } |
|
| 201 | 205 | |
| 202 | 206 | $this->routes = array_merge($this->routes, $route); |
| 203 | 207 | } |
@@ -68,19 +68,23 @@ discard block |
||
| 68 | 68 | public function __construct(Array $init_parameters) |
| 69 | 69 | { |
| 70 | 70 | # start sessions |
| 71 | - if (!isset($_SESSION)) |
|
| 72 | - session_start(); |
|
| 71 | + if (!isset($_SESSION)) { |
|
| 72 | + session_start(); |
|
| 73 | + } |
|
| 73 | 74 | |
| 74 | - if (!array_key_exists('environment', $init_parameters)) |
|
| 75 | - throw new \InvalidArgumentException("The 'environment' key was not defined"); |
|
| 75 | + if (!array_key_exists('environment', $init_parameters)) { |
|
| 76 | + throw new \InvalidArgumentException("The 'environment' key was not defined"); |
|
| 77 | + } |
|
| 76 | 78 | |
| 77 | - if (!array_key_exists('dev_mode', $init_parameters['environment'])) |
|
| 78 | - throw new \InvalidArgumentException("The 'dev_mode' key was not defined"); |
|
| 79 | + if (!array_key_exists('dev_mode', $init_parameters['environment'])) { |
|
| 80 | + throw new \InvalidArgumentException("The 'dev_mode' key was not defined"); |
|
| 81 | + } |
|
| 79 | 82 | |
| 80 | 83 | $this->devMode = $init_parameters["environment"]["dev_mode"]; |
| 81 | 84 | |
| 82 | - if (!array_key_exists('modules', $init_parameters)) |
|
| 83 | - throw new \InvalidArgumentException("The 'modules' key was not defined"); |
|
| 85 | + if (!array_key_exists('modules', $init_parameters)) { |
|
| 86 | + throw new \InvalidArgumentException("The 'modules' key was not defined"); |
|
| 87 | + } |
|
| 84 | 88 | |
| 85 | 89 | $this->modules = $init_parameters["modules"]; |
| 86 | 90 | |
@@ -94,8 +98,7 @@ discard block |
||
| 94 | 98 | { |
| 95 | 99 | ini_set('display_errors', 1); |
| 96 | 100 | error_reporting(-1); |
| 97 | - } |
|
| 98 | - else |
|
| 101 | + } else |
|
| 99 | 102 | { |
| 100 | 103 | ini_set('display_errors', 0); |
| 101 | 104 | error_reporting(0); |
@@ -103,26 +106,30 @@ discard block |
||
| 103 | 106 | |
| 104 | 107 | $this->loadModules($this->modules); |
| 105 | 108 | |
| 106 | - if (!array_key_exists('router', $init_parameters)) |
|
| 107 | - throw new \InvalidArgumentException("The 'router' key was not defined"); |
|
| 109 | + if (!array_key_exists('router', $init_parameters)) { |
|
| 110 | + throw new \InvalidArgumentException("The 'router' key was not defined"); |
|
| 111 | + } |
|
| 108 | 112 | |
| 109 | - if (!array_key_exists('routes', $init_parameters["router"])) |
|
| 110 | - throw new \InvalidArgumentException("The 'routes' key was not defined"); |
|
| 113 | + if (!array_key_exists('routes', $init_parameters["router"])) { |
|
| 114 | + throw new \InvalidArgumentException("The 'routes' key was not defined"); |
|
| 115 | + } |
|
| 111 | 116 | |
| 112 | 117 | $this->router = new Router($init_parameters["router"]["routes"]); |
| 113 | 118 | |
| 114 | - if (!array_key_exists('base_path', $init_parameters['environment'])) |
|
| 115 | - throw new \InvalidArgumentException("The 'base_path' key was not defined"); |
|
| 119 | + if (!array_key_exists('base_path', $init_parameters['environment'])) { |
|
| 120 | + throw new \InvalidArgumentException("The 'base_path' key was not defined"); |
|
| 121 | + } |
|
| 116 | 122 | |
| 117 | 123 | $this->router->setBasePath($init_parameters["environment"]["base_path"]); |
| 118 | 124 | |
| 119 | 125 | # load routes from init_parameters |
| 120 | 126 | foreach ($init_parameters["router"]["routes"] as $name => $route) |
| 121 | 127 | { |
| 122 | - if ($route instanceof \Zend\Router\Http\RouteInterface) |
|
| 123 | - $this->getRouter()->addZendRoute($name, $route); |
|
| 124 | - else |
|
| 125 | - $this->getRouter()->addRoute($route); |
|
| 128 | + if ($route instanceof \Zend\Router\Http\RouteInterface) { |
|
| 129 | + $this->getRouter()->addZendRoute($name, $route); |
|
| 130 | + } else { |
|
| 131 | + $this->getRouter()->addRoute($route); |
|
| 132 | + } |
|
| 126 | 133 | } |
| 127 | 134 | |
| 128 | 135 | # load routes from each module |
@@ -132,11 +139,13 @@ discard block |
||
| 132 | 139 | { |
| 133 | 140 | $module_config_file = require($this->modulePath . "/$module/config/module.config.php"); |
| 134 | 141 | |
| 135 | - if (!array_key_exists('router', $module_config_file)) |
|
| 136 | - throw new \RuntimeException("The 'router' key was not defined in the config file for module '$module'"); |
|
| 142 | + if (!array_key_exists('router', $module_config_file)) { |
|
| 143 | + throw new \RuntimeException("The 'router' key was not defined in the config file for module '$module'"); |
|
| 144 | + } |
|
| 137 | 145 | |
| 138 | - if (!array_key_exists('routes', $module_config_file["router"])) |
|
| 139 | - throw new \RuntimeException("The 'routes' key was not defined in the config file for module '$module'"); |
|
| 146 | + if (!array_key_exists('routes', $module_config_file["router"])) { |
|
| 147 | + throw new \RuntimeException("The 'routes' key was not defined in the config file for module '$module'"); |
|
| 148 | + } |
|
| 140 | 149 | |
| 141 | 150 | $this->getRouter()->addRoute($module_config_file["router"]["routes"]); |
| 142 | 151 | } |
@@ -162,14 +171,15 @@ discard block |
||
| 162 | 171 | * This instruction includes each module declared. |
| 163 | 172 | * Each module has an autoloader to load its classes (controllers and models) |
| 164 | 173 | */ |
| 165 | - if (file_exists($this->modulePath ."/". $module."/Module.php")) |
|
| 166 | - include($this->modulePath ."/". $module."/Module.php"); |
|
| 174 | + if (file_exists($this->modulePath ."/". $module."/Module.php")) { |
|
| 175 | + include($this->modulePath ."/". $module."/Module.php"); |
|
| 176 | + } |
|
| 167 | 177 | |
| 168 | 178 | spl_autoload_register($module . "\Module::loader"); |
| 169 | 179 | } |
| 180 | + } else { |
|
| 181 | + throw new \RuntimeException("The application must have at least one module"); |
|
| 170 | 182 | } |
| 171 | - else |
|
| 172 | - throw new \RuntimeException("The application must have at least one module"); |
|
| 173 | 183 | } |
| 174 | 184 | |
| 175 | 185 | /** |
@@ -191,8 +201,9 @@ discard block |
||
| 191 | 201 | $uri .= !empty($controller) ? '/' . $controller : ""; |
| 192 | 202 | $uri .= !empty($view) ? '/' . $view : ""; |
| 193 | 203 | |
| 194 | - if (empty($uri)) |
|
| 195 | - $uri = "/"; |
|
| 204 | + if (empty($uri)) { |
|
| 205 | + $uri = "/"; |
|
| 206 | + } |
|
| 196 | 207 | |
| 197 | 208 | $request->setUri($uri); |
| 198 | 209 | |
@@ -208,9 +219,9 @@ discard block |
||
| 208 | 219 | $view = $params["action"]; |
| 209 | 220 | |
| 210 | 221 | $this->router->setIdentifiers($module, $controller, $view); |
| 222 | + } else { |
|
| 223 | + $this->router->setIdentifiers($module, $controller, $view); |
|
| 211 | 224 | } |
| 212 | - else |
|
| 213 | - $this->router->setIdentifiers($module, $controller, $view); |
|
| 214 | 225 | |
| 215 | 226 | $this->router->run(); |
| 216 | 227 | } |