Skip to main content
Skip table of contents

Writing a registry object handler

To extend the Registry Object API, a registry object handler is required.

A list of available handler is available at applications/registry/services/method_handlers/registry_object_handlers/

A handler will use any available resource that is available in the get_resource() function available in the registry_objects API handler file. This is currently limited to:

  • index: The SOLR index of the record, providing the record is indexed correctly
  • xml: The RIFCS of the record
  • gXPath: The DOMXPath of the RIFCS, with the correct namespace
  • ro: The internal ro object of the registry
  • params: the params that is passed to the registry object API
  • default_params: the default params that is defaulted to the registry object API

Using these resource or any other resource, the handler should be able to return an array of result.

For example, this is the description handler located at applications/registry/services/method_handlers/registry_object_handlers/descriptions.php

PHP
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once(SERVICES_MODULE_PATH . 'method_handlers/registry_object_handlers/_ro_handler.php');
/**
* Descriptions handler
* As an example on how to get data from multiple source, index and xml
* @author Minh Duc Nguyen <minh.nguyen@ands.org.au>
* @return array list of description with types
*/
class Descriptions extends ROHandler {
	function handle() {
		$result = array();
        if ($this->xml) {
            foreach($this->xml->{$this->ro->class}->description as $description){
                $type = (string) $description['type'];
                if($type!='rights' && $type!='accessRights'){
                    $description_str = html_entity_decode((string) $description);
                    $result[] = array(
                        'type' => $type,
                        'description' => $description_str
                    );
                }
            }
        }
        return $result;
	}
}

To add a registry object handler, a new handler with a unique name must be registered in the array available near the top of the registry objects API file, located at applications/registry/services/method_handlers/registry_objects.php as  a private $valid_methods array. 

Then a file with a similar name must be placed in applications/registry/services/method_handlers/registry_object_handlers/
This will will contain a class that extends ROHandler with a mandatory function of handle() that returns the result we want

Example

  1. We want to create a handler that returns the registry object name
  2. We add name to the $valid_methods array
  3. We create a name.php file in applications/registry/services/method_handlers/registry_object_handlers/

Content of the name.php file will be

PHP
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once(SERVICES_MODULE_PATH . 'method_handlers/registry_object_handlers/_ro_handler.php');
class name extends ROHandler {
     function handle() {
          $result = array();
          if ($ro) { $result[] = $ro->title ;}
          return $result;
     }
}

By going to registry/services/api/registry_objects/145382/name, we’ll see the expected result

 

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.