Beispiel #1
0
 /**
  * Send the request
  *
  * @param RequestInterface $request The request to send
  *
  * @return MessageInterface The response
  */
 protected function send(RequestInterface $request)
 {
     $response = new Response();
     $client = new FileGetContents();
     $client->send($request, $response);
     return $response;
 }
Beispiel #2
0
 /**
  * @dataProvider provideInvalidHosts
  */
 public function testSendToInvalidUrl($host)
 {
     $this->setExpectedException('RuntimeException');
     $request = new Message\Request();
     $request->fromUrl('http://' . $host . ':12345');
     $response = new Message\Response();
     $client = new FileGetContents();
     $client->setTimeout(0.05);
     $client->send($request, $response);
 }
Beispiel #3
0
 private function doRealRequest($url, array $options)
 {
     $request = new FormRequest(Request::METHOD_POST);
     $request->fromUrl($url);
     $request->setFields($options);
     $response = new Response();
     $client = new FileGetContents();
     $client->send($request, $response);
     return $response->getContent();
 }
Beispiel #4
0
 /**
  * @param string $host
  * @param string $resource
  * @return string
  *   Return the response body from the HTTP request
  */
 public function doRequest($host, $resource)
 {
     if (!($cookieJar = $this->cache->fetch('wesnick.ringcentral.cookies'))) {
         $cookieJar = new CookieJar();
     }
     $client = new FileGetContents($cookieJar);
     $request = new Request(Request::METHOD_GET, $resource, $host);
     $response = new Response();
     $client->setVerifyPeer(false);
     $client->send($request, $response);
     $this->cache->save('wesnick.ringcentral.cookies', $client->getCookieJar());
     return $response->getContent();
 }
Beispiel #5
0
 /**
  * {@inheritdoc}
  */
 public function createClient(array $config = [])
 {
     if (!class_exists('Http\\Adapter\\Buzz\\Client')) {
         throw new \LogicException('To use the Buzz adapter you need to install the "php-http/buzz-adapter" package.');
     }
     $client = new FileGetContents();
     $options = $this->getOptions($config);
     $client->setTimeout($options['timeout']);
     $client->setVerifyPeer($options['verify_peer']);
     $client->setVerifyHost($options['verify_host']);
     $client->setProxy($options['proxy']);
     return new Adapter($client, $this->messageFactory);
 }
 public function getBrowser($_client, $_timeout)
 {
     switch ($_client) {
         case 'curl':
             $client = new Curl();
             break;
         case 'file_get_contents':
             $client = new FileGetContents();
             break;
         default:
             throw new \Exception('Client type "' . $_client . '" is invalid');
     }
     $client->setTimeout($_timeout);
     return new Browser($client);
 }
Beispiel #7
0
 public function doSendRequest(array $options)
 {
     $request = new FormRequest(Request::METHOD_POST);
     $request->fromUrl(static::HTTP_AccessPoint_Send);
     $request->setFields(array('json' => json_encode($options)));
     $response = new Response();
     $client = new FileGetContents();
     $client->send($request, $response);
     $json = $response->getContent();
     $status = json_decode($json, true);
     if (!isset($status[static::Error_Code])) {
         throw new InvalidResponseException('JSON response does not contain response code');
     }
     $normalized_status = $status;
     $normalized_status[self::NORMALIZED_MESSAGE] = $status[self::Error_Message];
     $normalized_status[self::NORMALIZED_CODE] = $status[self::Error_Code];
     return $normalized_status;
 }
 /**
  * @return Curl|FileGetContents
  */
 public static function getClient()
 {
     if (in_array('curl', get_loaded_extensions())) {
         $client = new Curl();
     } else {
         $client = new FileGetContents();
     }
     $client->setVerifyPeer(false);
     $client->setVerifyHost(false);
     return $client;
 }