Exemplo n.º 1
0
 /**
  * Call an ad-hoc view function
  * 
  * @param  array  $view   View function code to call
  * @param  array  $params Parameters to pass to the view
  * @param  mixed  $return_doc Type of document to return 
  * @return Sopha_View_Result
  */
 public function adHocView($view, array $params = array(), $return_doc = null)
 {
     require_once 'Sopha/Json.php';
     $url = $this->_db_uri . '_temp_view';
     $data = Sopha_Json::encode($view);
     $request = new Sopha_Http_Request($url, Sopha_Http_Request::POST, $data);
     foreach ($params as $k => $v) {
         $request->addQueryParam($k, Sopha_Json::encode($v));
     }
     $response = $request->send();
     switch ($response->getStatus()) {
         case 200:
             require_once 'Sopha/View/Result.php';
             if (!$return_doc) {
                 $return_doc = Sopha_View_Result::RETURN_ARRAY;
             }
             return new Sopha_View_Result($response->getDocument(), $return_doc);
             break;
         default:
             require_once 'Sopha/Db/Exception.php';
             throw new Sopha_Db_Exception("Unexpected response from server: " . "{$response->getStatus()} {$response->getMessage()}", $response->getStatus());
             break;
     }
 }
Exemplo n.º 2
0
 /**
  * Lazy-load the Attachment data if it was not already loaded
  */
 protected function _lazyLoadData()
 {
     require_once 'Sopha/Http/Request.php';
     $request = new Sopha_Http_Request($this->docUrl . '/' . $this->name);
     $response = $request->send();
     switch ($response->getStatus()) {
         case 200:
             $this->data = $response->getBody();
             $this->type = $response->getHeader('content-type');
             $this->size = $response->getHeader('content-length');
             break;
         case 404:
             require_once 'Sopha/Document/Exception.php';
             throw new Sopha_Document_Exception("Attachment '{$this->name}' does not exist", $response->getStatus());
             break;
         default:
             require_once 'Sopha/Db/Exception.php';
             throw new Sopha_Db_Exception("Unexpected response from server: " . "{$response->getStatus()} {$response->getMessage()}", $response->getStatus());
             break;
     }
 }