예제 #1
0
 /**
  * @param     $memberId
  * @param int $start
  * @param int $maxResults
  *
  * @return Segment[]|null
  * @throws RepositoryException
  */
 public function findAll($memberId, $start = 0, $maxResults = 100)
 {
     $cacheKey = self::CACHE_NAMESPACE . sha1($memberId . $start . $maxResults);
     if ($this->isCacheEnabled()) {
         if ($this->cache->contains($cacheKey)) {
             return $this->cache->fetch($cacheKey);
         }
     }
     $compiledUrl = $this->baseUrl . $memberId . "?start_element={$start}&num_elements={$maxResults}";
     $response = $this->client->request('GET', $compiledUrl);
     $repositoryResponse = RepositoryResponse::fromResponse($response);
     if (!$repositoryResponse->isSuccessful()) {
         throw RepositoryException::failed($repositoryResponse);
     }
     $stream = $response->getBody();
     $responseContent = json_decode($stream->getContents(), true);
     $stream->rewind();
     $result = [];
     if (!$responseContent['response']['segments']) {
         $responseContent['response']['segments'] = [];
     }
     foreach ($responseContent['response']['segments'] as $segmentArray) {
         $result[] = Segment::fromArray($segmentArray);
     }
     if ($this->isCacheEnabled()) {
         $this->cache->save($cacheKey, $result, self::CACHE_EXPIRATION);
     }
     return $result;
 }