Пример #1
0
 /**
  * Do a request to get the next batch of items
  *
  * @return int The number of items in the batch after the retrieve
  */
 private function retrieveBatch()
 {
     // Set OAI-PMH parameters for request
     // If resumptionToken, then we ignore params and just use that
     $params = $this->resumptionToken ? ['resumptionToken' => $this->resumptionToken] : $this->params;
     // Node name and verb
     $nodeName = $this->getItemNodeName();
     $verb = $this->verb;
     //Do it..
     $resp = $this->httpClient->request($verb, $params);
     $this->numRequests++;
     //Result format error?
     if (!isset($resp->{$verb}->{$nodeName})) {
         throw new MalformedResponseException(sprintf("Expected XML element list '%s' missing for verb '%s'", $nodeName, $verb));
     }
     //Process the results
     foreach ($resp->{$verb}->{$nodeName} as $node) {
         $this->batch[] = $node;
     }
     //Set the resumption token and expiration date, if specified in the response
     if (isset($resp->{$verb}->resumptionToken)) {
         $this->resumptionToken = (string) $resp->{$verb}->resumptionToken;
         if (isset($resp->{$verb}->resumptionToken['completeListSize'])) {
             $this->totalRecordsInCollection = (int) $resp->{$verb}->resumptionToken['completeListSize'];
         }
         if (isset($resp->{$verb}->resumptionToken['expirationDate'])) {
             $t = $resp->{$verb}->resumptionToken['expirationDate'];
             $this->expireDate = \DateTime::createFromFormat(\DateTime::ISO8601, $t);
         }
     } else {
         //Unset the resumption token when we're at the end of the list
         $this->resumptionToken = null;
     }
     //Return a count
     return count($this->batch);
 }
Пример #2
0
 /**
  * Get a single record
  *
  * @param  string            $id             Record Identifier
  * @param  string            $metadataPrefix Required by OAI-PMH endpoint
  * @return \SimpleXMLElement An XML document corresponding to the record
  */
 public function getRecord($id, $metadataPrefix)
 {
     $params = array('identifier' => $id, 'metadataPrefix' => $metadataPrefix);
     return $this->client->request('GetRecord', $params);
 }