Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function load(ClassMetadata $metadata, ParserInterface $parser, $retries = 0)
 {
     try {
         // Send the request and get the response.
         $response = $this->client->get('files/' . $this->folder . '/children')->send();
     } catch (ClientErrorResponseException $e) {
         if ($this->client->getDefaultOption('request.options/headers/Authorization') && $retries < 1) {
             $this->refreshToken();
             $retries++;
             return $this->load($metadata, $parser, $retries);
         }
         $this->handleBadResponseExceptions($e);
     }
     $json = $response->json();
     $files = $json['items'];
     $batch = array();
     foreach ($files as $file) {
         $batch[] = $this->client->get('files/' . $file['id']);
     }
     try {
         $responses = $this->client->send($batch);
     } catch (MultiTransferException $e) {
         $this->handleBadResponseExceptions($e->getFirst());
     }
     $content = array();
     foreach ($responses as $response) {
         $file = $response->json();
         $response = $this->client->get($file['downloadUrl'])->send();
         $downloadedContent = $response->getBody(true);
         $content[] = $parser->parse($metadata, $file['originalFilename'], $downloadedContent);
     }
     return $content;
 }