This tutorial will teach you, how to create your own PEAR::OAI Server backend.
Class File and Name
First of all, you will have to name the class and create the backend class file. Let's assume you call the class 'MyServerBackend' and the file 'MyServerBackend.php'.
Inherit from Abstract Backend Class
This new class inherits its methods from the abstract backend class that comes with PEAR::OAI:
require_once "OAI/Server/Backend.php";
class MyServerBackend extends OAI_ServerBackend
{
}
It does not hurt to have a look at the inherited class to know which methods it offers or requires you to be overwritten. The code is located at OAI/Server/Backend.php after installation of PEAR::OAI. Those methods which need to be overwritten are commented with "Has to be overwritten by each storage class".
It does not matter how you design the interface of your backend class besides the methods it inherits. You can add any other method you would like to, but make sure that you overwrite and keep the names of the methods that return a OAI response.
Overwriting Methods
You could for example overwrite the OAI_ServerBackend::getRecord() method to return some valuable data about a certain record from your repository. Looking at the parent method in the abstract backend class, we see that only an error constant "OAI_METHOD_NOT_SUPPORTED" is returned.
So let's overwrite this function and return some useful metadata:
require_once "OAI/Server/Backend.php";
class MyServerBackend extends OAI_ServerBackend
{
function getRecord()
{
$output =
'<header>'
.'<identifier>1</identifier>'
.'<datestamp>2003-07-01</datestamp>'
.'</header>'
.'<metadata>'
.'...'
.'</metadata>';
return $output;
}
}
Of course, you might rather retrieve data from a database of your choice. This function is meant for demonstration purposes. Whatever routines you execute inside the functions does not matter. What matters is the markup that you return.
Instantiation
To make your backend work with the PEAR::OAI Server, you have to instantiate your backend class first and then pass it to the PEAR::OAI Server class.
// include and instantiate backend
require_once 'MyServerBackend.php';
$backend = new MyServerBackend;
// include and instantiate PEAR::OAI Server
require_once 'OAI/Server.php';
$server = new OAI_Server;
// pass backend to OAI server
$server->backend($backend);
-- SandroZic
PHP Warnings
lib/WikiUser.php:50: Notice[8]: Only variables should be assigned by reference
lib/pear/DB/common.php:741: Notice[8]: Only variable references should be returned by reference
lib/pear/DB/common.php:741: Notice[8]: Only variable references should be returned by reference
lib/pear/DB/common.php:741: Notice[8]: Only variable references should be returned by reference
lib/pear/DB/common.php:741: Notice[8]: Only variable references should be returned by reference
lib/pear/DB/common.php:741: Notice[8]: Only variable references should be returned by reference
lib/pear/DB/common.php:741: Notice[8]: Only variable references should be returned by reference
lib/pear/DB/common.php:741: Notice[8]: Only variable references should be returned by reference
lib/Template.php:220: Notice[8]: Only variables should be assigned by reference
lib/Template.php:106: Notice[8]: Only variables should be assigned by reference
lib/Template.php:107: Notice[8]: Only variables should be assigned by reference
lib/Template.php(In template 'html'?):106: Notice[8]: Only variables should be assigned by reference
lib/Template.php(In template 'html'?):107: Notice[8]: Only variables should be assigned by reference
lib/Template.php(In template 'html'?):106: Notice[8]: Only variables should be assigned by reference
lib/Template.php(In template 'html'?):107: Notice[8]: Only variables should be assigned by reference
lib/Template.php(In template 'body'?)(In template 'html'?):106: Notice[8]: Only variables should be assigned by reference
lib/Template.php(In template 'body'?)(In template 'html'?):107: Notice[8]: Only variables should be assigned by reference
lib/Template.php(In template 'top'?)(In template 'body'?)(In template 'html'?):106: Notice[8]: Only variables should be assigned by reference
lib/Template.php(In template 'top'?)(In template 'body'?)(In template 'html'?):107: Notice[8]: Only variables should be assigned by reference
lib/pear/DB/common.php(In template 'navbar'?)(In template 'top'?)(In template 'body'?)(In template 'html'?):741: Notice[8]: Only variable references should be returned by reference
lib/Template.php(In template 'body'?)(In template 'html'?):106: Notice[8]: Only variables should be assigned by reference
lib/Template.php(In template 'body'?)(In template 'html'?):107: Notice[8]: Only variables should be assigned by reference
lib/Template.php(In template 'browse'?)(In template 'body'?)(In template 'html'?):106: Notice[8]: Only variables should be assigned by reference
lib/Template.php(In template 'browse'?)(In template 'body'?)(In template 'html'?):107: Notice[8]: Only variables should be assigned by reference
lib/Template.php(In template 'actionbar'?)(In template 'browse'?)(In template 'body'?)(In template 'html'?):106: Notice[8]: Only variables should be assigned by reference
lib/Template.php(In template 'actionbar'?)(In template 'browse'?)(In template 'body'?)(In template 'html'?):107: Notice[8]: Only variables should be assigned by reference
lib/Template.php(In template 'body'?)(In template 'html'?):106: Notice[8]: Only variables should be assigned by reference
lib/Template.php(In template 'body'?)(In template 'html'?):107: Notice[8]: Only variables should be assigned by reference
Page Execution took 0.112 seconds |