-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.php
62 lines (50 loc) · 1.64 KB
/
run.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
require __DIR__ . '/vendor/autoload.php';
use Phpoaipmh\Client;
use Phpoaipmh\Endpoint;
use Phpoaipmh\Exception\MalformedResponseException;
use Phpoaipmh\HttpAdapter\GuzzleAdapter;
use GuzzleHttp\Client as GuzzleClient;
$zbUrl = getenv( 'zbMATHUrl' ) ?: 'https://oai.zbmath.org/v1/';
$metaFormat = getenv( 'zbMATHFormat' ) ?: 'oai_dc';
$date = date( DateTime::ISO8601 );
$options = [];
if ( getenv( 'zbMATHApiKey' ) !== false ) {
$options = [
'headers' => [ 'X-API-KEY' => getenv( 'zbMATHApiKey' ) ],
];
}
$guzzle = new GuzzleAdapter( new GuzzleClient( $options ) );
class ErrorReportingClient extends Client {
protected function decodeResponse( $resp ): SimpleXMLElement {
try {
return parent::decodeResponse( $resp );
}
catch ( MalformedResponseException $exception ) {
error_log( "MalformedResponseException: " . $resp );
throw $exception;
}
}
}
$myEndpoint = new Endpoint( new ErrorReportingClient( $zbUrl, $guzzle ) );
$results = $myEndpoint->listMetadataFormats();
$iterator = $myEndpoint->listRecords( $metaFormat );
echo "Total count is " . ( $iterator->getTotalRecordCount() ?: 'unknown' );
// Write the header
echo /** @lang XML */
"<?xml version=\"1.0\" encoding=\"utf-8\"?>
<OAI-PMH xmlns=\"http://www.openarchives.org/OAI/2.0/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd\">
<responseDate>$date</responseDate>
<request metadataPrefix=\"$metaFormat\" verb=\"ListRecords\">$zbUrl</request>
<ListRecords>
";
foreach ( $iterator as $rec ) {
echo $rec->asXML();
}
// Write the footer
echo /** @lang XML */
<<<XML
</ListRecords>
</OAI-PMH>
XML;