Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bcdh/laravel-exist-db-rest-client
A Laravel client for querying and transforming results from eXist-db via REST API
https://github.com/bcdh/laravel-exist-db-rest-client
Last synced: about 2 months ago
JSON representation
A Laravel client for querying and transforming results from eXist-db via REST API
- Host: GitHub
- URL: https://github.com/bcdh/laravel-exist-db-rest-client
- Owner: BCDH
- License: gpl-2.0
- Created: 2016-05-09T15:10:11.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-11-08T18:15:16.000Z (about 8 years ago)
- Last Synced: 2024-11-18T07:00:01.604Z (about 2 months ago)
- Language: PHP
- Size: 38.1 KB
- Stars: 3
- Watchers: 4
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
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
```bash
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
```php
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](http://sabre.io/xml/reading/) 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
```php
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
```php
$result = $query->get();
$document = $result->getDocument();
$singleCd = $document[0];$html = $result->transform(__DIR__ . '/xml/cd_catalog_simplified.xsl', $singleCd);
```- Result
```php
$result = $query->get();
$document = $result->getDocument();
$rootTagName = '{}catalog';$html = $result->transform(__DIR__ . '/xml/cd_catalog_simplified.xsl', $document, $rootTagName);
```