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


PHP Client::get方法代码示例

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


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

示例1: scrape

 /**
  * Scrape URL and collect output
  * @param string $url
  * @param OutputInterface $output
  */
 public function scrape($url, OutputInterface $output)
 {
     $this->collection->exchangeArray([]);
     try {
         $initialPage = $this->client->get($url)->send();
     } catch (BadResponseException $e) {
         $output->writeln('<error>' . $e->getMessage() . '</error>');
         throw new \RuntimeException('Unable to load initial page');
     }
     $xml = $this->getSimpleXml($initialPage->getBody());
     $items = $xml->xpath($this->config['collection']);
     foreach ($items as $item) {
         $title = $item->xpath($this->config['title']);
         $unitPrice = $item->xpath($this->config['unitPrice']);
         $itemUrl = $item->xpath($this->config['itemUrl']);
         $itemSize = 0;
         $itemDesc = null;
         if (isset($itemUrl[0]->attributes()['href'])) {
             try {
                 $itemPage = $this->client->get((string) $itemUrl[0]->attributes()['href'])->send();
                 $itemPageBody = $this->getSimpleXml($itemPage->getBody());
                 $itemSize = $itemPage->getContentLength();
                 $itemDesc = $itemPageBody->xpath($this->config['desc']);
             } catch (BadResponseException $e) {
                 $output->writeln('<error>' . $e->getMessage() . '</error>');
             }
         }
         if ($title && $unitPrice) {
             $parsedPrice = (double) \trim(\str_replace('&pound', null, $unitPrice[0]));
             $this->collection->append(['title' => \trim($title[0]), 'unit_price' => $parsedPrice, 'description' => \trim($itemDesc[0]), 'size' => \round($itemSize / 1024) . 'kb']);
         }
     }
     return $this->collection;
 }
开发者ID:pharman,项目名称:Test,代码行数:39,代码来源:Scraper.php

示例2: lookupAddress

 /**
  * @param string $postalCode
  * @param string $houseNumber
  * @return array
  */
 public function lookupAddress($postalCode, $houseNumber)
 {
     $this->client->setConfig(['curl.options' => ['CURLOPT_CONNECTTIMEOUT_MS' => '2000', 'CURLOPT_RETURNTRANSFER' => true]]);
     $url = sprintf($this->baseUrl . '/%s/%s', $postalCode, $houseNumber);
     $request = $this->client->get($url)->setAuth($this->apiKey, $this->apiSecret);
     return $request->send()->json();
 }
开发者ID:dannyvw,项目名称:laravel-postcodenl,代码行数:12,代码来源:Postcodenl.php

示例3: getDocument

 /**
  * @return \DOMDocument
  */
 public function getDocument()
 {
     $request = $this->client->get($this->url);
     $this->response = $request->send();
     $this->setHtml($this->response->getBody(true));
     return parent::getDocument();
 }
开发者ID:robmasters,项目名称:optimus,代码行数:10,代码来源:GuzzleAdapter.php

示例4: injectScript

 /**
  * Injects the livereload script.
  *
  * @param Response $response A Response instance
  */
 protected function injectScript(Response $response)
 {
     if (function_exists('mb_stripos')) {
         $posrFunction = 'mb_strripos';
         $substrFunction = 'mb_substr';
     } else {
         $posrFunction = 'strripos';
         $substrFunction = 'substr';
     }
     $content = $response->getContent();
     $pos = $posrFunction($content, '</body>');
     if (false !== $pos) {
         $script = "livereload.js";
         if ($this->checkServerPresence) {
             // GET is required, as livereload apparently does not support HEAD requests ...
             $request = $this->httpClient->get($script);
             try {
                 $checkResponse = $this->httpClient->send($request);
                 if ($checkResponse->getStatusCode() !== 200) {
                     return;
                 }
             } catch (CurlException $e) {
                 // If error is connection failed, we assume the server is not running
                 if ($e->getCurlHandle()->getErrorNo() === 7) {
                     return;
                 }
                 throw $e;
             }
         }
         $content = $substrFunction($content, 0, $pos) . "\n" . '<script src="' . $this->httpClient->getBaseUrl() . $script . '"></script>' . "\n" . $substrFunction($content, $pos);
         $response->setContent($content);
     }
 }
开发者ID:bakie,项目名称:KunstmaanBundlesCMS,代码行数:38,代码来源:ScriptInjectorListener.php

示例5: get

 /**
  * @inheritdoc
  */
 public function get($url)
 {
     $request = $this->client->get($url);
     $this->setHeaders($request);
     $response = $request->send();
     return json_decode($response->getBody(true));
 }
开发者ID:erliz,项目名称:jira-api-client-guzzle-provider,代码行数:10,代码来源:Client.php

示例6: parse

 /**
  * parse
  *
  * @param  string $text
  *
  * @return array
  */
 public function parse($text)
 {
     $request = $this->client->get();
     $request->getQuery()->set('text', $text);
     $data = $request->send()->json();
     return $this->processSuggestions($text, $data);
 }
开发者ID:kcahir,项目名称:tweetcompare,代码行数:14,代码来源:Parser.php

示例7: authenticate

 public function authenticate(array $credentials)
 {
     $mcrypt = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, '');
     $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($mcrypt), MCRYPT_DEV_RANDOM);
     mcrypt_generic_init($mcrypt, $this->cryptPassword, $iv);
     $url = $this->getUrl($credentials[self::USERNAME], $credentials[self::PASSWORD], $mcrypt, $iv);
     try {
         $res = $this->httpClient->get($url)->send();
     } catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) {
         if ($e->getResponse()->getStatusCode() === 403) {
             throw new \Nette\Security\AuthenticationException("User '{$credentials[self::USERNAME]}' not found.", self::INVALID_CREDENTIAL);
         } elseif ($e->getResponse()->getStatusCode() === 404) {
             throw new \Nette\Security\AuthenticationException("Invalid password.", self::IDENTITY_NOT_FOUND);
         } else {
             throw $e;
         }
     }
     $responseBody = trim(mdecrypt_generic($mcrypt, $res->getBody(TRUE)));
     $apiData = Json::decode($responseBody);
     $user = $this->db->table('users')->where('id = ?', $apiData->id)->fetch();
     $registered = new \DateTimeImmutable($apiData->registered->date, new \DateTimeZone($apiData->registered->timezone));
     $userData = array('username' => $credentials[self::USERNAME], 'password' => $this->calculateAddonsPortalPasswordHash($credentials[self::PASSWORD]), 'email' => $apiData->email, 'realname' => $apiData->realname, 'url' => $apiData->url, 'signature' => $apiData->signature, 'language' => $apiData->language, 'num_posts' => $apiData->num_posts, 'apiToken' => $apiData->apiToken, 'registered' => $registered->getTimestamp());
     if (!$user) {
         $userData['id'] = $apiData->id;
         $userData['group_id'] = 4;
         $this->db->table('users')->insert($userData);
         $user = $this->db->table('users')->where('username = ?', $credentials[self::USERNAME])->fetch();
     } else {
         $user->update($userData);
     }
     return $this->createIdentity($user);
 }
开发者ID:newPOPE,项目名称:web-addons.nette.org,代码行数:32,代码来源:NetteOrgAuthenticator.php

示例8: product

 /**
  * Query product
  *
  * @param $productId
  * @return mixed
  */
 public function product($productId)
 {
     $query = ['apikey' => Config::get('providers.' . $this->provider)['apikey']];
     $url = $this->baseUrl . "products/{$productId}?" . http_build_query($query);
     $request = $this->client->get($url);
     $response = $request->send();
     return $response->json()['products'][0];
 }
开发者ID:hackersofamsterdam,项目名称:doh-php,代码行数:14,代码来源:bol.php

示例9: get

 /**
  * @param string $uri
  * @param array $params
  * @param null $headers
  * @return array|null
  */
 public function get($uri, $params = [], $headers = null)
 {
     if (!empty($params)) {
         $uri .= '?' . http_build_query($params);
     }
     $response = $this->client->get($uri, $headers)->send();
     return $this->parseResponse($response);
 }
开发者ID:seregazhuk,项目名称:php-headhunter-api,代码行数:14,代码来源:GuzzleHttpAdater.php

示例10: getFileContent

 /**
  * @param string $file
  * @return string
  */
 public function getFileContent($file)
 {
     $request = $this->client->get('/exports/openstackcert/' . $file);
     $request->setAuth(COA_FILE_API_BASE_USER, COA_FILE_API_BASE_PASS);
     $response = $request->send();
     $content = (string) $response->getBody();
     return $content;
 }
开发者ID:OpenStackweb,项目名称:openstack-org,代码行数:12,代码来源:COAFileApi.php

示例11: getLinhas

 public function getLinhas($termosBusca)
 {
     $request = $this->client->get('Linha/Buscar');
     $request->addCookie('apiCredentials', $this->apiCredentials);
     $request->getQuery()->set('termosBusca', $termosBusca);
     $response = $request->send();
     return $response->json();
 }
开发者ID:rodrigorigotti,项目名称:api-olho-vivo,代码行数:8,代码来源:OlhoVivo.php

示例12: getUserDetails

 /**
  * Return the current users information 
  * 
  * @param  Array $authorization
  * @return Array
  */
 public function getUserDetails(array $authorization)
 {
     $endpoint = "people/me.json";
     $url = "{$authorization['accounts'][0]['href']}/{$endpoint}";
     $whoami = $this->client->get($url)->send()->json();
     $avatar = parse_url($whoami['avatar_url']);
     return ['name' => $whoami['name'], 'firstName' => $authorization['identity']['first_name'], 'lastName' => $authorization['identity']['last_name'], 'email' => $whoami['email_address'], 'avatar' => "//{$avatar['host']}/{$avatar['path']}?{$avatar['query']}"];
 }
开发者ID:bigset1,项目名称:blueridge,代码行数:14,代码来源:OAuth.php

示例13: prepareRequest

 /**
  * @param string $method
  * @param array $context
  * @return \Guzzle\Http\Message\RequestInterface
  */
 protected function prepareRequest($method, $context = array())
 {
     $request = $this->client->get($method);
     $query = $request->getQuery();
     foreach ($context as $key => $value) {
         $query->set($key, $value);
     }
     return $request;
 }
开发者ID:Cherkesov,项目名称:GFB-SocialClient,代码行数:14,代码来源:AbstractRestClient.php

示例14: get

 /**
  * @param string $uri
  * @param array $headers
  * @param array $options
  * @return array|\Guzzle\Http\Message\Response|null
  */
 public function get($uri, $headers = [], $options = [])
 {
     if (!$uri) {
         return null;
     }
     $this->request = $this->client->get($uri, $headers, $options);
     $this->response = $this->request->send();
     return $this->response;
 }
开发者ID:chilimatic,项目名称:database-component,代码行数:15,代码来源:Connection.php

示例15: handle

 /**
  * {@inheritdoc}
  */
 public function handle($workload)
 {
     /** @var PageDocument $document */
     $document = $this->documentManager->find($workload['uuid'], $workload['locale']);
     $urls = $this->webspaceManager->findUrlsByResourceLocator($document->getResourceSegment(), $this->environment, $workload['locale'], $workload['webspaceKey']);
     foreach ($urls as $url) {
         $this->client->get($url)->send();
     }
 }
开发者ID:php-task,项目名称:SuluTaskBundle,代码行数:12,代码来源:PageWarmupHandler.php


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