當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Browser::getClient方法代碼示例

本文整理匯總了PHP中Buzz\Browser::getClient方法的典型用法代碼示例。如果您正苦於以下問題:PHP Browser::getClient方法的具體用法?PHP Browser::getClient怎麽用?PHP Browser::getClient使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Buzz\Browser的用法示例。


在下文中一共展示了Browser::getClient方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: __construct

 /**
  * @param $timeout
  */
 public function __construct($timeout, $logger)
 {
     $this->browser = new Browser(new Curl());
     $this->browser->getClient()->setVerifyPeer(false);
     $this->browser->getClient()->setTimeout($timeout);
     $this->logger = $logger;
 }
開發者ID:gbelmm,項目名稱:RMSPushNotificationsBundle,代碼行數:10,代碼來源:MicrosoftNotification.php

示例2: send

 /**
  * @param array $data
  *
  * @return array|string|null
  *
  * @throws \Exception
  */
 public function send($data = null)
 {
     $request = new FormRequest($this->method, $this->resource, $this->host);
     if ($data) {
         $request->addFields($data);
     }
     try {
         $this->logger->addDebug('Request: ' . $request->getUrl());
         /** @var Buzz\Message\Response $response */
         $response = $this->client->send($request);
         $this->logger->addDebug('Response: ' . $response->getStatusCode() . ' ' . substr($response->getContent(), 0, 300) . PHP_EOL . var_export($this->client->getClient()->getInfo(), true));
     } catch (\Exception $e) {
         switch ($e->getCode()) {
             case 28:
                 $code = 504;
                 break;
             default:
                 $code = $e->getCode() >= 100 ? $e->getCode() : 500;
         }
         $this->logger->addCritical(PHP_EOL . __METHOD__ . sprintf('[%s/%s] %s', $e->getCode(), $code, $e->getMessage()));
         throw new WebGateException($e->getMessage(), $code, $e);
     }
     if ($response->getStatusCode() != 200) {
         throw new WebGateException(json_decode($response->getContent(), true), $response->getStatusCode());
     }
     return json_decode($response->getContent(), true);
 }
開發者ID:avtonom,項目名稱:web-gate-bundle,代碼行數:34,代碼來源:RestService.php

示例3: send

 /**
  * Sends the data to the given registration IDs via the GCM server
  *
  * @param  \RMS\PushNotificationsBundle\Message\MessageInterface              $message
  * @throws \RMS\PushNotificationsBundle\Exception\InvalidMessageTypeException
  * @return bool
  */
 public function send(MessageInterface $message)
 {
     if (!$message instanceof AndroidMessage) {
         throw new InvalidMessageTypeException(sprintf("Message type '%s' not supported by GCM", get_class($message)));
     }
     if (!$message->isGCM()) {
         throw new InvalidMessageTypeException("Non-GCM messages not supported by the Android GCM sender");
     }
     $headers = array("Authorization: key=" . $this->apiKey, "Content-Type: application/json");
     $data = array_merge($message->getGCMOptions(), array("data" => $message->getData()));
     // Chunk number of registration IDs according to the maximum allowed by GCM
     $chunks = array_chunk($message->getGCMIdentifiers(), $this->registrationIdMaxCount);
     // Perform the calls (in parallel)
     $this->responses = array();
     foreach ($chunks as $registrationIDs) {
         $data["registration_ids"] = $registrationIDs;
         $this->responses[] = $this->browser->post($this->apiURL, $headers, json_encode($data));
     }
     // If we're using multiple concurrent connections via MultiCurl
     // then we should flush all requests
     if ($this->browser->getClient() instanceof MultiCurl) {
         $this->browser->getClient()->flush();
     }
     // Determine success
     foreach ($this->responses as $response) {
         $message = json_decode($response->getContent());
         if ($message === null || $message->success == 0 || $message->failure > 0) {
             return false;
         }
     }
     return true;
 }
開發者ID:Yameveo,項目名稱:RMSPushNotificationsBundle,代碼行數:39,代碼來源:AndroidGCMNotification.php

示例4: __construct

 /**
  * Class constructor.
  *
  * @param $apiKey
  * @param null $apiUrl
  */
 public function __construct($apiKey, $apiUrl = null)
 {
     $this->apiKey = $apiKey;
     if ($apiUrl) {
         $this->apiUrl = $apiUrl;
     }
     $this->browser = new Browser(new MultiCurl());
     $this->browser->getClient()->setVerifyPeer(false);
 }
開發者ID:LucasSales,項目名稱:TrabalhoAndroid,代碼行數:15,代碼來源:Client.php

示例5: __construct

 /**
  * @param array $options
  */
 public function __construct(array $options = [])
 {
     $this->options = array_merge(static::getDefaultConfigs(), $options);
     $buzzClassName = $this->options['buzz.class'];
     $this->buzz = new $buzzClassName();
     $this->servers = $this->options['replay.http_client.servers'];
     // Increase timeout
     $this->buzz->getClient()->setTimeout($this->options['buzz.timeout']);
 }
開發者ID:phxlol,項目名稱:lol-replay-downloader,代碼行數:12,代碼來源:ReplayClient.php

示例6: execute

 /**
  * Execute an Api request
  *
  * @param string $endpoint
  * @param array $payload
  * @param array $options
  * @return mixed
  */
 public function execute($endpoint, array $payload, array $options = [])
 {
     $endpoint = $this->baseEndpoint . $endpoint;
     // set a timeout if applicable
     if (isset($options['timeout'])) {
         $this->transport->getClient()->setTimeout((int) $options['timeout']);
     } else {
         if (isset($this->timeout)) {
             $this->transport->getClient()->setTimeout((int) $this->timeout);
         }
     }
     $response = $this->transport->post($endpoint, $this->getHeaders(), json_encode(['meta' => ['when' => date('Y-m-d H:i:s'), 'server' => gethostname()], 'data' => $payload]));
     return json_decode($response->getContent(), true);
 }
開發者ID:kabudu,項目名稱:silex-api-client-service-provider,代碼行數:22,代碼來源:BuzzClient.php

示例7: __construct

 /**
  * Instantiated a new http client
  *
  * @param array        $options Http client options
  * @param null|Browser $browser Buzz client
  */
 public function __construct(array $options = array(), Browser $browser = null)
 {
     $this->options = array_merge($this->options, $options);
     $this->browser = $browser ?: new Browser(new Curl());
     $this->browser->getClient()->setTimeout($this->options['timeout']);
     $this->browser->getClient()->setVerifyPeer(false);
     if (null !== $this->options['login'] || null !== $this->options['token']) {
         if (null !== $this->options['token']) {
             $options = array($this->options['token']);
         } else {
             $options = array($this->options['login'], $this->options['password']);
         }
         $this->browser->addListener(new AuthListener($this->options['auth_method'], $options));
     }
 }
開發者ID:nickl-,項目名稱:php-github-api,代碼行數:21,代碼來源:HttpClient.php

示例8: flush

 /**
  * Flush notifications. Triggers the requests.
  *
  * @return array|bool If there are no errors, return true.
  *                    If there were no notifications in the queue, return false.
  *                    Else return an array of information for each notification sent (success, statusCode, headers, content)
  *
  * @throws \ErrorException
  */
 public function flush()
 {
     if (empty($this->notifications)) {
         return false;
     }
     // for each endpoint server type
     $responses = $this->prepareAndSend($this->notifications);
     // if multi curl, flush
     if ($this->browser->getClient() instanceof MultiCurl) {
         /** @var MultiCurl $multiCurl */
         $multiCurl = $this->browser->getClient();
         $multiCurl->flush();
     }
     /** @var Response|null $response */
     $return = array();
     $completeSuccess = true;
     foreach ($responses as $i => $response) {
         if (!isset($response)) {
             $return[] = array('success' => false, 'endpoint' => $this->notifications[$i]->getEndpoint());
             $completeSuccess = false;
         } elseif (!$response->isSuccessful()) {
             $return[] = array('success' => false, 'endpoint' => $this->notifications[$i]->getEndpoint(), 'statusCode' => $response->getStatusCode(), 'headers' => $response->getHeaders(), 'content' => $response->getContent(), 'expired' => in_array($response->getStatusCode(), array(400, 404, 410)));
             $completeSuccess = false;
         } else {
             $return[] = array('success' => true);
         }
     }
     // reset queue
     $this->notifications = null;
     return $completeSuccess ? true : $return;
 }
開發者ID:minishlink,項目名稱:web-push,代碼行數:40,代碼來源:WebPush.php

示例9: post

 /**
  * @param string $url
  *   The URL to POST to
  * @param SiteDocument $site
  *   The site being posted to
  * @param array $params
  *   An array of keys and values to be posted
  *
  * @return mixed
  *   The content of the response
  *
  * @throws WardenRequestException
  *   If any error occurs
  */
 public function post($url, SiteDocument $site, array $params = array())
 {
     try {
         $this->setClientTimeout($this->connectionTimeout);
         // Don't verify SSL certificate.
         // @TODO make this optional
         $this->buzz->getClient()->setVerifyPeer(FALSE);
         if ($site->getAuthUser() && $site->getAuthPass()) {
             $headers = array(sprintf('Authorization: Basic %s', base64_encode($site->getAuthUser() . ':' . $site->getAuthPass())));
             $this->setConnectionHeaders($headers);
         }
         $params['token'] = $this->sslEncryptionService->generateRequestToken();
         $content = http_build_query($params);
         /** @var \Buzz\Message\Response $response */
         $response = $this->buzz->post($url, $this->connectionHeaders, $content);
         if (!$response->isSuccessful()) {
             $this->logger->addError("Unable to request data from {$url}\nStatus code: " . $response->getStatusCode() . "\nHeaders: " . print_r($response->getHeaders(), TRUE));
             throw new WardenRequestException("Unable to request data from {$url}. Check log for details.");
         }
         $site->setLastSuccessfulRequest();
         $this->siteManager->updateDocument();
         return $response->getContent();
     } catch (ClientException $clientException) {
         throw new WardenRequestException($clientException->getMessage());
     }
 }
開發者ID:TWEagle,項目名稱:warden,代碼行數:40,代碼來源:SiteConnectionService.php

示例10: checkAnswer

 /**
  * Calls an HTTP POST function to verify if the user's guess was correct
  *
  * @param string $remoteIp
  * @param string $challenge
  * @param string $response
  * @throws Exception
  * @return boolean
  */
 public function checkAnswer($remoteIp, $challenge, $response)
 {
     $headers = array('Connection' => 'close');
     $content = array('private_key' => $this->privateKey, 'session_token' => $response, 'simple_mode' => 1);
     $browser = new Browser();
     $browser->getClient()->setVerifyPeer(false);
     try {
         /** @var Response $resp */
         $resp = $browser->post(self::VERIFY_SERVER, $headers, http_build_query($content));
     } catch (Exception $e) {
         throw new CaptchaException('Failed to send captcha', 500, $e);
     }
     if (!$resp->isSuccessful()) {
         throw new CaptchaException('Error: ' . $resp->getStatusCode());
     }
     $answer = $resp->getContent();
     if (!$answer) {
         throw new CaptchaException('Error: Invalid captcha response');
     }
     $success = isset($answer) && filter_var($answer, FILTER_VALIDATE_INT);
     if (!$success) {
         return new CaptchaResponse($success, 'Invalid captcha');
     }
     return new CaptchaResponse($success);
 }
開發者ID:iamraghavgupta,項目名稱:paytoshi-faucet,代碼行數:34,代碼來源:FuncaptchaService.php

示例11: checkAnswer

 /**
  * Calls an HTTP POST function to verify if the user's guess was correct
  *
  * @param string $remoteIp
  * @param string $challenge
  * @param string $response
  * @throws Exception
  * @return boolean
  */
 public function checkAnswer($remoteIp, $challenge, $response)
 {
     if (empty($remoteIp)) {
         throw new CaptchaException('RemoteIp missing');
     }
     $headers = array('Connection' => 'close');
     $content = array('secret' => $this->privateKey, 'remoteip' => $remoteIp, 'response' => $response);
     $browser = new Browser();
     $browser->getClient()->setVerifyPeer(false);
     try {
         /** @var Response $resp */
         $resp = $browser->post(self::VERIFY_SERVER, $headers, http_build_query($content));
     } catch (Exception $e) {
         throw new CaptchaException('Failed to check captcha', 500, $e);
     }
     if (!$resp->isSuccessful()) {
         throw new CaptchaException('Error: ' . $resp->getStatusCode());
     }
     $answer = json_decode($resp->getContent());
     if (!$answer) {
         throw new CaptchaException('Error: Invalid captcha response');
     }
     $success = isset($answer->success) && filter_var($answer->success, FILTER_VALIDATE_BOOLEAN);
     if (!$success) {
         return new CaptchaResponse($success, 'Invalid captcha');
     }
     return new CaptchaResponse($success);
 }
開發者ID:iamraghavgupta,項目名稱:paytoshi-faucet,代碼行數:37,代碼來源:RecaptchaService.php

示例12: sendInternalRequest

 /**
  * {@inheritdoc}
  */
 protected function sendInternalRequest(InternalRequestInterface $internalRequest)
 {
     $this->browser->getClient()->setTimeout($this->getConfiguration()->getTimeout());
     $this->browser->getClient()->setMaxRedirects(0);
     $request = $this->browser->getMessageFactory()->createRequest($internalRequest->getMethod(), $uri = (string) $internalRequest->getUri());
     $request->setProtocolVersion($internalRequest->getProtocolVersion());
     $request->setHeaders($this->prepareHeaders($internalRequest, false));
     $data = $this->browser->getClient() instanceof AbstractCurl ? $this->prepareContent($internalRequest) : $this->prepareBody($internalRequest);
     $request->setContent($data);
     try {
         $response = $this->browser->send($request);
     } catch (\Exception $e) {
         throw HttpAdapterException::cannotFetchUri($uri, $this->getName(), $e->getMessage());
     }
     return $this->getConfiguration()->getMessageFactory()->createResponse($response->getStatusCode(), (string) $response->getProtocolVersion(), HeadersNormalizer::normalize($response->getHeaders()), BodyNormalizer::normalize($response->getContent(), $internalRequest->getMethod()));
 }
開發者ID:KGalley,項目名稱:whathood,代碼行數:19,代碼來源:BuzzHttpAdapter.php

示例13: __construct

 /**
  * Mockable constructor.
  * @param Browser $browser Buzz instance
  * @param array $options
  */
 public function __construct(Browser $browser, array $options)
 {
     if ($browser->getClient() instanceof FileGetContents) {
         throw new \InvalidArgumentException('The FileGetContents client is known not to work with this library. Please instantiate the Browser with an instance of \\Buzz\\Client\\Curl');
     }
     $this->browser = $browser;
     $this->options = $options;
 }
開發者ID:JoeShiels1,項目名稱:YouTrack,代碼行數:13,代碼來源:YouTrackCommunicator.php

示例14: sendRequest

 /**
  * Sends a request.
  *
  * @param string $url     The url.
  * @param string $method  The http method.
  * @param array  $headers The header.
  * @param array  $content The content.
  *
  * @throws \Widop\HttpAdapter\HttpAdapterException If an error occured.
  *
  * @return \Widop\HttpAdapter\HttpResponse The response.
  */
 private function sendRequest($url, $method, array $headers = array(), array $content = array())
 {
     $this->browser->getClient()->setMaxRedirects($this->getMaxRedirects());
     try {
         $response = $this->browser->call($url, $method, $headers, $content);
     } catch (\Exception $e) {
         throw HttpAdapterException::cannotFetchUrl($url, $this->getName(), $e->getMessage());
     }
     return $this->createResponse($response->getStatusCode(), $url, $response->getHeaders(), $response->getContent());
 }
開發者ID:widop,項目名稱:http-adapter,代碼行數:22,代碼來源:BuzzHttpAdapter.php

示例15: setBrowser

 /**
  * @param Browser $browser
  */
 public function setBrowser(Browser $browser)
 {
     $client = $browser->getClient();
     $client->setVerifyPeer(false);
     $client->setTimeout(30);
     if ($client instanceof \Buzz\Client\Curl) {
         $client->setOption(CURLOPT_USERAGENT, 'KnpBundles.com Bot');
     }
     $this->browser = $browser;
 }
開發者ID:KnpLabs,項目名稱:KnpBundles,代碼行數:13,代碼來源:Travis.php


注:本文中的Buzz\Browser::getClient方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。