public static function responseWithAttachment($data) { $response = new CouchDBResponse(); $response->setAttachmentData($data); return $response; }
/** * undocumented function * * @param CouchDBCommand $command * @return void * @author Adam Venturella */ public function execute(CouchDBCommand $command) { $request = $command->request(); // default to a header that won't mean anything $authorization = "X-CouchDB-PHP-Authenticate: None"; switch ($this->_authorization) { case 'basic': $authorization = 'Authorization: Basic ' . base64_encode($this->_username . ':' . $this->_password); break; case 'cookie': $session = null; if (isset($this->_authorization_session)) { $session = $this->_authorization_session; } else { if (isset($_COOKIE['AuthSession'])) { $session = 'AuthSession=' . $_COOKIE['AuthSession']; } } $authorization = "X-CouchDB-WWW-Authenticate: Cookie\r\nCookie: " . $session . "\r\n"; break; } $request = str_replace('{host}', $this->_host . ':' . $this->_port, $request); $request = str_replace('{authorization}', $authorization, $request); $data = $this->connect($request); // maybe change this to not require the class but place a method in the CouchDBCommand // interface $command->rawResponse() returns bool or something like that. // dunno if I am comfortable NEEDING that class here. On the other hand it seems silly // to require all of the commands to need that function. Abstract CouchDBCommand? if (is_a($command, 'CDBGetAttachment')) { $response = CouchDBResponse::responseWithAttachment($data); } else { $response = CouchDBResponse::responseWithData($data); } /* if($response->headers['status']['code'] == 401) // Unauthorized { if(isset($response->headers['WWW-Authenticate'])) { if (strpos($response->headers['WWW-Authenticate'], 'Basic') !== false) { // need a way to deal with this for n requests per state basic auth, save baiscally } } } */ /*if($response->error) { throw new Exception('CouchDBCommand('.$command.') Failed with error '.$response->error['error'].': '.$response->error['reason']); } else { return $response; } */ return $response; }