bcdh/exist-db-rest-client

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

v1.0.4 2016-05-12 14:32 UTC

This package is not auto-updated.

Last update: 2024-04-13 16:07:17 UTC


README

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);