Пример #1
0
 /**
  * @param string            $url
  * @param string|array|null $args
  * @param string            $method
  * @param array             $options
  * @return Response
  * @throws Exception
  */
 public function request($url, $args = null, $method = Options::DEFAULT_METHOD, array $options = array())
 {
     $method = Filter::up($method);
     $url = 'GET' === $method ? Url::addArg((array) $args, $url) : $url;
     $options = new Options(array_merge($this->_options->getArrayCopy(), $options));
     $client = $this->_getClient($options);
     $response = new Response();
     try {
         list($code, $headers, $body) = $client->request($url, $args, $method, $options);
         $response->setCode($code);
         $response->setHeaders($headers);
         $response->setBody($body);
     } catch (\Exception $e) {
         if ($options->isExceptions()) {
             throw new Exception($e->getMessage(), $e->getCode(), $e);
         } else {
             $response->setCode($e->getCode());
             $response->setHeaders(array());
             $response->setBody($e->getMessage());
         }
     }
     return $response;
 }
Пример #2
0
 public function testGetSameJSON()
 {
     $resp = new Response();
     $resp->setBody($this->_json);
     $json1 = $resp->getJSON();
     $json2 = $resp->getJSON();
     isSame('value-1', $resp->getJSON()->get('key-1'));
     isSame('value-2', $resp->getJSON()->find('key-2'));
     isSame($json1, $json2);
     isSame($json1, $resp->getJSON());
     isSame($json2, $resp->getJSON());
     $resp->setBody($this->_json);
     isNotSame($json1, $resp->getJSON());
     isNotSame($json2, $resp->getJSON());
     isSame($resp->getJSON(), $resp->getJSON());
 }