当前位置: 首页>>代码示例>>PHP>>正文


PHP Client::createRequest方法代码示例

本文整理汇总了PHP中GuzzleHttp\Client::createRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::createRequest方法的具体用法?PHP Client::createRequest怎么用?PHP Client::createRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GuzzleHttp\Client的用法示例。


在下文中一共展示了Client::createRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createRequest

 /**
  * @param string $url
  * @param string $method
  * @param array $options
  * @return \GuzzleHttp\Message\Request
  */
 protected function createRequest($url, $method = 'GET', $options = array())
 {
     // $defaults = array('future' => true, 'debug' => true);
     $defaults = array('future' => true);
     $req = $this->client->createRequest($method, $url, array_merge($defaults, $options));
     return $req;
 }
开发者ID:hirasso,项目名称:wordpress-shariff-wrapper,代码行数:13,代码来源:Request.php

示例2: subscribe

 /**
  * Method to handle the Subscribe Request to the Hub
  */
 public function subscribe()
 {
     // Start empty $hubUrl variable
     $hubUrl = '';
     // Check if the Hub URL finishes with a / or not to be able to create the correct subscribe URL
     if (preg_match("/\\/\$/", $this->current_options['hub_url'])) {
         $hubUrl = $this->current_options['hub_url'] . 'subscribe';
     } else {
         $hubUrl = $this->current_options['hub_url'] . '/subscribe';
     }
     // Json Data needed to send to the Hub for Subscription
     $subscribeJson = json_encode(array("callbackUrl" => esc_url($this->callbackUrl), "topicId" => esc_url($this->current_options['topic_url'])), JSON_UNESCAPED_SLASHES);
     $subscribeRequest = $this->guzzleClient->createRequest('POST', $hubUrl);
     $subscribeRequest->setHeader('Content-Type', 'application/json');
     $subscribeRequest->setBody(Stream::factory($subscribeJson));
     $subscribeResponse = $this->guzzleClient->send($subscribeRequest);
     // Check if Response is 200, 202 or 204 and add a log message otherwise log error message
     if (in_array($subscribeResponse->getStatusCode(), array(200, 202, 204))) {
         HubLogger::log('Your Subscription request is being processed. Check back later to see if you are fully Subscribed', $subscribeResponse->getStatusCode());
         return true;
     } else {
         HubLogger::error('Error issuing Subscribe request to the Hub. Please make sure all your details are correct', $subscribeResponse->getStatusCode());
         return false;
     }
 }
开发者ID:dannyoz,项目名称:tls,代码行数:28,代码来源:HubSubscriber.php

示例3: forwardIpn

 /**
  * @param IpnEntity $ipn
  * @return bool
  */
 public function forwardIpn(IpnEntity $ipn)
 {
     $urls = $ipn->getForwardUrls();
     if (!empty($urls)) {
         $requests = [];
         foreach ($urls as $url) {
             $request = $this->guzzle->createRequest('post', $url);
             $request->setHeader($this->customHeader, $this->getKey());
             if (in_array($url, $this->disabledJsonFormatting)) {
                 $request->getQuery()->merge($ipn->toArray());
             } else {
                 $request->setHeader('content-type', 'application/json');
                 if ($this->formatter) {
                     $response = $this->formatter->formatJsonResponse($ipn);
                 } else {
                     $response = ['ipn' => $ipn->toArray()];
                 }
                 $request->setBody(Stream::factory(json_encode($response)));
             }
             $requests[] = $request;
         }
         $this->guzzle->sendAll($requests, ['parallel' => $this->maxRequests]);
         return true;
     }
     return false;
 }
开发者ID:iyoworks,项目名称:ipn-forwarder,代码行数:30,代码来源:Forwarder.php

示例4: getRequest

 /**
  * Handles all api calls
  * 
  * @param string $uri
  * @param array $params
  * @return array
  * @throws \Exception
  */
 public function getRequest($uri, array $params = [])
 {
     // validate uri
     if (!is_string($uri)) {
         throw new InvalidArgumentException("Invalid uri {$uri} submitted.");
     }
     // make sure uri isn't absolute - remove first / if there
     if ($uri[0] == '/') {
         $uri = substr($uri, 1);
     }
     try {
         $request = $this->client->createRequest('GET', $uri, ['query' => $params]);
         $response = $this->client->send($request)->json();
         // cairo returns 200 even for errors so check response for error
         // errors array can have multiple, which do we show? create one string for all?
         if (!empty($response['errors'])) {
             throw RequestException::create($request, new Response($response['errors'][0]['code'], [], null, ['reason_phrase' => $response['errors'][0]['messages'][0]]));
         }
     } catch (RequestException $e) {
         $message = $e->getRequest() . "\n";
         if ($e->hasResponse()) {
             $message .= $e->getResponse() . "\n";
         }
         throw new Exception($message, $e->getCode());
     }
     return $response;
 }
开发者ID:joeyrivera,项目名称:badgeville-php,代码行数:35,代码来源:Sites.php

示例5: upload

 /**
  * Performs a upload request
  *
  * @param  Request $request
  * @return An array attactment objects
  */
 public function upload(Request $request)
 {
     $this->emit('before.request', [$request, &$this->headers]);
     $files = $request->getFiles();
     if ($files->count() == 0) {
         throw new \UnexpectedValueException("Upload request must have at least one file.");
     }
     $options = ['headers' => $this->headers, 'cookies' => true, 'verify' => false];
     if (!empty($this->_authToken)) {
         $options['cookies'] = array('ZM_AUTH_TOKEN' => $this->_authToken);
     }
     $httpRequest = $this->_httpClient->createRequest('POST', $this->_location, $options);
     $postBody = $httpRequest->getBody();
     $postBody->setField('requestId', $request->getRequestId());
     foreach ($files as $file) {
         $postBody->addFile(new PostFile(basename($file), fopen($file, 'r')));
     }
     $httpRequest->setQuery(['fmt' => 'raw,extended']);
     try {
         $response = $this->_httpClient->send($httpRequest);
         $this->emit('after.request', [$response, $response->getHeaders()]);
     } catch (BadResponseException $ex) {
         if ($ex->hasResponse()) {
             $response = $ex->getResponse();
             $this->emit('after.request', [$response, $response->getHeaders()]);
         }
         throw $ex;
     }
     return $this->_parseResponse($response);
 }
开发者ID:zimbra-api,项目名称:upload,代码行数:36,代码来源:Client.php

示例6: request

 /**
  * Guzzle 4 Request method implementation
  *
  * @param string $httpMethod
  * @param string $path
  * @param array $params
  * @param null $version
  * @param bool $isAuthorization
  *
  * @return Response|mixed
  * @throws ClientException
  * @throws AuthorizeException
  * @throws ServerException
  * @throws Error
  */
 public function request($httpMethod = 'GET', $path = '', $params = array(), $version = null, $isAuthorization = false)
 {
     $guzzleClient = new GuzzleClient();
     switch ($httpMethod) {
         case 'GET':
             $request = $guzzleClient->createRequest($httpMethod, $path, array('query' => $params));
             break;
         default:
             $request = $guzzleClient->createRequest($httpMethod, $path, array('body' => $params));
     }
     try {
         $res = $guzzleClient->send($request);
     } catch (GuzzleException\ClientException $e) {
         //catch error 404
         $error_message = $e->getResponse();
         if ($isAuthorization) {
             throw new AuthorizeException($error_message, $e->getCode(), $e->getPrevious());
         } else {
             throw new ClientException($error_message, $e->getCode(), $e->getPrevious());
         }
     } catch (GuzzleException\ServerException $e) {
         throw new ServerException($e, $e->getCode(), $e->getPrevious());
     } catch (GuzzleException\BadResponseException $e) {
         throw new Error($e->getResponse(), $e->getCode(), $e->getPrevious());
     }
     $response = new Response($res->json(), $res->getCode());
     return $response;
 }
开发者ID:siliconstraits,项目名称:cems-php-sdk,代码行数:43,代码来源:Guzzle4.php

示例7: request

 /**
  * @param string $method
  * @param string $uri
  * @param array  $options
  *
  * @return ResponseInterface
  */
 public function request($method, $uri, array $options = [])
 {
     $this->lazyLoadGuzzle();
     $this->lastRequest = $this->guzzle->createRequest($method, $uri, $options);
     $response = $this->guzzle->send($this->lastRequest);
     return $response;
 }
开发者ID:prgtw,项目名称:basecrm-php-api,代码行数:14,代码来源:GuzzleClient.php

示例8: createBaseRequest

 protected function createBaseRequest($accessToken, $method, $baseUrl)
 {
     $request = $this->client->createRequest($method, $baseUrl);
     //        $request->getQuery()->set("api_key", $this->apiKey);
     $request->setHeaders($this->getHeaders($accessToken));
     return $request;
 }
开发者ID:guodont,项目名称:transrush-sdk,代码行数:7,代码来源:BaseService.php

示例9: doRequest

 /**
  * @return array
  */
 public function doRequest() : array
 {
     $this->generateRequestOptions();
     $this->authenticator->authenticate($this);
     $request = $this->httpClient->createRequest($this->method, $this->getUrl(), $this->requestOptions);
     return $this->httpClient->send($request)->json();
 }
开发者ID:silwerclaw,项目名称:jirapi,代码行数:10,代码来源:Request.php

示例10: send

 /**
  * {@InheritDoc}
  */
 public function send(Request $request)
 {
     $guzzleRequest = $this->client->createRequest($request->getMethod(), $request->getUri(), ['headers' => $request->getHeaders()]);
     $guzzleRequest->setBody(Stream::factory($request->getBody()));
     $guzzleResponse = $this->getClient()->send($guzzleRequest);
     $response = new Response($guzzleResponse->getStatusCode(), $guzzleResponse->getHeaders(), $guzzleResponse->getBody(true));
     return $response;
 }
开发者ID:canaltp,项目名称:fenrir-api-client,代码行数:11,代码来源:Guzzle5.php

示例11: sendGuzzleRequest

 protected function sendGuzzleRequest($http_verb = 'GET', $url, $data = null)
 {
     if (date(time()) >= Session::get('oauth_token_expiry')) {
         $this->refreshAccessToken();
     }
     $request = $this->client->createRequest($http_verb, $url, ['json' => $data, 'headers' => ['Authorization' => 'Bearer ' . Session::get('access_token')]]);
     return $this->client->send($request)->json();
 }
开发者ID:adrielpdeguzman,项目名称:chainofmemories_gui,代码行数:8,代码来源:BaseController.php

示例12: broadcast

 /**
  * Broadcast the given event.
  *
  * @param  array $channels
  * @param  string $event
  * @param  array $payload
  * @return void
  */
 public function broadcast(array $channels, $event, array $payload = array())
 {
     foreach ($channels as $channel) {
         $payload = ['text' => array_merge(['eventtype' => $event], $payload)];
         $request = $this->client->createRequest('POST', '/pub?id=' . $channel, ['json' => $payload]);
         $response = $this->client->send($request);
     }
 }
开发者ID:cmosguy,项目名称:laravel-http-pushstream-broadcaster,代码行数:16,代码来源:PushStreamBroadcaster.php

示例13: execute

 public function execute($method, $uri, $data)
 {
     $request = $this->guzzleClient->createRequest($method, $uri, $data);
     /** @var ResponseInterface $response */
     /** @noinspection PhpVoidFunctionResultUsedInspection */
     $response = $this->guzzleClient->send($request);
     return new Response($response);
 }
开发者ID:credibility,项目名称:dandb,代码行数:8,代码来源:Requester.php

示例14: prepareRequest

 /**
  * @param  Request       $request
  * @return GuzzleRequest
  */
 protected function prepareRequest(Request $request)
 {
     $guzzleRequest = $this->client->createRequest($request->getMethod(), (string) $request->getUrl(), array('version' => $request->getProtocolVersion()));
     if (null !== ($content = $request->getContent())) {
         $guzzleRequest->setBody(Stream::factory($content));
     }
     $guzzleRequest->setHeaders($this->prepareHeaders($request));
     return $guzzleRequest;
 }
开发者ID:saxulum,项目名称:saxulum-http-client-adapter-guzzle,代码行数:13,代码来源:HttpClient.php

示例15: buildBaseRequest

 protected function buildBaseRequest()
 {
     $request = $this->client->createRequest(Settings::GET, Settings::BASE_URL . $this->ENDPOINT_URL, Settings::$CREATE_REQUEST_OPTIONS);
     if ($this->supportsLocalization) {
         $query = $request->getQuery();
         $query->set(Settings::LANG, Settings::$LOCALE);
     }
     return $request;
 }
开发者ID:EtienneLamoureux,项目名称:durmand-scriptorium,代码行数:9,代码来源:RequestFactory.php


注:本文中的GuzzleHttp\Client::createRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。