Skip to content

A Laravel client for querying and transforming results from eXist-db via REST API

License

Notifications You must be signed in to change notification settings

BCDH/Laravel-eXist-db-REST-Client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel eXist-db REST Client

A Laravel client for querying and transforming results from eXist-db via REST API.

Requirements:

  • Laravel 5
  • PHP 5.5
  • PHP XSLT extension
sudo apt-get install php5-xsl

Installing

####1. Add the service provider to your config/app.php:

BCDH\ExistDbRestClient\ExistDbServiceProvider::class

####2. Publish your configuration file:

php artisan vendor:publish

####3. Edit your connection credentials in config/exist-db.php

[
    'user'          => 'admin',
    'password'      => 'admin',

    'protocol'      => 'http',
    'host'          => 'localhost',
    'port'          => 8080,
    'path'          => 'exist/rest',

    /* alternatively, you can specify the URI as a whole in the form */
    // 'uri'=>'http://localhost:8080/exist/rest/'

    'xsl'           => 'no',
    'indent'        => 'yes',
    'howMany'       => 10,
    'start'         => 1,
    'wrap'          => 'yes'
]

Usage

use BCDH\ExistDbRestClient\ExistDbRestClient;

$q = 'for $cd in /CD[./ARTIST=$artist] return $cd';

$connection = new ExistDbRestClient();

$query = $connection->prepareQuery();
$query->bindVariable('artist', 'Bonnie Tyler');
$query->setCollection("CDCatalog");
$query->setQuery($q);

$result = $query->get();
$document = $result->getDocument();

Result formatting

sabre/xml library is used for parsing xml result. You can pass an instance of \Sabre\Xml\Service with your own (de)serializers to Query request methods

Result example

array(
    array(
        'name' => '{}CD',
        'value' => array(
            0 => array(
                'name' => '{}TITLE',
                'value' => 'Empire Burlesque',
                'attributes' => array(),
            ),
            1 => array(
                'name' => '{}ARTIST',
                'value' => 'Bob Dylan',
                'attributes' => array(),
            ),
            2 => array(
                'name' => '{}COUNTRY',
                'value' => 'USA',
                'attributes' => array(),
            ),
            3 => array(
                'name' => '{}COMPANY',
                'value' => 'Columbia',
                'attributes' => array(),
            )
        ),
        'attributes' =>  array (
            'favourite' => '1',
        ),
    ),
);

XLS transformations

  • Single result
$result = $query->get();
$document = $result->getDocument();
$singleCd = $document[0];

$html = $result->transform(__DIR__ . '/xml/cd_catalog_simplified.xsl', $singleCd);
  • Result
$result = $query->get();
$document = $result->getDocument();
$rootTagName = '{}catalog';

$html = $result->transform(__DIR__ . '/xml/cd_catalog_simplified.xsl', $document, $rootTagName);

About

A Laravel client for querying and transforming results from eXist-db via REST API

Resources

License

Stars

Watchers

Forks

Packages

No packages published