public function request() { $location = '/' . $this->database . '/_temp_view'; if (!empty($this->options)) { $location .= '?'; $this->options = array_map("couchdb_json_encode", $this->options); $location .= http_build_query($this->options); } $this->map = strtr($this->map, array("\n" => '', "\t" => '')); $map = couchdb_json_encode($this->map); $function = "{ \"map\": {$map}"; if ($this->reduce) { $this->reduce = strtr($this->reduce, array("\n" => '', "\t" => '')); $reduce = couchdb_json_encode($this->reduce); $function .= ","; $function .= "\"reduce\": {$reduce}"; } $function .= "}"; $content_length = strlen($function); return <<<REQUEST POST {$location} HTTP/1.0 Host: {host} Connection: Close Content-Length: {$content_length} Content-Type: application/json {authorization} {$function} REQUEST; }
public function request() { $password = couchdb_json_encode($this->password); $content_length = strlen($password); return <<<REQUEST PUT /_config/admins/{$this->username} HTTP/1.0 Host: {host} Connection: Close Content-Length: {$content_length} Content-Type: application/json {authorization} {$password} REQUEST; }
public function request() { $object = new stdClass(); $object->source = $this->source; $object->target = $this->target; $json = couchdb_json_encode($object); $content_length = strlen($json); return <<<REQUEST POST /_replicate HTTP/1.0 Host: {host} Connection: Close Content-Length: {$content_length} Content-Type: application/json {authorization} {$json} REQUEST; }
/** * Delete ACL rules from users/_local/_acl * * @param array $collection An array of arrays representing rules * or an array of objects representing rules * @return CouchDBResponse * @author Adam Venturella * @example ../samples/acl/acl_delete.php Delete ACL rules */ public function acl_delete_rules($collection) { static $loaded = false; if (!$loaded) { require_once 'commands/CDBPutDocument.php'; $loaded = true; } static $matchDB = 2; static $matchRole = 4; static $matchAllow = 8; $matchAll = $matchDB | $matchRole | $matchAllow; $acl = $this->acl(); $response = null; if (!$acl->error) { $rules = array(); $document = $acl->result; foreach ($document['rules'] as $rule) { foreach ($collection as $target) { if (is_object($target)) { $target = array('db' => $target->db, 'role' => $target->role, 'allow' => $target->allow); } $match = 0; if ($target['db'] == $rule['db']) { $match = $match | $matchDB; } if ($target['role'] == $rule['role']) { $match = $match | $matchRole; } if ($target['allow'] == $rule['allow']) { $match = $match | $matchAllow; } if ($match != $matchAll) { $key = hash('md5', serialize($rule)); if (!isset($rules[$key])) { $rules[$key] = $rule; } } } } $rules = array_values($rules); $document['rules'] = $rules; $json = couchdb_json_encode($document); $id = '_local/_acl'; $batch = false; $connection = new CouchDBConnection($this->connectionOptions); $response = $connection->execute(new CDBPutDocument('users', $json, $id, $batch)); return $response; } }