GithubHelp home page GithubHelp logo

sebas932 / php-oai-pmh-client Goto Github PK

View Code? Open in Web Editor NEW

This project forked from scriptotek/php-oai-pmh-client

0.0 2.0 0.0 257 KB

PHP OAI-PMH client with a clean API

License: MIT License

PHP 100.00%

php-oai-pmh-client's Introduction

Build Status Coverage Status Code Quality Latest Stable Version Total Downloads

php-oai-pmh-client

Simple PHP client package for fetching data from an OAI-PMH server, using the Guzzle HTTP client. The returned data is parsed by QuiteSimpleXMLElement.

On network problems, the client will retry a configurable number of times, emitting a request.error event each time, before finally throwing a ConnectionError.

Install using Composer

composer require scriptotek/oai-pmh-client

Example

require_once('vendor/autoload.php');
use Scriptotek\OaiPmh\Client as OaiPmhClient;

$url = 'http://oai.bibsys.no/repository';

$client = new OaiPmhClient($url, array(
    'schema' => 'marcxchange',
    'user-agent' => 'MyTool/0.1',
    'max-retries' => 10,
    'sleep-time-on-error' => 30,
));

Fetching a single record

try {
    $record = $client->record('oai:bibsys.no:biblio:113889372');
} catch (Scriptotek\OaiPmh\ConnectionError $e) {
    echo $e->getMsg();
    die;
} catch (Scriptotek\OaiPmh\BadRequestError $e) {
    echo 'Bad request: ' . $e->getMsg() . "\n";
    die;
}

echo $record->identifier . "\n";
echo $record->datestamp . "\n";
echo $record->data->asXML() . "\n";

Iterating over a record set

foreach ($client->records('') as $record) {
	echo $record->identifier . "\n";
	echo $record->datestamp . "\n";
}

Events

$client->on('request.start', function($verb) {
    print "Starting " . $verb . " request\n";
});
$client->on('request.error', function($err) {
    print "Non-fatal error: " . $err . "\n";
});
$client->on('request.complete', function($verb) {
    print "Completed " . $verb . " request\n";
});

API documentation

API documentation can be generated using e.g. Sami, which is included in the dev requirements of composer.json.

php vendor/bin/sami.php update sami.config.php -v

You can view it at scriptotek.github.io/php-oai-pmh-client

php-oai-pmh-client's People

Contributors

danmichaelo avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.