Пример #1
0
 /**
  * GET action
  *
  * @param string $url the target URL
  * @param array $options
  * @return PromiseInterface the body of the result
  */
 public function getAsync($url, array $options = [])
 {
     return $this->client->getAsync($url, $options)->then(function (ResponseInterface $response) {
         if ($response->getStatusCode() !== 200) {
             throw new HttpException('HTTP error ' . $response->getStatusCode(), $response->getStatusCode());
         }
         return $response->getBody()->getContents();
     }, function (RequestException $e) {
         throw new HttpException($e->getMessage());
     });
 }
Пример #2
0
 protected function yieldAsyncPromisesForImageUrls() : \Generator
 {
     foreach ($this->imageUrls as $url) {
         (yield $url => $this->guzzleClient->getAsync($url));
     }
 }