示例#1
0
文件: Response.php 项目: stunti/zf2
 /**
  * Populate this instance based on a Zend_Http_Response object
  *
  * @param \Zend\HTTP\Response\Response $response
  * @return \Zend\Service\ReCaptcha\Response
  */
 public function setFromHttpResponse(HTTPResponse\Response $response)
 {
     $body = $response->getBody();
     $parts = explode("\n", $body, 2);
     if (count($parts) !== 2) {
         $status = 'false';
         $errorCode = '';
     } else {
         list($status, $errorCode) = $parts;
     }
     $this->setStatus($status);
     $this->setErrorCode($errorCode);
     return $this;
 }
示例#2
0
 /**
  * Parse a HTTP response body and collect returned parameters
  * as raw url decoded key-value pairs in an associative array.
  *
  * @param  \Zend\HTTP\Response\Response $response
  * @return array
  */
 protected function _parseParameters(HTTPResponse $response)
 {
     $params = array();
     $body = $response->getBody();
     if (empty($body)) {
         return;
     }
     // validate body based on acceptable characters...todo
     $parts = explode('&', $body);
     foreach ($parts as $kvpair) {
         $pair = explode('=', $kvpair);
         $params[rawurldecode($pair[0])] = rawurldecode($pair[1]);
     }
     return $params;
 }