@@ -189,6 +189,9 @@ |
||
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | |
| 192 | + /** |
|
| 193 | + * @param string $value |
|
| 194 | + */ |
|
| 192 | 195 | public function setLanguage($value) { |
| 193 | 196 | if (!empty($value)) |
| 194 | 197 | $this->meta['language'] = strtolower((string)$value); |
@@ -63,8 +63,9 @@ discard block |
||
| 63 | 63 | * @brief Removes `_design/` from he document identifier. |
| 64 | 64 | */ |
| 65 | 65 | protected function fixDocId() { |
| 66 | - if (isset($this->meta['_id'])) |
|
| 67 | - $this->meta['_id'] = preg_replace('%\A_design/%m', "", $this->meta['_id']); |
|
| 66 | + if (isset($this->meta['_id'])) { |
|
| 67 | + $this->meta['_id'] = preg_replace('%\A_design/%m', "", $this->meta['_id']); |
|
| 68 | + } |
|
| 68 | 69 | } |
| 69 | 70 | |
| 70 | 71 | |
@@ -94,8 +95,9 @@ discard block |
||
| 94 | 95 | */ |
| 95 | 96 | public function resetHandlers() { |
| 96 | 97 | foreach ($this->sections as $name => $value) { |
| 97 | - if (array_key_exists($name, $this->meta)) |
|
| 98 | - unset($this->meta[$name]); |
|
| 98 | + if (array_key_exists($name, $this->meta)) { |
|
| 99 | + unset($this->meta[$name]); |
|
| 100 | + } |
|
| 99 | 101 | } |
| 100 | 102 | } |
| 101 | 103 | |
@@ -108,16 +110,17 @@ discard block |
||
| 108 | 110 | */ |
| 109 | 111 | public function getHandlerAttributes($section, $name = "") { |
| 110 | 112 | if (empty($name)) { // The handler doesn't have a name. |
| 111 | - if (array_key_exists($section, $this->meta)) |
|
| 112 | - return $this->meta[$section]; |
|
| 113 | - else |
|
| 114 | - throw new \Exception(sprintf("Can't find '%s' handler in the design document.", $section)); |
|
| 115 | - } |
|
| 116 | - else { // The handler has a name. |
|
| 117 | - if (@array_key_exists($name, $this->meta[$section])) |
|
| 118 | - return $this->meta[$section][$name]; |
|
| 119 | - else |
|
| 120 | - throw new \Exception(sprintf("Can't find '%s' handler in the design document '%s' section.", $name, $section)); |
|
| 113 | + if (array_key_exists($section, $this->meta)) { |
|
| 114 | + return $this->meta[$section]; |
|
| 115 | + } else { |
|
| 116 | + throw new \Exception(sprintf("Can't find '%s' handler in the design document.", $section)); |
|
| 117 | + } |
|
| 118 | + } else { // The handler has a name. |
|
| 119 | + if (@array_key_exists($name, $this->meta[$section])) { |
|
| 120 | + return $this->meta[$section][$name]; |
|
| 121 | + } else { |
|
| 122 | + throw new \Exception(sprintf("Can't find '%s' handler in the design document '%s' section.", $name, $section)); |
|
| 123 | + } |
|
| 121 | 124 | } |
| 122 | 125 | } |
| 123 | 126 | |
@@ -133,22 +136,25 @@ discard block |
||
| 133 | 136 | $section = $handler->getSection(); |
| 134 | 137 | |
| 135 | 138 | if (property_exists($handler, "name")) { |
| 136 | - if (!$handler->isConsistent()) |
|
| 137 | - throw new \Exception(sprintf("The '%s' handler '%s' is not consistent.", $section, $handler->name)); |
|
| 138 | - |
|
| 139 | - if (@array_key_exists($handler->name, $this->meta[$section])) |
|
| 140 | - throw new \Exception(sprintf("The '%s' handler '%s' already exists.", $section, $handler->name)); |
|
| 141 | - else |
|
| 142 | - $this->meta[$section][$handler->name] = $handler->asArray(); |
|
| 143 | - } |
|
| 144 | - else { |
|
| 145 | - if (!$handler->isConsistent()) |
|
| 146 | - throw new \Exception(sprintf("The '%s' handler is not consistent.", $section)); |
|
| 147 | - |
|
| 148 | - if (array_key_exists($section, $this->meta)) |
|
| 149 | - throw new \Exception(sprintf("The '%s' handler already exists.", $section)); |
|
| 150 | - else |
|
| 151 | - $this->meta[$section] = $handler; |
|
| 139 | + if (!$handler->isConsistent()) { |
|
| 140 | + throw new \Exception(sprintf("The '%s' handler '%s' is not consistent.", $section, $handler->name)); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + if (@array_key_exists($handler->name, $this->meta[$section])) { |
|
| 144 | + throw new \Exception(sprintf("The '%s' handler '%s' already exists.", $section, $handler->name)); |
|
| 145 | + } else { |
|
| 146 | + $this->meta[$section][$handler->name] = $handler->asArray(); |
|
| 147 | + } |
|
| 148 | + } else { |
|
| 149 | + if (!$handler->isConsistent()) { |
|
| 150 | + throw new \Exception(sprintf("The '%s' handler is not consistent.", $section)); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + if (array_key_exists($section, $this->meta)) { |
|
| 154 | + throw new \Exception(sprintf("The '%s' handler already exists.", $section)); |
|
| 155 | + } else { |
|
| 156 | + $this->meta[$section] = $handler; |
|
| 157 | + } |
|
| 152 | 158 | } |
| 153 | 159 | } |
| 154 | 160 | |
@@ -163,16 +169,17 @@ discard block |
||
| 163 | 169 | */ |
| 164 | 170 | public function removeHandler($section, $name = "") { |
| 165 | 171 | if (empty($name)) { // The handler doesn't have a name. |
| 166 | - if (array_key_exists($section, $this->meta)) |
|
| 167 | - unset($this->meta[$section]); |
|
| 168 | - else |
|
| 169 | - throw new \Exception(sprintf("Can't find the '%s' handler.", $section)); |
|
| 170 | - } |
|
| 171 | - else { // The handler has a name. |
|
| 172 | - if (@array_key_exists($name, $this->meta[$section])) |
|
| 173 | - unset($this->meta[$section][$name]); |
|
| 174 | - else |
|
| 175 | - throw new \Exception(sprintf("Can't find the '%s' handler '%s'", $section, $name)); |
|
| 172 | + if (array_key_exists($section, $this->meta)) { |
|
| 173 | + unset($this->meta[$section]); |
|
| 174 | + } else { |
|
| 175 | + throw new \Exception(sprintf("Can't find the '%s' handler.", $section)); |
|
| 176 | + } |
|
| 177 | + } else { // The handler has a name. |
|
| 178 | + if (@array_key_exists($name, $this->meta[$section])) { |
|
| 179 | + unset($this->meta[$section][$name]); |
|
| 180 | + } else { |
|
| 181 | + throw new \Exception(sprintf("Can't find the '%s' handler '%s'", $section, $name)); |
|
| 182 | + } |
|
| 176 | 183 | } |
| 177 | 184 | } |
| 178 | 185 | |
@@ -190,16 +197,18 @@ discard block |
||
| 190 | 197 | |
| 191 | 198 | |
| 192 | 199 | public function setLanguage($value) { |
| 193 | - if (!empty($value)) |
|
| 194 | - $this->meta['language'] = strtolower((string)$value); |
|
| 195 | - else |
|
| 196 | - throw new \InvalidArgumentException("\$language must be a non-empty string."); |
|
| 200 | + if (!empty($value)) { |
|
| 201 | + $this->meta['language'] = strtolower((string)$value); |
|
| 202 | + } else { |
|
| 203 | + throw new \InvalidArgumentException("\$language must be a non-empty string."); |
|
| 204 | + } |
|
| 197 | 205 | } |
| 198 | 206 | |
| 199 | 207 | |
| 200 | 208 | public function unsetLanguage() { |
| 201 | - if ($this->isMetadataPresent('language')) |
|
| 202 | - unset($this->meta['language']); |
|
| 209 | + if ($this->isMetadataPresent('language')) { |
|
| 210 | + unset($this->meta['language']); |
|
| 211 | + } |
|
| 203 | 212 | } |
| 204 | 213 | |
| 205 | 214 | //! @endcond |
@@ -162,6 +162,11 @@ discard block |
||
| 162 | 162 | /* |
| 163 | 163 | * Public API, convert a UUID from one format to another |
| 164 | 164 | */ |
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @param integer $from |
|
| 168 | + * @param integer $to |
|
| 169 | + */ |
|
| 165 | 170 | static public function convert($uuid, $from, $to) { |
| 166 | 171 | $conv = self::$m_convert[$from][$to]; |
| 167 | 172 | if (!isset($conv)) |
@@ -189,6 +194,11 @@ discard block |
||
| 189 | 194 | /* |
| 190 | 195 | * Generate UUID version 3 and 5 (name based) |
| 191 | 196 | */ |
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * @param string $hash |
|
| 200 | + * @param integer $version |
|
| 201 | + */ |
|
| 192 | 202 | static private function generateName($ns, $node, $hash, $version) { |
| 193 | 203 | $ns_fmt = self::detectFormat($ns); |
| 194 | 204 | $field = self::convert($ns, $ns_fmt, self::FMT_FIELD); |
@@ -67,29 +67,29 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | class UUID { |
| 69 | 69 | /* UUID versions */ |
| 70 | - const UUID_TIME = 1; /* Time based UUID */ |
|
| 71 | - const UUID_NAME_MD5 = 3; /* Name based (MD5) UUID */ |
|
| 72 | - const UUID_RANDOM = 4; /* Random UUID */ |
|
| 73 | - const UUID_NAME_SHA1 = 5; /* Name based (SHA1) UUID */ |
|
| 70 | + const UUID_TIME = 1; /* Time based UUID */ |
|
| 71 | + const UUID_NAME_MD5 = 3; /* Name based (MD5) UUID */ |
|
| 72 | + const UUID_RANDOM = 4; /* Random UUID */ |
|
| 73 | + const UUID_NAME_SHA1 = 5; /* Name based (SHA1) UUID */ |
|
| 74 | 74 | |
| 75 | 75 | /* UUID formats */ |
| 76 | 76 | const FMT_FIELD = 100; |
| 77 | 77 | const FMT_STRING = 101; |
| 78 | 78 | const FMT_BINARY = 102; |
| 79 | - const FMT_QWORD = 1; /* Quad-word, 128-bit (not impl.) */ |
|
| 80 | - const FMT_DWORD = 2; /* Double-word, 64-bit (not impl.) */ |
|
| 81 | - const FMT_WORD = 4; /* Word, 32-bit (not impl.) */ |
|
| 82 | - const FMT_SHORT = 8; /* Short (not impl.) */ |
|
| 83 | - const FMT_BYTE = 16; /* Byte */ |
|
| 84 | - const FMT_DEFAULT = 16; |
|
| 79 | + const FMT_QWORD = 1; /* Quad-word, 128-bit (not impl.) */ |
|
| 80 | + const FMT_DWORD = 2; /* Double-word, 64-bit (not impl.) */ |
|
| 81 | + const FMT_WORD = 4; /* Word, 32-bit (not impl.) */ |
|
| 82 | + const FMT_SHORT = 8; /* Short (not impl.) */ |
|
| 83 | + const FMT_BYTE = 16; /* Byte */ |
|
| 84 | + const FMT_DEFAULT = 16; |
|
| 85 | 85 | |
| 86 | 86 | /* Field UUID representation */ |
| 87 | 87 | static private $m_uuid_field = array( |
| 88 | - 'time_low' => 0, /* 32-bit */ |
|
| 89 | - 'time_mid' => 0, /* 16-bit */ |
|
| 90 | - 'time_hi' => 0, /* 16-bit */ |
|
| 91 | - 'clock_seq_hi' => 0, /* 8-bit */ |
|
| 92 | - 'clock_seq_low' => 0, /* 8-bit */ |
|
| 88 | + 'time_low' => 0, /* 32-bit */ |
|
| 89 | + 'time_mid' => 0, /* 16-bit */ |
|
| 90 | + 'time_hi' => 0, /* 16-bit */ |
|
| 91 | + 'clock_seq_hi' => 0, /* 8-bit */ |
|
| 92 | + 'clock_seq_low' => 0, /* 8-bit */ |
|
| 93 | 93 | 'node' => array() /* 48-bit */ |
| 94 | 94 | ); |
| 95 | 95 | |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | $uuid[9] = $src['clock_seq_low']; |
| 285 | 285 | |
| 286 | 286 | for ($i = 0; $i < 6; $i++) |
| 287 | - $uuid[10+$i] = $src['node'][$i]; |
|
| 287 | + $uuid[10 + $i] = $src['node'][$i]; |
|
| 288 | 288 | |
| 289 | 289 | return ($uuid); |
| 290 | 290 | } |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | $field['clock_seq_low'] = $uuid[9]; |
| 315 | 315 | |
| 316 | 316 | for ($i = 0; $i < 6; $i++) |
| 317 | - $field['node'][$i] = $uuid[10+$i]; |
|
| 317 | + $field['node'][$i] = $uuid[10 + $i]; |
|
| 318 | 318 | return ($field); |
| 319 | 319 | } |
| 320 | 320 | |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | $field['clock_seq_hi'] = ($parts[3] & 0xff00) >> 8; |
| 340 | 340 | $field['clock_seq_low'] = $parts[3] & 0x00ff; |
| 341 | 341 | for ($i = 0; $i < 6; $i++) |
| 342 | - $field['node'][$i] = $parts[4+$i]; |
|
| 342 | + $field['node'][$i] = $parts[4 + $i]; |
|
| 343 | 343 | |
| 344 | 344 | return ($field); |
| 345 | 345 | } |
@@ -131,17 +131,18 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | /* Auto-detect UUID format */ |
| 133 | 133 | static private function detectFormat($src) { |
| 134 | - if (is_string($src)) |
|
| 135 | - return self::FMT_STRING; |
|
| 136 | - else if (is_array($src)) { |
|
| 134 | + if (is_string($src)) { |
|
| 135 | + return self::FMT_STRING; |
|
| 136 | + } else if (is_array($src)) { |
|
| 137 | 137 | $len = count($src); |
| 138 | - if ($len == 1 || ($len % 2) == 0) |
|
| 139 | - return $len; |
|
| 140 | - else |
|
| 141 | - return (-1); |
|
| 138 | + if ($len == 1 || ($len % 2) == 0) { |
|
| 139 | + return $len; |
|
| 140 | + } else { |
|
| 141 | + return (-1); |
|
| 142 | + } |
|
| 143 | + } else { |
|
| 144 | + return self::FMT_BINARY; |
|
| 142 | 145 | } |
| 143 | - else |
|
| 144 | - return self::FMT_BINARY; |
|
| 145 | 146 | } |
| 146 | 147 | |
| 147 | 148 | /* |
@@ -151,8 +152,9 @@ discard block |
||
| 151 | 152 | static public function generate($type, $fmt = self::FMT_BYTE, |
| 152 | 153 | $node = "", $ns = "") { |
| 153 | 154 | $func = self::$m_generate[$type]; |
| 154 | - if (!isset($func)) |
|
| 155 | - return null; |
|
| 155 | + if (!isset($func)) { |
|
| 156 | + return null; |
|
| 157 | + } |
|
| 156 | 158 | $conv = self::$m_convert[self::FMT_FIELD][$fmt]; |
| 157 | 159 | |
| 158 | 160 | $uuid = self::$func($ns, $node); |
@@ -164,8 +166,9 @@ discard block |
||
| 164 | 166 | */ |
| 165 | 167 | static public function convert($uuid, $from, $to) { |
| 166 | 168 | $conv = self::$m_convert[$from][$to]; |
| 167 | - if (!isset($conv)) |
|
| 168 | - return ($uuid); |
|
| 169 | + if (!isset($conv)) { |
|
| 170 | + return ($uuid); |
|
| 171 | + } |
|
| 169 | 172 | |
| 170 | 173 | return (self::$conv($uuid)); |
| 171 | 174 | } |
@@ -181,8 +184,9 @@ discard block |
||
| 181 | 184 | $uuid['time_low'] = mt_rand(0, 0xffff) + (mt_rand(0, 0xffff) << 16); |
| 182 | 185 | $uuid['time_mid'] = mt_rand(0, 0xffff); |
| 183 | 186 | $uuid['clock_seq_low'] = mt_rand(0, 255); |
| 184 | - for ($i = 0; $i < 6; $i++) |
|
| 185 | - $uuid['node'][$i] = mt_rand(0, 255); |
|
| 187 | + for ($i = 0; $i < 6; $i++) { |
|
| 188 | + $uuid['node'][$i] = mt_rand(0, 255); |
|
| 189 | + } |
|
| 186 | 190 | return ($uuid); |
| 187 | 191 | } |
| 188 | 192 | |
@@ -205,8 +209,9 @@ discard block |
||
| 205 | 209 | /* Hash the namespace and node and convert to a byte array */ |
| 206 | 210 | $val = $hash($raw, true); |
| 207 | 211 | $tmp = unpack('C16', $val); |
| 208 | - foreach (array_keys($tmp) as $key) |
|
| 209 | - $byte[$key - 1] = $tmp[$key]; |
|
| 212 | + foreach (array_keys($tmp) as $key) { |
|
| 213 | + $byte[$key - 1] = $tmp[$key]; |
|
| 214 | + } |
|
| 210 | 215 | |
| 211 | 216 | /* Convert byte array to a field array */ |
| 212 | 217 | $field = self::conv_byte2field($byte); |
@@ -264,8 +269,9 @@ discard block |
||
| 264 | 269 | * Node should be set to the 48-bit IEEE node identifier, but |
| 265 | 270 | * we leave it for the user to supply the node. |
| 266 | 271 | */ |
| 267 | - for ($i = 0; $i < 6; $i++) |
|
| 268 | - $uuid['node'][$i] = ord(substr($node, $i, 1)); |
|
| 272 | + for ($i = 0; $i < 6; $i++) { |
|
| 273 | + $uuid['node'][$i] = ord(substr($node, $i, 1)); |
|
| 274 | + } |
|
| 269 | 275 | |
| 270 | 276 | return ($uuid); |
| 271 | 277 | } |
@@ -283,8 +289,9 @@ discard block |
||
| 283 | 289 | $uuid[8] = $src['clock_seq_hi']; |
| 284 | 290 | $uuid[9] = $src['clock_seq_low']; |
| 285 | 291 | |
| 286 | - for ($i = 0; $i < 6; $i++) |
|
| 287 | - $uuid[10+$i] = $src['node'][$i]; |
|
| 292 | + for ($i = 0; $i < 6; $i++) { |
|
| 293 | + $uuid[10+$i] = $src['node'][$i]; |
|
| 294 | + } |
|
| 288 | 295 | |
| 289 | 296 | return ($uuid); |
| 290 | 297 | } |
@@ -313,8 +320,9 @@ discard block |
||
| 313 | 320 | $field['clock_seq_hi'] = $uuid[8]; |
| 314 | 321 | $field['clock_seq_low'] = $uuid[9]; |
| 315 | 322 | |
| 316 | - for ($i = 0; $i < 6; $i++) |
|
| 317 | - $field['node'][$i] = $uuid[10+$i]; |
|
| 323 | + for ($i = 0; $i < 6; $i++) { |
|
| 324 | + $field['node'][$i] = $uuid[10+$i]; |
|
| 325 | + } |
|
| 318 | 326 | return ($field); |
| 319 | 327 | } |
| 320 | 328 | |
@@ -338,8 +346,9 @@ discard block |
||
| 338 | 346 | $field['time_hi'] = ($parts[2]); |
| 339 | 347 | $field['clock_seq_hi'] = ($parts[3] & 0xff00) >> 8; |
| 340 | 348 | $field['clock_seq_low'] = $parts[3] & 0x00ff; |
| 341 | - for ($i = 0; $i < 6; $i++) |
|
| 342 | - $field['node'][$i] = $parts[4+$i]; |
|
| 349 | + for ($i = 0; $i < 6; $i++) { |
|
| 350 | + $field['node'][$i] = $parts[4+$i]; |
|
| 351 | + } |
|
| 343 | 352 | |
| 344 | 353 | return ($field); |
| 345 | 354 | } |
@@ -54,6 +54,7 @@ |
||
| 54 | 54 | * @brief Converts the given JSON into an array. |
| 55 | 55 | * @param[in] string $json A JSON object. |
| 56 | 56 | * @param[in] bool $assoc When `true`, returned objects will be converted into associative arrays. |
| 57 | + * @param boolean $assoc |
|
| 57 | 58 | * @retval array |
| 58 | 59 | */ |
| 59 | 60 | public static function fromJson($json, $assoc) { |
@@ -59,10 +59,11 @@ |
||
| 59 | 59 | public static function fromJson($json, $assoc) { |
| 60 | 60 | $data = json_decode((string)$json, $assoc); |
| 61 | 61 | |
| 62 | - if (is_null($data)) |
|
| 63 | - switch (json_last_error()) { |
|
| 62 | + if (is_null($data)) { |
|
| 63 | + switch (json_last_error()) { |
|
| 64 | 64 | case JSON_ERROR_DEPTH: |
| 65 | 65 | throw new JSONErrorException("Unable to parse the given JSON, the maximum stack depth has been exceeded."); |
| 66 | + } |
|
| 66 | 67 | break; |
| 67 | 68 | case JSON_ERROR_STATE_MISMATCH: |
| 68 | 69 | throw new JSONErrorException("Unable to parse the given JSON, invalid or malformed JSON."); |
@@ -266,6 +266,7 @@ discard block |
||
| 266 | 266 | * @param[in] string $path The absolute path of the request. |
| 267 | 267 | * @param[in] string $queryParams (optional) Associative array of query parameters. |
| 268 | 268 | * @param[in] string $headerFields (optional) Associative array of header fields. |
| 269 | + * @param string $path |
|
| 269 | 270 | */ |
| 270 | 271 | public function __construct($method, $path, array $queryParams = NULL, array $headerFields = NULL) { |
| 271 | 272 | parent::__construct(); |
@@ -419,6 +420,8 @@ discard block |
||
| 419 | 420 | * @brief This helper forces request to use the Authorization Basic mode. |
| 420 | 421 | * @param[in] string $userName User name. |
| 421 | 422 | * @param[in] string $password Password. |
| 423 | + * @param string $userName |
|
| 424 | + * @param string $password |
|
| 422 | 425 | */ |
| 423 | 426 | public function setBasicAuth($userName, $password) { |
| 424 | 427 | $this->setHeaderField(self::AUTHORIZATION_HF, "Basic ".base64_encode("$userName:$password")); |
@@ -189,9 +189,9 @@ discard block |
||
| 189 | 189 | */ |
| 190 | 190 | const X_FORWARDED_FOR_HF = "X-Forwarded-For"; |
| 191 | 191 | |
| 192 | - const DESTINATION_HF = "Destination"; //!< This header field is not supported by HTTP 1.1. It's a special header field used by CouchDB. |
|
| 193 | - const X_COUCHDB_WWW_AUTHENTICATE_HF = "X-CouchDB-WWW-Authenticate"; //!< This header field is not supported by HTTP 1.1. It's a special method header field by CouchDB. |
|
| 194 | - const X_COUCHDB_FULL_COMMIT_HF = "X-Couch-Full-Commit"; //!< This header field is not supported by HTTP 1.1. It's a special header field used by CouchDB. |
|
| 192 | + const DESTINATION_HF = "Destination"; //!< This header field is not supported by HTTP 1.1. It's a special header field used by CouchDB. |
|
| 193 | + const X_COUCHDB_WWW_AUTHENTICATE_HF = "X-CouchDB-WWW-Authenticate"; //!< This header field is not supported by HTTP 1.1. It's a special method header field by CouchDB. |
|
| 194 | + const X_COUCHDB_FULL_COMMIT_HF = "X-Couch-Full-Commit"; //!< This header field is not supported by HTTP 1.1. It's a special header field used by CouchDB. |
|
| 195 | 195 | |
| 196 | 196 | //!@} |
| 197 | 197 | |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | $params = explode('&', $query); |
| 409 | 409 | |
| 410 | 410 | foreach ($params as $param) { |
| 411 | - @list($name, $value) = explode('=', $param, 2); |
|
| 411 | + @list($name, $value) = explode('=', $param, 2); |
|
| 412 | 412 | $this->setQueryParam($name, $value); |
| 413 | 413 | } |
| 414 | 414 | } |
@@ -281,11 +281,13 @@ discard block |
||
| 281 | 281 | $this->setMethod($method); |
| 282 | 282 | $this->setPath($path); |
| 283 | 283 | |
| 284 | - if (isset($queryParams)) |
|
| 285 | - $this->setMultipleQueryParamsAtOnce($queryParams); |
|
| 284 | + if (isset($queryParams)) { |
|
| 285 | + $this->setMultipleQueryParamsAtOnce($queryParams); |
|
| 286 | + } |
|
| 286 | 287 | |
| 287 | - if (isset($headerFields)) |
|
| 288 | - $this->setMultipleHeaderFieldsAtOnce($headerFields); |
|
| 288 | + if (isset($headerFields)) { |
|
| 289 | + $this->setMultipleHeaderFieldsAtOnce($headerFields); |
|
| 290 | + } |
|
| 289 | 291 | } |
| 290 | 292 | |
| 291 | 293 | |
@@ -318,10 +320,11 @@ discard block |
||
| 318 | 320 | * @param[in] string $method The HTTP method for the request. You should use one of the public constants, like GET_METHOD. |
| 319 | 321 | */ |
| 320 | 322 | public function setMethod($method) { |
| 321 | - if (array_key_exists($method, self::$supportedMethods)) |
|
| 322 | - $this->method = $method; |
|
| 323 | - else |
|
| 324 | - throw new \UnexpectedValueException("$method method not supported. Use addCustomMethod() to add an unsupported method."); |
|
| 323 | + if (array_key_exists($method, self::$supportedMethods)) { |
|
| 324 | + $this->method = $method; |
|
| 325 | + } else { |
|
| 326 | + throw new \UnexpectedValueException("$method method not supported. Use addCustomMethod() to add an unsupported method."); |
|
| 327 | + } |
|
| 325 | 328 | } |
| 326 | 329 | |
| 327 | 330 | |
@@ -330,10 +333,11 @@ discard block |
||
| 330 | 333 | * @param[in] string $method The HTTP custom method. |
| 331 | 334 | */ |
| 332 | 335 | public static function addCustomMethod($method) { |
| 333 | - if (array_key_exists($method, self::$supportedMethods)) |
|
| 334 | - throw new \UnexpectedValueException("$method method is supported and already exists."); |
|
| 335 | - else |
|
| 336 | - self::$supportedMethods[] = $method; |
|
| 336 | + if (array_key_exists($method, self::$supportedMethods)) { |
|
| 337 | + throw new \UnexpectedValueException("$method method is supported and already exists."); |
|
| 338 | + } else { |
|
| 339 | + self::$supportedMethods[] = $method; |
|
| 340 | + } |
|
| 337 | 341 | } |
| 338 | 342 | |
| 339 | 343 | |
@@ -351,10 +355,11 @@ discard block |
||
| 351 | 355 | * @param[in] string $path The absolute path of the request. |
| 352 | 356 | */ |
| 353 | 357 | public function setPath($path) { |
| 354 | - if (is_string($path)) |
|
| 355 | - $this->path = addslashes($path); |
|
| 356 | - else |
|
| 357 | - throw new \InvalidArgumentException("\$path must be a string."); |
|
| 358 | + if (is_string($path)) { |
|
| 359 | + $this->path = addslashes($path); |
|
| 360 | + } else { |
|
| 361 | + throw new \InvalidArgumentException("\$path must be a string."); |
|
| 362 | + } |
|
| 358 | 363 | } |
| 359 | 364 | |
| 360 | 365 | |
@@ -364,11 +369,12 @@ discard block |
||
| 364 | 369 | * @param[in] string $value Parameter value. |
| 365 | 370 | */ |
| 366 | 371 | public function setQueryParam($name, $value) { |
| 367 | - if (preg_match('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/', $name)) |
|
| 368 | - $this->queryParams[$name] = $value; |
|
| 369 | - else |
|
| 370 | - throw new \InvalidArgumentException("\$name must start with a letter or underscore, followed by any number of |
|
| 372 | + if (preg_match('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/', $name)) { |
|
| 373 | + $this->queryParams[$name] = $value; |
|
| 374 | + } else { |
|
| 375 | + throw new \InvalidArgumentException("\$name must start with a letter or underscore, followed by any number of |
|
| 371 | 376 | letters, numbers, or underscores."); |
| 377 | + } |
|
| 372 | 378 | } |
| 373 | 379 | |
| 374 | 380 | |
@@ -377,11 +383,12 @@ discard block |
||
| 377 | 383 | * @param[in] array $params An associative array of parameters. |
| 378 | 384 | */ |
| 379 | 385 | public function setMultipleQueryParamsAtOnce(array $params) { |
| 380 | - if (Helper\ArrayHelper::isAssociative($params)) |
|
| 381 | - foreach ($params as $name => $value) |
|
| 386 | + if (Helper\ArrayHelper::isAssociative($params)) { |
|
| 387 | + foreach ($params as $name => $value) |
|
| 382 | 388 | $this->setQueryParam($name, $value); |
| 383 | - else |
|
| 384 | - throw new \InvalidArgumentException("\$params must be an associative array."); |
|
| 389 | + } else { |
|
| 390 | + throw new \InvalidArgumentException("\$params must be an associative array."); |
|
| 391 | + } |
|
| 385 | 392 | } |
| 386 | 393 | |
| 387 | 394 | |
@@ -390,11 +397,12 @@ discard block |
||
| 390 | 397 | * @retval string |
| 391 | 398 | */ |
| 392 | 399 | public function getQueryString() { |
| 393 | - if (empty($this->queryParams)) |
|
| 394 | - return ""; |
|
| 395 | - else |
|
| 396 | - // Encoding is based on RFC 3986. |
|
| 400 | + if (empty($this->queryParams)) { |
|
| 401 | + return ""; |
|
| 402 | + } else { |
|
| 403 | + // Encoding is based on RFC 3986. |
|
| 397 | 404 | return "?".http_build_query($this->queryParams, NULL, "&", PHP_QUERY_RFC3986); |
| 405 | + } |
|
| 398 | 406 | } |
| 399 | 407 | |
| 400 | 408 | |
@@ -45,10 +45,11 @@ |
||
| 45 | 45 | * @retval string|bool The codec name or `false` if the attachment is not compressed. |
| 46 | 46 | */ |
| 47 | 47 | public function getContentEncoding() { |
| 48 | - if ($this->response->hasHeaderField(Response::CONTENT_ENCODING_HF)) |
|
| 49 | - return $this->response->getHeaderFieldValue(Response::CONTENT_ENCODING_HF); |
|
| 50 | - else |
|
| 51 | - return FALSE; |
|
| 48 | + if ($this->response->hasHeaderField(Response::CONTENT_ENCODING_HF)) { |
|
| 49 | + return $this->response->getHeaderFieldValue(Response::CONTENT_ENCODING_HF); |
|
| 50 | + } else { |
|
| 51 | + return FALSE; |
|
| 52 | + } |
|
| 52 | 53 | } |
| 53 | 54 | |
| 54 | 55 | |
@@ -100,8 +100,8 @@ |
||
| 100 | 100 | $buffer .= "File Opened Since: ".sprintf($since, $time['days'], $time['hours'], $time['minutes'], $time['seconds']).PHP_EOL; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - $buffer .= "Disk Size: ".round($this->diskSize/(1024*1024*1024), 3)." GB".PHP_EOL; |
|
| 104 | - $buffer .= "Data Size: ".round($this->dataSize/(1024*1024*1024), 3)." GB".PHP_EOL; |
|
| 103 | + $buffer .= "Disk Size: ".round($this->diskSize / (1024 * 1024 * 1024), 3)." GB".PHP_EOL; |
|
| 104 | + $buffer .= "Data Size: ".round($this->dataSize / (1024 * 1024 * 1024), 3)." GB".PHP_EOL; |
|
| 105 | 105 | $buffer .= "Disk Format Version: ".$this->diskFormatVersion.PHP_EOL; |
| 106 | 106 | |
| 107 | 107 | $compactRunning = ($this->compactRunning) ? 'active' : 'inactive'; |
@@ -82,9 +82,9 @@ |
||
| 82 | 82 | $this->purgeSeq = $info['purge_seq']; |
| 83 | 83 | $this->compactRunning = $info['compact_running']; |
| 84 | 84 | $this->committedUpdateSeq = $info['committed_update_seq']; |
| 85 | + } else { |
|
| 86 | + throw new \Exception("\$info must be an associative array."); |
|
| 85 | 87 | } |
| 86 | - else |
|
| 87 | - throw new \Exception("\$info must be an associative array."); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | |
@@ -908,7 +908,7 @@ |
||
| 908 | 908 | * @see http://docs.couchdb.org/en/latest/api/server/common.html#post--_replicate |
| 909 | 909 | */ |
| 910 | 910 | public function startReplication($sourceDbUrl, $targetDbUrl, $proxy = NULL, $createTargetDb = TRUE, |
| 911 | - $continuous = FALSE, $filter = NULL, Opt\ViewQueryOpts $opts = NULL) { |
|
| 911 | + $continuous = FALSE, $filter = NULL, Opt\ViewQueryOpts $opts = NULL) { |
|
| 912 | 912 | // Sets source and target databases. |
| 913 | 913 | if (is_string($sourceDbUrl) && !empty($sourceDbUrl) && |
| 914 | 914 | is_string($targetDbUrl) && !empty($targetDbUrl)) { |
@@ -35,8 +35,8 @@ discard block |
||
| 35 | 35 | //!@{ |
| 36 | 36 | |
| 37 | 37 | const STD_DOC_PATH = ""; //!< Path for standard documents. |
| 38 | - const LOCAL_DOC_PATH = "_local/"; //!< Path for local documents. |
|
| 39 | - const DESIGN_DOC_PATH = "_design/"; //!< Path for design documents. |
|
| 38 | + const LOCAL_DOC_PATH = "_local/"; //!< Path for local documents. |
|
| 39 | + const DESIGN_DOC_PATH = "_design/"; //!< Path for design documents. |
|
| 40 | 40 | |
| 41 | 41 | //!@} |
| 42 | 42 | |
@@ -783,7 +783,7 @@ discard block |
||
| 783 | 783 | public function cleanupViews() { |
| 784 | 784 | $this->checkForDb(); |
| 785 | 785 | |
| 786 | - $request = new Request(Request::POST_METHOD, "/".$this->dbName."/_view_cleanup"); |
|
| 786 | + $request = new Request(Request::POST_METHOD, "/".$this->dbName."/_view_cleanup"); |
|
| 787 | 787 | |
| 788 | 788 | // A POST method requires Content-Type header. |
| 789 | 789 | $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json"); |
@@ -102,10 +102,13 @@ discard block |
||
| 102 | 102 | foreach ($keys as $key) { |
| 103 | 103 | $hash = md5(json_encode($key)); |
| 104 | 104 | |
| 105 | - if (isset($matches[$hash])) // Match found. |
|
| 105 | + if (isset($matches[$hash])) { |
|
| 106 | + // Match found. |
|
| 106 | 107 | $allRows[] = $matches[$hash]; |
| 107 | - else // No match found. |
|
| 108 | + } else { |
|
| 109 | + // No match found. |
|
| 108 | 110 | $allRows[] = ['id' => NULL, 'key' => $key, 'value' => NULL]; |
| 111 | + } |
|
| 109 | 112 | } |
| 110 | 113 | |
| 111 | 114 | // Overrides the response, replacing rows. |
@@ -176,15 +179,18 @@ discard block |
||
| 176 | 179 | * @param[in] bool $excludeLocal Document path. |
| 177 | 180 | */ |
| 178 | 181 | public function validateDocPath($path, $excludeLocal = FALSE) { |
| 179 | - if (empty($path)) // STD_DOC_PATH |
|
| 182 | + if (empty($path)) { |
|
| 183 | + // STD_DOC_PATH |
|
| 180 | 184 | return; |
| 185 | + } |
|
| 181 | 186 | |
| 182 | - if ($path == self::DESIGN_DOC_PATH) |
|
| 183 | - return; |
|
| 184 | - elseif ($path == self::LOCAL_DOC_PATH && $excludeLocal) |
|
| 185 | - throw new \InvalidArgumentException("Local document doesn't have attachments."); |
|
| 186 | - else |
|
| 187 | - throw new \InvalidArgumentException("Invalid document path."); |
|
| 187 | + if ($path == self::DESIGN_DOC_PATH) { |
|
| 188 | + return; |
|
| 189 | + } elseif ($path == self::LOCAL_DOC_PATH && $excludeLocal) { |
|
| 190 | + throw new \InvalidArgumentException("Local document doesn't have attachments."); |
|
| 191 | + } else { |
|
| 192 | + throw new \InvalidArgumentException("Invalid document path."); |
|
| 193 | + } |
|
| 188 | 194 | } |
| 189 | 195 | |
| 190 | 196 | |
@@ -206,10 +212,11 @@ discard block |
||
| 206 | 212 | # One of the characters “_$()” «_$()» |
| 207 | 213 | # A character in the range between “+” and “/” «+-/» |
| 208 | 214 | # Assert position at the very end of the string «\z» |
| 209 | - if (preg_match('%\A[a-z][a-z\d_$()+-/]++\z%', $name)) |
|
| 210 | - return $name = rawurlencode($name); |
|
| 211 | - else |
|
| 212 | - throw new \InvalidArgumentException("Invalid database name."); |
|
| 215 | + if (preg_match('%\A[a-z][a-z\d_$()+-/]++\z%', $name)) { |
|
| 216 | + return $name = rawurlencode($name); |
|
| 217 | + } else { |
|
| 218 | + throw new \InvalidArgumentException("Invalid database name."); |
|
| 219 | + } |
|
| 213 | 220 | } |
| 214 | 221 | |
| 215 | 222 | |
@@ -220,10 +227,11 @@ discard block |
||
| 220 | 227 | * @param string $docId Document id. |
| 221 | 228 | */ |
| 222 | 229 | public function validateAndEncodeDocId(&$docId) { |
| 223 | - if (!empty($docId)) |
|
| 224 | - $docId = rawurlencode($docId); |
|
| 225 | - else |
|
| 226 | - throw new \InvalidArgumentException("\$docId must be a non-empty string."); |
|
| 230 | + if (!empty($docId)) { |
|
| 231 | + $docId = rawurlencode($docId); |
|
| 232 | + } else { |
|
| 233 | + throw new \InvalidArgumentException("\$docId must be a non-empty string."); |
|
| 234 | + } |
|
| 227 | 235 | } |
| 228 | 236 | |
| 229 | 237 | //!@} |
@@ -255,10 +263,10 @@ discard block |
||
| 255 | 263 | // before the client has received the entire response. To avoid problems, we trap the exception and we go on. |
| 256 | 264 | try { |
| 257 | 265 | $this->send($request); |
| 258 | - } |
|
| 259 | - catch (\Exception $e) { |
|
| 260 | - if ($e->getCode() > 0) |
|
| 261 | - throw $e; |
|
| 266 | + } catch (\Exception $e) { |
|
| 267 | + if ($e->getCode() > 0) { |
|
| 268 | + throw $e; |
|
| 269 | + } |
|
| 262 | 270 | } |
| 263 | 271 | } |
| 264 | 272 | |
@@ -295,10 +303,11 @@ discard block |
||
| 295 | 303 | public function getFavicon() { |
| 296 | 304 | $response = $this->send(new Request(Request::GET_METHOD, "/favicon.ico")); |
| 297 | 305 | |
| 298 | - if ($response->getHeaderFieldValue(Request::CONTENT_TYPE_HF) == "image/x-icon") |
|
| 299 | - return $response->getBody(); |
|
| 300 | - else |
|
| 301 | - throw new \InvalidArgumentException("Content-Type must be image/x-icon."); |
|
| 306 | + if ($response->getHeaderFieldValue(Request::CONTENT_TYPE_HF) == "image/x-icon") { |
|
| 307 | + return $response->getBody(); |
|
| 308 | + } else { |
|
| 309 | + throw new \InvalidArgumentException("Content-Type must be image/x-icon."); |
|
| 310 | + } |
|
| 302 | 311 | } |
| 303 | 312 | |
| 304 | 313 | |
@@ -334,8 +343,9 @@ discard block |
||
| 334 | 343 | |
| 335 | 344 | $request = new Request(Request::GET_METHOD, "/_db_updates"); |
| 336 | 345 | |
| 337 | - if (isset($opts)) |
|
| 338 | - $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
|
| 346 | + if (isset($opts)) { |
|
| 347 | + $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
|
| 348 | + } |
|
| 339 | 349 | |
| 340 | 350 | return $this->send($request)->getBodyAsArray(); |
| 341 | 351 | } |
@@ -364,9 +374,9 @@ discard block |
||
| 364 | 374 | $request = new Request(Request::GET_METHOD, "/_log"); |
| 365 | 375 | $request->setQueryParam("bytes", $bytes); |
| 366 | 376 | return $this->send($request)->getBody(); |
| 377 | + } else { |
|
| 378 | + throw new \InvalidArgumentException("\$bytes must be a positive integer."); |
|
| 367 | 379 | } |
| 368 | - else |
|
| 369 | - throw new \InvalidArgumentException("\$bytes must be a positive integer."); |
|
| 370 | 380 | } |
| 371 | 381 | |
| 372 | 382 | |
@@ -383,13 +393,15 @@ discard block |
||
| 383 | 393 | |
| 384 | 394 | $response = $this->send($request); |
| 385 | 395 | |
| 386 | - if ($count == 1) // We don't need to use === operator because, just above, we made a type checking. |
|
| 396 | + if ($count == 1) { |
|
| 397 | + // We don't need to use === operator because, just above, we made a type checking. |
|
| 387 | 398 | return $response->getBodyAsArray()['uuids'][0]; |
| 388 | - else |
|
| 389 | - return $response->getBodyAsArray()['uuids']; |
|
| 399 | + } else { |
|
| 400 | + return $response->getBodyAsArray()['uuids']; |
|
| 401 | + } |
|
| 402 | + } else { |
|
| 403 | + throw new \InvalidArgumentException("\$count must be a positive integer."); |
|
| 390 | 404 | } |
| 391 | - else |
|
| 392 | - throw new \InvalidArgumentException("\$count must be a positive integer."); |
|
| 393 | 405 | } |
| 394 | 406 | |
| 395 | 407 | //!@} |
@@ -403,8 +415,9 @@ discard block |
||
| 403 | 415 | private function endTransaction() { |
| 404 | 416 | if (is_array($this->transaction)) { |
| 405 | 417 | |
| 406 | - foreach ($this->transaction as $doc) |
|
| 407 | - unset($doc); |
|
| 418 | + foreach ($this->transaction as $doc) { |
|
| 419 | + unset($doc); |
|
| 420 | + } |
|
| 408 | 421 | |
| 409 | 422 | unset($this->transaction); |
| 410 | 423 | } |
@@ -416,10 +429,11 @@ discard block |
||
| 416 | 429 | * @brief Starts a new transaction. |
| 417 | 430 | */ |
| 418 | 431 | public function begin() { |
| 419 | - if (is_null($this->transaction)) |
|
| 420 | - $this->transaction = []; |
|
| 421 | - else |
|
| 422 | - throw new \RuntimeException("A transaction is already in progress."); |
|
| 432 | + if (is_null($this->transaction)) { |
|
| 433 | + $this->transaction = []; |
|
| 434 | + } else { |
|
| 435 | + throw new \RuntimeException("A transaction is already in progress."); |
|
| 436 | + } |
|
| 423 | 437 | } |
| 424 | 438 | |
| 425 | 439 | |
@@ -445,8 +459,7 @@ discard block |
||
| 445 | 459 | try { |
| 446 | 460 | $this->performBulkOperations($this->transaction, $immediately, TRUE, $newEdits); |
| 447 | 461 | $this->endTransaction(); |
| 448 | - } |
|
| 449 | - catch (\Exception $e) { |
|
| 462 | + } catch (\Exception $e) { |
|
| 450 | 463 | $this->rollback(); |
| 451 | 464 | throw $e; |
| 452 | 465 | } |
@@ -481,8 +494,9 @@ discard block |
||
| 481 | 494 | if (!empty($section)) { |
| 482 | 495 | $path .= "/".$section; |
| 483 | 496 | |
| 484 | - if (!empty($key)) |
|
| 485 | - $path .= "/".$key; |
|
| 497 | + if (!empty($key)) { |
|
| 498 | + $path .= "/".$key; |
|
| 499 | + } |
|
| 486 | 500 | } |
| 487 | 501 | |
| 488 | 502 | return $this->send(new Request(Request::GET_METHOD, $path))->getBodyAsArray(); |
@@ -497,14 +511,17 @@ discard block |
||
| 497 | 511 | * @see http://docs.couchdb.org/en/latest/api/server/configuration.html#put--_config-section-key |
| 498 | 512 | */ |
| 499 | 513 | public function setConfigKey($section, $key, $value) { |
| 500 | - if (!is_string($section) or empty($section)) |
|
| 501 | - throw new \InvalidArgumentException("\$section must be a not empty string."); |
|
| 514 | + if (!is_string($section) or empty($section)) { |
|
| 515 | + throw new \InvalidArgumentException("\$section must be a not empty string."); |
|
| 516 | + } |
|
| 502 | 517 | |
| 503 | - if (!is_string($key) or empty($key)) |
|
| 504 | - throw new \InvalidArgumentException("\$key must be a not empty string."); |
|
| 518 | + if (!is_string($key) or empty($key)) { |
|
| 519 | + throw new \InvalidArgumentException("\$key must be a not empty string."); |
|
| 520 | + } |
|
| 505 | 521 | |
| 506 | - if (is_null($value)) |
|
| 507 | - throw new \InvalidArgumentException("\$value cannot be null."); |
|
| 522 | + if (is_null($value)) { |
|
| 523 | + throw new \InvalidArgumentException("\$value cannot be null."); |
|
| 524 | + } |
|
| 508 | 525 | |
| 509 | 526 | $request = new Request(Request::PUT_METHOD, "/_config/".$section."/".$key); |
| 510 | 527 | $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json"); |
@@ -520,11 +537,13 @@ discard block |
||
| 520 | 537 | * @see http://docs.couchdb.org/en/latest/api/configuration.html#delete-config-section-key |
| 521 | 538 | */ |
| 522 | 539 | public function deleteConfigKey($section, $key) { |
| 523 | - if (!is_string($section) or empty($section)) |
|
| 524 | - throw new \InvalidArgumentException("\$section must be a not empty string."); |
|
| 540 | + if (!is_string($section) or empty($section)) { |
|
| 541 | + throw new \InvalidArgumentException("\$section must be a not empty string."); |
|
| 542 | + } |
|
| 525 | 543 | |
| 526 | - if (!is_string($key) or empty($key)) |
|
| 527 | - throw new \InvalidArgumentException("\$key must be a not empty string."); |
|
| 544 | + if (!is_string($key) or empty($key)) { |
|
| 545 | + throw new \InvalidArgumentException("\$key must be a not empty string."); |
|
| 546 | + } |
|
| 528 | 547 | |
| 529 | 548 | $this->send(new Request(Request::DELETE_METHOD, "/_config/".$section."/".$key)); |
| 530 | 549 | } |
@@ -551,11 +570,13 @@ discard block |
||
| 551 | 570 | * @see http://docs.couchdb.org/en/latest/api/server/authn.html#post--_session |
| 552 | 571 | */ |
| 553 | 572 | public function setSession($userName, $password) { |
| 554 | - if (!is_string($userName) or empty($userName)) |
|
| 555 | - throw new \InvalidArgumentException("\$userName must be a not empty string."); |
|
| 573 | + if (!is_string($userName) or empty($userName)) { |
|
| 574 | + throw new \InvalidArgumentException("\$userName must be a not empty string."); |
|
| 575 | + } |
|
| 556 | 576 | |
| 557 | - if (!is_string($password) or empty($password)) |
|
| 558 | - throw new \InvalidArgumentException("\$password must be a not empty string."); |
|
| 577 | + if (!is_string($password) or empty($password)) { |
|
| 578 | + throw new \InvalidArgumentException("\$password must be a not empty string."); |
|
| 579 | + } |
|
| 559 | 580 | |
| 560 | 581 | $request = new Request(Request::POST_METHOD, "/_session"); |
| 561 | 582 | |
@@ -650,8 +671,9 @@ discard block |
||
| 650 | 671 | * you are making a not supported call to CouchDB. |
| 651 | 672 | */ |
| 652 | 673 | public function checkForDb() { |
| 653 | - if (empty($this->dbName)) |
|
| 654 | - throw new \RuntimeException("No database selected."); |
|
| 674 | + if (empty($this->dbName)) { |
|
| 675 | + throw new \RuntimeException("No database selected."); |
|
| 676 | + } |
|
| 655 | 677 | } |
| 656 | 678 | |
| 657 | 679 | |
@@ -669,11 +691,12 @@ discard block |
||
| 669 | 691 | if ($name != $this->dbName) { |
| 670 | 692 | $this->send(new Request(Request::PUT_METHOD, "/".$name."/")); |
| 671 | 693 | |
| 672 | - if ($autoSelect) |
|
| 673 | - $this->dbName = $name; |
|
| 694 | + if ($autoSelect) { |
|
| 695 | + $this->dbName = $name; |
|
| 696 | + } |
|
| 697 | + } else { |
|
| 698 | + throw new \UnexpectedValueException("You can't create a database with the same name of the selected database."); |
|
| 674 | 699 | } |
| 675 | - else |
|
| 676 | - throw new \UnexpectedValueException("You can't create a database with the same name of the selected database."); |
|
| 677 | 700 | } |
| 678 | 701 | |
| 679 | 702 | |
@@ -687,10 +710,11 @@ discard block |
||
| 687 | 710 | public function deleteDb($name) { |
| 688 | 711 | $this->validateAndEncodeDbName($name); |
| 689 | 712 | |
| 690 | - if ($name != $this->dbName) |
|
| 691 | - $this->send(new Request(Request::DELETE_METHOD, "/".$name)); |
|
| 692 | - else |
|
| 693 | - throw new \UnexpectedValueException("You can't delete the selected database."); |
|
| 713 | + if ($name != $this->dbName) { |
|
| 714 | + $this->send(new Request(Request::DELETE_METHOD, "/".$name)); |
|
| 715 | + } else { |
|
| 716 | + throw new \UnexpectedValueException("You can't delete the selected database."); |
|
| 717 | + } |
|
| 694 | 718 | } |
| 695 | 719 | |
| 696 | 720 | |
@@ -718,8 +742,9 @@ discard block |
||
| 718 | 742 | |
| 719 | 743 | $request = new Request(Request::GET_METHOD, "/".$this->dbName."/_changes"); |
| 720 | 744 | |
| 721 | - if (isset($opts)) |
|
| 722 | - $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
|
| 745 | + if (isset($opts)) { |
|
| 746 | + $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
|
| 747 | + } |
|
| 723 | 748 | |
| 724 | 749 | return $this->send($request); |
| 725 | 750 | } |
@@ -914,40 +939,47 @@ discard block |
||
| 914 | 939 | is_string($targetDbUrl) && !empty($targetDbUrl)) { |
| 915 | 940 | $body["source"] = $sourceDbUrl; |
| 916 | 941 | $body["target"] = $targetDbUrl; |
| 942 | + } else { |
|
| 943 | + throw new \InvalidArgumentException("\$source_db_url and \$target_db_url must be non-empty strings."); |
|
| 917 | 944 | } |
| 918 | - else |
|
| 919 | - throw new \InvalidArgumentException("\$source_db_url and \$target_db_url must be non-empty strings."); |
|
| 920 | 945 | |
| 921 | - if (!is_bool($continuous)) |
|
| 922 | - throw new \InvalidArgumentException("\$continuous must be a bool."); |
|
| 923 | - elseif ($continuous) |
|
| 924 | - $body["continuous"] = $continuous; |
|
| 946 | + if (!is_bool($continuous)) { |
|
| 947 | + throw new \InvalidArgumentException("\$continuous must be a bool."); |
|
| 948 | + } elseif ($continuous) { |
|
| 949 | + $body["continuous"] = $continuous; |
|
| 950 | + } |
|
| 925 | 951 | |
| 926 | 952 | // Uses the specified proxy if any set. |
| 927 | - if (isset($proxy)) |
|
| 928 | - $body["proxy"] = $this->proxy; |
|
| 953 | + if (isset($proxy)) { |
|
| 954 | + $body["proxy"] = $this->proxy; |
|
| 955 | + } |
|
| 929 | 956 | |
| 930 | 957 | // create_target option |
| 931 | - if (!is_bool($createTargetDb)) |
|
| 932 | - throw new \InvalidArgumentException("\$createTargetDb must be a bool."); |
|
| 933 | - elseif ($createTargetDb) |
|
| 934 | - $body["create_target"] = $createTargetDb; |
|
| 958 | + if (!is_bool($createTargetDb)) { |
|
| 959 | + throw new \InvalidArgumentException("\$createTargetDb must be a bool."); |
|
| 960 | + } elseif ($createTargetDb) { |
|
| 961 | + $body["create_target"] = $createTargetDb; |
|
| 962 | + } |
|
| 935 | 963 | |
| 936 | 964 | if (!empty($filter)) { |
| 937 | - if (is_string($filter)) // filter option |
|
| 965 | + if (is_string($filter)) { |
|
| 966 | + // filter option |
|
| 938 | 967 | $body["filter"] = $filter; |
| 939 | - elseif (is_array($filter)) // doc_ids option |
|
| 968 | + } elseif (is_array($filter)) { |
|
| 969 | + // doc_ids option |
|
| 940 | 970 | $body["doc_ids"] = array_values($filter); |
| 941 | - else |
|
| 942 | - throw new \InvalidArgumentException("\$filter must be a string or an array."); |
|
| 971 | + } else { |
|
| 972 | + throw new \InvalidArgumentException("\$filter must be a string or an array."); |
|
| 973 | + } |
|
| 943 | 974 | } |
| 944 | 975 | |
| 945 | 976 | // queryParams option |
| 946 | 977 | if (!is_null($opts)) { |
| 947 | - if ($opts instanceof Opt\ViewQueryOpts) |
|
| 948 | - $body["query_params"] = get_object_vars($opts); |
|
| 949 | - else |
|
| 950 | - throw new \InvalidArgumentException("\$queryParams must be an instance of ViewQueryOpts class."); |
|
| 978 | + if ($opts instanceof Opt\ViewQueryOpts) { |
|
| 979 | + $body["query_params"] = get_object_vars($opts); |
|
| 980 | + } else { |
|
| 981 | + throw new \InvalidArgumentException("\$queryParams must be an instance of ViewQueryOpts class."); |
|
| 982 | + } |
|
| 951 | 983 | } |
| 952 | 984 | |
| 953 | 985 | return $this->send(Request::POST_METHOD, "/_replicate", NULL, NULL, $body); |
@@ -961,8 +993,9 @@ discard block |
||
| 961 | 993 | * @see http://docs.couchdb.org/en/latest/api/server/common.html#canceling-continuous-replication |
| 962 | 994 | */ |
| 963 | 995 | public function stopReplication($replicationId) { |
| 964 | - if (is_null($replicationId)) |
|
| 965 | - throw new \InvalidArgumentException("You must provide a replication id."); |
|
| 996 | + if (is_null($replicationId)) { |
|
| 997 | + throw new \InvalidArgumentException("You must provide a replication id."); |
|
| 998 | + } |
|
| 966 | 999 | |
| 967 | 1000 | $body["replication_id"] = $replicationId; |
| 968 | 1001 | $body["cancel"] = TRUE; |
@@ -1008,15 +1041,16 @@ discard block |
||
| 1008 | 1041 | public function queryAllDocs(array $keys = NULL, Opt\ViewQueryOpts $opts = NULL, Hook\IChunkHook $chunkHook = NULL) { |
| 1009 | 1042 | $this->checkForDb(); |
| 1010 | 1043 | |
| 1011 | - if (is_null($keys)) |
|
| 1012 | - $request = new Request(Request::GET_METHOD, "/".$this->dbName."/_all_docs"); |
|
| 1013 | - else { |
|
| 1044 | + if (is_null($keys)) { |
|
| 1045 | + $request = new Request(Request::GET_METHOD, "/".$this->dbName."/_all_docs"); |
|
| 1046 | + } else { |
|
| 1014 | 1047 | $request = new Request(Request::POST_METHOD, "/".$this->dbName."/_all_docs"); |
| 1015 | 1048 | $request->setBody(json_encode(['keys' => $keys])); |
| 1016 | 1049 | } |
| 1017 | 1050 | |
| 1018 | - if (isset($opts)) |
|
| 1019 | - $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
|
| 1051 | + if (isset($opts)) { |
|
| 1052 | + $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
|
| 1053 | + } |
|
| 1020 | 1054 | |
| 1021 | 1055 | $result = $this->send($request, $chunkHook)->getBodyAsArray(); |
| 1022 | 1056 | |
@@ -1045,12 +1079,13 @@ discard block |
||
| 1045 | 1079 | $this->checkForDb(); |
| 1046 | 1080 | $this->validateAndEncodeDocId($designDocName); |
| 1047 | 1081 | |
| 1048 | - if (empty($viewName)) |
|
| 1049 | - throw new \InvalidArgumentException("You must provide a valid \$viewName."); |
|
| 1082 | + if (empty($viewName)) { |
|
| 1083 | + throw new \InvalidArgumentException("You must provide a valid \$viewName."); |
|
| 1084 | + } |
|
| 1050 | 1085 | |
| 1051 | - if (empty($keys)) |
|
| 1052 | - $request = new Request(Request::GET_METHOD, "/".$this->dbName."/_design/".$designDocName."/_view/".$viewName); |
|
| 1053 | - else { |
|
| 1086 | + if (empty($keys)) { |
|
| 1087 | + $request = new Request(Request::GET_METHOD, "/".$this->dbName."/_design/".$designDocName."/_view/".$viewName); |
|
| 1088 | + } else { |
|
| 1054 | 1089 | $request = new Request(Request::POST_METHOD, "/".$this->dbName."/_design/".$designDocName."/_view/".$viewName); |
| 1055 | 1090 | $request->setBody(json_encode(['keys' => $keys])); |
| 1056 | 1091 | } |
@@ -1058,14 +1093,15 @@ discard block |
||
| 1058 | 1093 | if (isset($opts)) { |
| 1059 | 1094 | $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
| 1060 | 1095 | $includeMissingKeys = $opts->issetIncludeMissingKeys(); |
| 1096 | + } else { |
|
| 1097 | + $includeMissingKeys = FALSE; |
|
| 1061 | 1098 | } |
| 1062 | - else |
|
| 1063 | - $includeMissingKeys = FALSE; |
|
| 1064 | 1099 | |
| 1065 | 1100 | $result = $this->send($request, $chunkHook)->getBodyAsArray(); |
| 1066 | 1101 | |
| 1067 | - if ($includeMissingKeys) |
|
| 1068 | - $this->addMissingRows($keys, $result['rows']); |
|
| 1102 | + if ($includeMissingKeys) { |
|
| 1103 | + $this->addMissingRows($keys, $result['rows']); |
|
| 1104 | + } |
|
| 1069 | 1105 | |
| 1070 | 1106 | return new Result\QueryResult($result); |
| 1071 | 1107 | } |
@@ -1093,30 +1129,33 @@ discard block |
||
| 1093 | 1129 | $handler = new Handler\ViewHandler('temp'); |
| 1094 | 1130 | $handler->language = $language; |
| 1095 | 1131 | $handler->mapFn = $mapFn; |
| 1096 | - if (!empty($reduce)) |
|
| 1097 | - $handler->reduceFn = $reduceFn; |
|
| 1132 | + if (!empty($reduce)) { |
|
| 1133 | + $handler->reduceFn = $reduceFn; |
|
| 1134 | + } |
|
| 1098 | 1135 | |
| 1099 | 1136 | $request = new Request(Request::POST_METHOD, "/".$this->dbName."/_temp_view"); |
| 1100 | 1137 | $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json"); |
| 1101 | 1138 | |
| 1102 | 1139 | $array = $handler->asArray(); |
| 1103 | 1140 | |
| 1104 | - if (!empty($keys)) |
|
| 1105 | - $array['keys'] = $keys; |
|
| 1141 | + if (!empty($keys)) { |
|
| 1142 | + $array['keys'] = $keys; |
|
| 1143 | + } |
|
| 1106 | 1144 | |
| 1107 | 1145 | $request->setBody(json_encode($array)); |
| 1108 | 1146 | |
| 1109 | 1147 | if (isset($opts)) { |
| 1110 | 1148 | $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
| 1111 | 1149 | $includeMissingKeys = $opts->issetIncludeMissingKeys(); |
| 1150 | + } else { |
|
| 1151 | + $includeMissingKeys = FALSE; |
|
| 1112 | 1152 | } |
| 1113 | - else |
|
| 1114 | - $includeMissingKeys = FALSE; |
|
| 1115 | 1153 | |
| 1116 | 1154 | $result = $this->send($request, $chunkHook)->getBodyAsArray(); |
| 1117 | 1155 | |
| 1118 | - if ($includeMissingKeys) |
|
| 1119 | - $this->addMissingRows($keys, $result['rows']); |
|
| 1156 | + if ($includeMissingKeys) { |
|
| 1157 | + $this->addMissingRows($keys, $result['rows']); |
|
| 1158 | + } |
|
| 1120 | 1159 | |
| 1121 | 1160 | return new Result\QueryResult($result); |
| 1122 | 1161 | } |
@@ -1179,8 +1218,9 @@ discard block |
||
| 1179 | 1218 | public function setRevsLimit($revsLimit = self::REVS_LIMIT) { |
| 1180 | 1219 | $this->checkForDb(); |
| 1181 | 1220 | |
| 1182 | - if (!is_int($revsLimit) or ($revsLimit <= 0)) |
|
| 1183 | - throw new \InvalidArgumentException("\$revsLimit must be a positive integer."); |
|
| 1221 | + if (!is_int($revsLimit) or ($revsLimit <= 0)) { |
|
| 1222 | + throw new \InvalidArgumentException("\$revsLimit must be a positive integer."); |
|
| 1223 | + } |
|
| 1184 | 1224 | |
| 1185 | 1225 | $request = new Request(Request::PUT_METHOD, "/".$this->dbName."/_revs_limit"); |
| 1186 | 1226 | $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json"); |
@@ -1238,16 +1278,17 @@ discard block |
||
| 1238 | 1278 | $request = new Request(Request::GET_METHOD, $requestPath); |
| 1239 | 1279 | |
| 1240 | 1280 | // Retrieves the specific revision of the document. |
| 1241 | - if (!empty($rev)) |
|
| 1242 | - $request->setQueryParam("rev", (string)$rev); |
|
| 1281 | + if (!empty($rev)) { |
|
| 1282 | + $request->setQueryParam("rev", (string)$rev); |
|
| 1283 | + } |
|
| 1243 | 1284 | |
| 1244 | 1285 | // If there are any options, add them to the request. |
| 1245 | 1286 | if (isset($opts)) { |
| 1246 | 1287 | $request->setMultipleQueryParamsAtOnce($opts->asArray()); |
| 1247 | 1288 | $ignoreClass = $opts->issetIgnoreClass(); |
| 1289 | + } else { |
|
| 1290 | + $ignoreClass = FALSE; |
|
| 1248 | 1291 | } |
| 1249 | - else |
|
| 1250 | - $ignoreClass = FALSE; |
|
| 1251 | 1292 | |
| 1252 | 1293 | $response = $this->send($request); |
| 1253 | 1294 | $body = $response->getBodyAsArray(); |
@@ -1259,18 +1300,18 @@ discard block |
||
| 1259 | 1300 | if (!$ignoreClass && isset($body['class'])) { // Special document class inherited from Doc or LocalDoc. |
| 1260 | 1301 | $class = "\\".$body['class']; |
| 1261 | 1302 | $doc = new $class; |
| 1303 | + } elseif ($path == self::DESIGN_DOC_PATH) { |
|
| 1304 | + $doc = new Doc\DesignDoc; |
|
| 1305 | + } else { |
|
| 1306 | + $doc = NULL; |
|
| 1262 | 1307 | } |
| 1263 | - elseif ($path == self::DESIGN_DOC_PATH) |
|
| 1264 | - $doc = new Doc\DesignDoc; |
|
| 1265 | - else |
|
| 1266 | - $doc = NULL; |
|
| 1267 | 1308 | |
| 1268 | 1309 | if (is_object($doc)) { |
| 1269 | 1310 | $doc->assignArray($body); |
| 1270 | 1311 | return $doc; |
| 1312 | + } else { |
|
| 1313 | + return $response; |
|
| 1271 | 1314 | } |
| 1272 | - else |
|
| 1273 | - return $response; |
|
| 1274 | 1315 | } |
| 1275 | 1316 | |
| 1276 | 1317 | |
@@ -1297,8 +1338,9 @@ discard block |
||
| 1297 | 1338 | |
| 1298 | 1339 | // Whether the document has an id we use a different HTTP method. Using POST CouchDB generates an id for the doc |
| 1299 | 1340 | // using PUT we need to specify one. We can still use the function getUuids() to ask CouchDB for some ids. |
| 1300 | - if (!$doc->issetId()) |
|
| 1301 | - $doc->setid(Generator\UUID::generate(Generator\UUID::UUID_RANDOM, Generator\UUID::FMT_STRING)); |
|
| 1341 | + if (!$doc->issetId()) { |
|
| 1342 | + $doc->setid(Generator\UUID::generate(Generator\UUID::UUID_RANDOM, Generator\UUID::FMT_STRING)); |
|
| 1343 | + } |
|
| 1302 | 1344 | |
| 1303 | 1345 | $this->setDocInfo($doc); |
| 1304 | 1346 | |
@@ -1312,8 +1354,9 @@ discard block |
||
| 1312 | 1354 | $request->setBody($doc->asJson()); |
| 1313 | 1355 | |
| 1314 | 1356 | // Enables batch mode. |
| 1315 | - if ($batchMode) |
|
| 1316 | - $request->setQueryParam("batch", "ok"); |
|
| 1357 | + if ($batchMode) { |
|
| 1358 | + $request->setQueryParam("batch", "ok"); |
|
| 1359 | + } |
|
| 1317 | 1360 | |
| 1318 | 1361 | $this->send($request); |
| 1319 | 1362 | } |
@@ -1366,10 +1409,11 @@ discard block |
||
| 1366 | 1409 | // This request uses the special method COPY. |
| 1367 | 1410 | $request = new Request(Request::COPY_METHOD, $path); |
| 1368 | 1411 | |
| 1369 | - if (empty($rev)) |
|
| 1370 | - $request->setHeaderField(Request::DESTINATION_HF, $targetDocId); |
|
| 1371 | - else |
|
| 1372 | - $request->setHeaderField(Request::DESTINATION_HF, $targetDocId."?rev=".(string)$rev); |
|
| 1412 | + if (empty($rev)) { |
|
| 1413 | + $request->setHeaderField(Request::DESTINATION_HF, $targetDocId); |
|
| 1414 | + } else { |
|
| 1415 | + $request->setHeaderField(Request::DESTINATION_HF, $targetDocId."?rev=".(string)$rev); |
|
| 1416 | + } |
|
| 1373 | 1417 | |
| 1374 | 1418 | $this->send($request); |
| 1375 | 1419 | } |
@@ -1399,8 +1443,9 @@ discard block |
||
| 1399 | 1443 | $request = new Request(Request::POST_METHOD, $path); |
| 1400 | 1444 | |
| 1401 | 1445 | $purge = []; |
| 1402 | - foreach ($refs as $ref) |
|
| 1403 | - $purge[] = $ref->asArray(); |
|
| 1446 | + foreach ($refs as $ref) { |
|
| 1447 | + $purge[] = $ref->asArray(); |
|
| 1448 | + } |
|
| 1404 | 1449 | |
| 1405 | 1450 | $request->setBody(json_encode($purge)); |
| 1406 | 1451 | |
@@ -1433,26 +1478,30 @@ discard block |
||
| 1433 | 1478 | public function performBulkOperations(array $docs, $fullCommit = FALSE, $allOrNothing = FALSE, $newEdits = TRUE) { |
| 1434 | 1479 | $this->checkForDb(); |
| 1435 | 1480 | |
| 1436 | - if (count($docs) == 0) |
|
| 1437 | - throw new \InvalidArgumentException("The \$docs array cannot be empty."); |
|
| 1438 | - else |
|
| 1439 | - $operations = []; |
|
| 1481 | + if (count($docs) == 0) { |
|
| 1482 | + throw new \InvalidArgumentException("The \$docs array cannot be empty."); |
|
| 1483 | + } else { |
|
| 1484 | + $operations = []; |
|
| 1485 | + } |
|
| 1440 | 1486 | |
| 1441 | 1487 | $path = "/".$this->dbName."/_bulk_docs"; |
| 1442 | 1488 | |
| 1443 | 1489 | $request = new Request(Request::POST_METHOD, $path); |
| 1444 | 1490 | $request->setHeaderField(Request::CONTENT_TYPE_HF, "application/json"); |
| 1445 | 1491 | |
| 1446 | - if ($fullCommit) |
|
| 1447 | - $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "full_commit"); |
|
| 1448 | - else |
|
| 1449 | - $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "delay_commit"); |
|
| 1492 | + if ($fullCommit) { |
|
| 1493 | + $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "full_commit"); |
|
| 1494 | + } else { |
|
| 1495 | + $request->setHeaderField(Request::X_COUCHDB_FULL_COMMIT_HF, "delay_commit"); |
|
| 1496 | + } |
|
| 1450 | 1497 | |
| 1451 | - if ($allOrNothing) |
|
| 1452 | - $operations['all_or_nothing'] = 'true'; |
|
| 1498 | + if ($allOrNothing) { |
|
| 1499 | + $operations['all_or_nothing'] = 'true'; |
|
| 1500 | + } |
|
| 1453 | 1501 | |
| 1454 | - if (!$newEdits) |
|
| 1455 | - $operations['new_edits'] = 'false'; |
|
| 1502 | + if (!$newEdits) { |
|
| 1503 | + $operations['new_edits'] = 'false'; |
|
| 1504 | + } |
|
| 1456 | 1505 | |
| 1457 | 1506 | foreach ($docs as $doc) { |
| 1458 | 1507 | $this->setDocInfo($doc); |
@@ -1490,8 +1539,9 @@ discard block |
||
| 1490 | 1539 | $request = new Request(Request::HEAD_METHOD, $path); |
| 1491 | 1540 | |
| 1492 | 1541 | // In case we want retrieve a specific document revision. |
| 1493 | - if (!empty($rev)) |
|
| 1494 | - $request->setQueryParam("rev", (string)$rev); |
|
| 1542 | + if (!empty($rev)) { |
|
| 1543 | + $request->setQueryParam("rev", (string)$rev); |
|
| 1544 | + } |
|
| 1495 | 1545 | |
| 1496 | 1546 | return $this->send($request); |
| 1497 | 1547 | } |
@@ -1517,8 +1567,9 @@ discard block |
||
| 1517 | 1567 | $request = new Request(Request::GET_METHOD, $path); |
| 1518 | 1568 | |
| 1519 | 1569 | // In case we want retrieve a specific document revision. |
| 1520 | - if (!empty($rev)) |
|
| 1521 | - $request->setQueryParam("rev", (string)$rev); |
|
| 1570 | + if (!empty($rev)) { |
|
| 1571 | + $request->setQueryParam("rev", (string)$rev); |
|
| 1572 | + } |
|
| 1522 | 1573 | |
| 1523 | 1574 | return $this->send($request)->getBody(); |
| 1524 | 1575 | } |
@@ -1547,8 +1598,9 @@ discard block |
||
| 1547 | 1598 | $request->setBody(base64_encode($attachment->getData())); |
| 1548 | 1599 | |
| 1549 | 1600 | // In case of adding or updating an existence document. |
| 1550 | - if (!empty($rev)) |
|
| 1551 | - $request->setQueryParam("rev", (string)$rev); |
|
| 1601 | + if (!empty($rev)) { |
|
| 1602 | + $request->setQueryParam("rev", (string)$rev); |
|
| 1603 | + } |
|
| 1552 | 1604 | |
| 1553 | 1605 | return $this->send($request); |
| 1554 | 1606 | } |
@@ -17,7 +17,7 @@ |
||
| 17 | 17 | * configurations.\n |
| 18 | 18 | * Inherit from LocalDoc if you want create a persistent class that is not replicable. |
| 19 | 19 | * @nosubgrouping |
| 20 | - */ |
|
| 20 | + */ |
|
| 21 | 21 | class LocalDoc extends AbstractDoc { |
| 22 | 22 | |
| 23 | 23 | |
@@ -25,8 +25,9 @@ |
||
| 25 | 25 | * @brief Removes `_local/` from he document identifier. |
| 26 | 26 | */ |
| 27 | 27 | protected function fixDocId() { |
| 28 | - if (isset($this->meta['_id'])) |
|
| 29 | - $this->meta['_id'] = preg_replace('%\A_local/%m', "", $this->meta['_id']); |
|
| 28 | + if (isset($this->meta['_id'])) { |
|
| 29 | + $this->meta['_id'] = preg_replace('%\A_local/%m', "", $this->meta['_id']); |
|
| 30 | + } |
|
| 30 | 31 | } |
| 31 | 32 | |
| 32 | 33 | |
@@ -59,10 +59,11 @@ |
||
| 59 | 59 | |
| 60 | 60 | |
| 61 | 61 | public function setId($value) { |
| 62 | - if (!empty($value)) |
|
| 63 | - $this->id = (string)$value; |
|
| 64 | - else |
|
| 65 | - throw new \Exception("\$id must be a non-empty string."); |
|
| 62 | + if (!empty($value)) { |
|
| 63 | + $this->id = (string)$value; |
|
| 64 | + } else { |
|
| 65 | + throw new \Exception("\$id must be a non-empty string."); |
|
| 66 | + } |
|
| 66 | 67 | } |
| 67 | 68 | |
| 68 | 69 | |