@@ -103,8 +103,9 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | public function getOption($key, $name) |
| 105 | 105 | { |
| 106 | - if (!array_key_exists($key, $this->options)) |
|
| 107 | - throw new \LogicException("The option '$key' does not exists"); |
|
| 106 | + if (!array_key_exists($key, $this->options)) { |
|
| 107 | + throw new \LogicException("The option '$key' does not exists"); |
|
| 108 | + } |
|
| 108 | 109 | |
| 109 | 110 | return array_key_exists($name, $this->options[$key]) ? $this->options[$key][$name] : null; |
| 110 | 111 | } |
@@ -158,8 +159,9 @@ discard block |
||
| 158 | 159 | |
| 159 | 160 | foreach ($attribs as $key => $attributes) |
| 160 | 161 | { |
| 161 | - if (!array_key_exists($key, $attribs)) |
|
| 162 | - throw new \LogicException("The field '$key' does not exists!"); |
|
| 162 | + if (!array_key_exists($key, $attribs)) { |
|
| 163 | + throw new \LogicException("The field '$key' does not exists!"); |
|
| 164 | + } |
|
| 163 | 165 | |
| 164 | 166 | $label = (array_key_exists('label', array_keys($this->options))) ? $attributes["label"] : $key; |
| 165 | 167 | |
@@ -225,19 +227,21 @@ discard block |
||
| 225 | 227 | |
| 226 | 228 | case 'min': |
| 227 | 229 | |
| 228 | - if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['number', 'range'])) |
|
| 229 | - $validator = new GreaterThan(['min' => $value, 'inclusive' => true]); |
|
| 230 | - else |
|
| 231 | - throw new \LogicException("The input type must be 'range' or 'number'"); |
|
| 230 | + if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['number', 'range'])) { |
|
| 231 | + $validator = new GreaterThan(['min' => $value, 'inclusive' => true]); |
|
| 232 | + } else { |
|
| 233 | + throw new \LogicException("The input type must be 'range' or 'number'"); |
|
| 234 | + } |
|
| 232 | 235 | |
| 233 | 236 | break; |
| 234 | 237 | |
| 235 | 238 | case 'max': |
| 236 | 239 | |
| 237 | - if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['number', 'range'])) |
|
| 238 | - $validator = new LessThan(['max' => $value, 'inclusive' => true]); |
|
| 239 | - else |
|
| 240 | - throw new \LogicException("The input type must be 'range' or 'number'"); |
|
| 240 | + if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['number', 'range'])) { |
|
| 241 | + $validator = new LessThan(['max' => $value, 'inclusive' => true]); |
|
| 242 | + } else { |
|
| 243 | + throw new \LogicException("The input type must be 'range' or 'number'"); |
|
| 244 | + } |
|
| 241 | 245 | |
| 242 | 246 | break; |
| 243 | 247 | |
@@ -245,10 +249,11 @@ discard block |
||
| 245 | 249 | |
| 246 | 250 | $baseValue = (array_key_exists('min', $all_attribs)) ? $all_attribs['min'] : 0; |
| 247 | 251 | |
| 248 | - if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['range'])) |
|
| 249 | - $validator = new Step(['baseValue' => $baseValue, 'step' => $value]); |
|
| 250 | - else |
|
| 251 | - throw new \LogicException("The input type must be 'range'"); |
|
| 252 | + if (array_key_exists('type', $all_attribs) && in_array($all_attribs['type'], ['range'])) { |
|
| 253 | + $validator = new Step(['baseValue' => $baseValue, 'step' => $value]); |
|
| 254 | + } else { |
|
| 255 | + throw new \LogicException("The input type must be 'range'"); |
|
| 256 | + } |
|
| 252 | 257 | |
| 253 | 258 | break; |
| 254 | 259 | } |
@@ -272,8 +277,9 @@ discard block |
||
| 272 | 277 | $validator = new NotEmpty(); |
| 273 | 278 | $attribute = $this->formHandler->getAttribute($key, "value"); |
| 274 | 279 | |
| 275 | - if (is_null($attribute)) |
|
| 276 | - throw new \LogicException("Missing attribute 'value' in '" . $key . "'."); |
|
| 280 | + if (is_null($attribute)) { |
|
| 281 | + throw new \LogicException("Missing attribute 'value' in '" . $key . "'."); |
|
| 282 | + } |
|
| 277 | 283 | |
| 278 | 284 | $value = $attribute->getValue(); |
| 279 | 285 | |
@@ -287,8 +293,9 @@ discard block |
||
| 287 | 293 | { |
| 288 | 294 | $className = "\Zend\I18n\Validator\\" . $class; |
| 289 | 295 | |
| 290 | - if (!class_exists($className)) |
|
| 291 | - throw new \RuntimeException("The class '$userInputClass' or '$className' does not exists"); |
|
| 296 | + if (!class_exists($className)) { |
|
| 297 | + throw new \RuntimeException("The class '$userInputClass' or '$className' does not exists"); |
|
| 298 | + } |
|
| 292 | 299 | } |
| 293 | 300 | |
| 294 | 301 | $validator = new $className($params); |
@@ -326,21 +333,22 @@ discard block |
||
| 326 | 333 | $v->setTranslator($this->translator); |
| 327 | 334 | $notEmpty = $v->isValid($val); |
| 328 | 335 | |
| 329 | - if (!$required && !$notEmpty) |
|
| 330 | - return null; |
|
| 336 | + if (!$required && !$notEmpty) { |
|
| 337 | + return null; |
|
| 338 | + } |
|
| 331 | 339 | |
| 332 | 340 | $valid = $validator->isValid($val); |
| 333 | 341 | $this->setValid($valid); |
| 334 | 342 | |
| 335 | 343 | if (!$valid) |
| 336 | 344 | { |
| 337 | - if (!in_array($key, array_keys($this->messages))) |
|
| 338 | - $this->messages[$key] = array(); |
|
| 345 | + if (!in_array($key, array_keys($this->messages))) { |
|
| 346 | + $this->messages[$key] = array(); |
|
| 347 | + } |
|
| 339 | 348 | |
| 340 | 349 | $this->messages[$key] = array_merge($this->messages[$key], $validator->getMessages()); |
| 341 | 350 | } |
| 342 | - } |
|
| 343 | - else { |
|
| 351 | + } else { |
|
| 344 | 352 | foreach ($form_value as $val) |
| 345 | 353 | { |
| 346 | 354 | $this->_validate($validator, $val, $key, $required); |
@@ -108,8 +108,9 @@ discard block |
||
| 108 | 108 | |
| 109 | 109 | foreach ($attribs[$label] as $attrib) |
| 110 | 110 | { |
| 111 | - if ($attrib->getName() == $name) |
|
| 112 | - return $attrib; |
|
| 111 | + if ($attrib->getName() == $name) { |
|
| 112 | + return $attrib; |
|
| 113 | + } |
|
| 113 | 114 | } |
| 114 | 115 | } |
| 115 | 116 | |
@@ -129,12 +130,12 @@ discard block |
||
| 129 | 130 | if (array_key_exists($label, $attribs)) |
| 130 | 131 | { |
| 131 | 132 | |
| 132 | - if (!array_key_exists($name, $attribs)) |
|
| 133 | - $this->attributes[$label][] = new Attribute($name, $value); |
|
| 134 | - else |
|
| 135 | - $this->getAttribute($label, $name)->setValue($value); |
|
| 136 | - } |
|
| 137 | - else { |
|
| 133 | + if (!array_key_exists($name, $attribs)) { |
|
| 134 | + $this->attributes[$label][] = new Attribute($name, $value); |
|
| 135 | + } else { |
|
| 136 | + $this->getAttribute($label, $name)->setValue($value); |
|
| 137 | + } |
|
| 138 | + } else { |
|
| 138 | 139 | $this->attributes[$label][] = new Attribute($name, $value); |
| 139 | 140 | } |
| 140 | 141 | } |
@@ -166,8 +167,9 @@ discard block |
||
| 166 | 167 | */ |
| 167 | 168 | public function __construct($options) |
| 168 | 169 | { |
| 169 | - if (!array_key_exists('endTag', $options)) |
|
| 170 | - $this->setEndTag(false); |
|
| 170 | + if (!array_key_exists('endTag', $options)) { |
|
| 171 | + $this->setEndTag(false); |
|
| 172 | + } |
|
| 171 | 173 | |
| 172 | 174 | foreach ($options as $key => $value) |
| 173 | 175 | { |
@@ -76,11 +76,13 @@ discard block |
||
| 76 | 76 | $event = $eventHandlers; |
| 77 | 77 | $clousure = function(){}; |
| 78 | 78 | |
| 79 | - if (!array_key_exists('success', $event)) |
|
| 80 | - $event["success"] = $clousure; |
|
| 79 | + if (!array_key_exists('success', $event)) { |
|
| 80 | + $event["success"] = $clousure; |
|
| 81 | + } |
|
| 81 | 82 | |
| 82 | - if (!array_key_exists('error', $event)) |
|
| 83 | - $event["error"] = $clousure; |
|
| 83 | + if (!array_key_exists('error', $event)) { |
|
| 84 | + $event["error"] = $clousure; |
|
| 85 | + } |
|
| 84 | 86 | |
| 85 | 87 | $listener = false; |
| 86 | 88 | |
@@ -90,8 +92,7 @@ discard block |
||
| 90 | 92 | $this->error($errno, socket_strerror($errno)); |
| 91 | 93 | |
| 92 | 94 | throw new \RuntimeException("Could not set socket to listen"); |
| 93 | - } |
|
| 94 | - else { |
|
| 95 | + } else { |
|
| 95 | 96 | |
| 96 | 97 | echo "\n"; |
| 97 | 98 | echo "Server Started : " . date('Y-m-d H:i:s') . "\n"; |
@@ -116,8 +117,9 @@ discard block |
||
| 116 | 117 | socket_close($spawn); |
| 117 | 118 | } |
| 118 | 119 | |
| 119 | - if (!$listener) |
|
| 120 | - call_user_func($event["error"], $this->getLastError()); |
|
| 120 | + if (!$listener) { |
|
| 121 | + call_user_func($event["error"], $this->getLastError()); |
|
| 122 | + } |
|
| 121 | 123 | |
| 122 | 124 | return $listener; |
| 123 | 125 | } |
@@ -26,18 +26,18 @@ discard block |
||
| 26 | 26 | * |
| 27 | 27 | * @return string |
| 28 | 28 | */ |
| 29 | - public function read($socket) |
|
| 30 | - { |
|
| 31 | - if (($message = @socket_read($socket, 1024)) === false) |
|
| 32 | - { |
|
| 33 | - $errno = socket_last_error(); |
|
| 34 | - $this->error($errno, socket_strerror($errno)); |
|
| 29 | + public function read($socket) |
|
| 30 | + { |
|
| 31 | + if (($message = @socket_read($socket, 1024)) === false) |
|
| 32 | + { |
|
| 33 | + $errno = socket_last_error(); |
|
| 34 | + $this->error($errno, socket_strerror($errno)); |
|
| 35 | 35 | |
| 36 | - throw new \RuntimeException("Could not read message from client socket"); |
|
| 37 | - } |
|
| 36 | + throw new \RuntimeException("Could not read message from client socket"); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - return $message; |
|
| 40 | - } |
|
| 39 | + return $message; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * Sends a message to client socket |
@@ -49,18 +49,18 @@ discard block |
||
| 49 | 49 | * |
| 50 | 50 | * @return integer |
| 51 | 51 | */ |
| 52 | - public function send($socket, $message) |
|
| 53 | - { |
|
| 54 | - if (($bytes = @socket_write($socket, $message, strlen($message))) === false) |
|
| 55 | - { |
|
| 56 | - $errno = socket_last_error(); |
|
| 57 | - $this->error($errno, socket_strerror($errno)); |
|
| 52 | + public function send($socket, $message) |
|
| 53 | + { |
|
| 54 | + if (($bytes = @socket_write($socket, $message, strlen($message))) === false) |
|
| 55 | + { |
|
| 56 | + $errno = socket_last_error(); |
|
| 57 | + $this->error($errno, socket_strerror($errno)); |
|
| 58 | 58 | |
| 59 | - throw new \RuntimeException("Could not send message to the client socket"); |
|
| 60 | - } |
|
| 59 | + throw new \RuntimeException("Could not send message to the client socket"); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - return $bytes; |
|
| 63 | - } |
|
| 62 | + return $bytes; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | 65 | /** |
| 66 | 66 | * Sets socket to listening |
@@ -71,54 +71,54 @@ discard block |
||
| 71 | 71 | * |
| 72 | 72 | * @return boolean |
| 73 | 73 | */ |
| 74 | - public function listen(Array $eventHandlers = array()) |
|
| 75 | - { |
|
| 76 | - $event = $eventHandlers; |
|
| 77 | - $clousure = function(){}; |
|
| 74 | + public function listen(Array $eventHandlers = array()) |
|
| 75 | + { |
|
| 76 | + $event = $eventHandlers; |
|
| 77 | + $clousure = function(){}; |
|
| 78 | 78 | |
| 79 | - if (!array_key_exists('success', $event)) |
|
| 80 | - $event["success"] = $clousure; |
|
| 79 | + if (!array_key_exists('success', $event)) |
|
| 80 | + $event["success"] = $clousure; |
|
| 81 | 81 | |
| 82 | - if (!array_key_exists('error', $event)) |
|
| 83 | - $event["error"] = $clousure; |
|
| 82 | + if (!array_key_exists('error', $event)) |
|
| 83 | + $event["error"] = $clousure; |
|
| 84 | 84 | |
| 85 | - $listener = false; |
|
| 85 | + $listener = false; |
|
| 86 | 86 | |
| 87 | - if (!($listener = @socket_listen($this->socket, 30))) |
|
| 88 | - { |
|
| 89 | - $errno = socket_last_error(); |
|
| 90 | - $this->error($errno, socket_strerror($errno)); |
|
| 87 | + if (!($listener = @socket_listen($this->socket, 30))) |
|
| 88 | + { |
|
| 89 | + $errno = socket_last_error(); |
|
| 90 | + $this->error($errno, socket_strerror($errno)); |
|
| 91 | 91 | |
| 92 | - throw new \RuntimeException("Could not set socket to listen"); |
|
| 93 | - } |
|
| 94 | - else { |
|
| 92 | + throw new \RuntimeException("Could not set socket to listen"); |
|
| 93 | + } |
|
| 94 | + else { |
|
| 95 | 95 | |
| 96 | - echo "\n"; |
|
| 97 | - echo "Server Started : " . date('Y-m-d H:i:s') . "\n"; |
|
| 98 | - echo "Master socket : " . $this->socket . "\n"; |
|
| 99 | - echo "Listening on : " . $this->host . " port " . $this->port . "\n\n"; |
|
| 96 | + echo "\n"; |
|
| 97 | + echo "Server Started : " . date('Y-m-d H:i:s') . "\n"; |
|
| 98 | + echo "Master socket : " . $this->socket . "\n"; |
|
| 99 | + echo "Listening on : " . $this->host . " port " . $this->port . "\n\n"; |
|
| 100 | 100 | |
| 101 | - $socket = $this->socket; |
|
| 101 | + $socket = $this->socket; |
|
| 102 | 102 | |
| 103 | - if (!($spawn = @socket_accept($this->socket))) |
|
| 104 | - { |
|
| 105 | - $errno = socket_last_error(); |
|
| 106 | - $this->error($errno, socket_strerror($errno)); |
|
| 103 | + if (!($spawn = @socket_accept($this->socket))) |
|
| 104 | + { |
|
| 105 | + $errno = socket_last_error(); |
|
| 106 | + $this->error($errno, socket_strerror($errno)); |
|
| 107 | 107 | |
| 108 | - throw new \RuntimeException("Could not accept incoming connection"); |
|
| 109 | - } |
|
| 108 | + throw new \RuntimeException("Could not accept incoming connection"); |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - $input = $this->read($spawn); |
|
| 111 | + $input = $this->read($spawn); |
|
| 112 | 112 | |
| 113 | - $input = trim($input); |
|
| 114 | - call_user_func($event["success"], $input, $this, $spawn); |
|
| 113 | + $input = trim($input); |
|
| 114 | + call_user_func($event["success"], $input, $this, $spawn); |
|
| 115 | 115 | |
| 116 | - socket_close($spawn); |
|
| 117 | - } |
|
| 116 | + socket_close($spawn); |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - if (!$listener) |
|
| 120 | - call_user_func($event["error"], $this->getLastError()); |
|
| 119 | + if (!$listener) |
|
| 120 | + call_user_func($event["error"], $this->getLastError()); |
|
| 121 | 121 | |
| 122 | - return $listener; |
|
| 123 | - } |
|
| 122 | + return $listener; |
|
| 123 | + } |
|
| 124 | 124 | } |
| 125 | 125 | \ No newline at end of file |
@@ -127,8 +127,9 @@ |
||
| 127 | 127 | { |
| 128 | 128 | $codes = $this->httpStatusCodes; |
| 129 | 129 | |
| 130 | - if (!in_array($code, array_keys($codes))) |
|
| 131 | - throw new \LogicException("Status code not supported"); |
|
| 130 | + if (!in_array($code, array_keys($codes))) { |
|
| 131 | + throw new \LogicException("Status code not supported"); |
|
| 132 | + } |
|
| 132 | 133 | |
| 133 | 134 | return $this->httpStatusCodes[$code]; |
| 134 | 135 | } |
@@ -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; |
@@ -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 | /** |
@@ -22,10 +22,10 @@ |
||
| 22 | 22 | * |
| 23 | 23 | * @var integer |
| 24 | 24 | */ |
| 25 | - const FILE_PERMISSION_DENIED = 1; |
|
| 26 | - const FILE_NOT_FOUND = 2; |
|
| 27 | - const FILE_EXISTS = 3; |
|
| 28 | - const NOT_DIRECTORY = 4; |
|
| 25 | + const FILE_PERMISSION_DENIED = 1; |
|
| 26 | + const FILE_NOT_FOUND = 2; |
|
| 27 | + const FILE_EXISTS = 3; |
|
| 28 | + const NOT_DIRECTORY = 4; |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * Common JSON errors |
@@ -67,12 +67,13 @@ |
||
| 67 | 67 | */ |
| 68 | 68 | protected function error($code, $message = null) |
| 69 | 69 | { |
| 70 | - if (!array_key_exists($code, $this->errors)) |
|
| 71 | - $this->errors[$code] = (array_key_exists($code, $this->standardErrors)) |
|
| 70 | + if (!array_key_exists($code, $this->errors)) { |
|
| 71 | + $this->errors[$code] = (array_key_exists($code, $this->standardErrors)) |
|
| 72 | 72 | ? |
| 73 | 73 | is_null($message) |
| 74 | 74 | ? $this->standardErrors[$code] |
| 75 | 75 | : preg_replace('/%[a-zA-Z]*%/', $message, $this->standardErrors[$code]) |
| 76 | 76 | : $message; |
| 77 | + } |
|
| 77 | 78 | } |
| 78 | 79 | } |
| 79 | 80 | \ No newline at end of file |