bcdh / exist-db-rest-client
eXist-db 通过 REST API 查询和转换结果的 Laravel 客户端
v1.0.4
2016-05-12 14:32 UTC
Requires
- php: ~5.5|~7.0
- guzzlehttp/guzzle: ^5.0|^6.0
- illuminate/support: 5.*
- sabre/xml: ~1.4
Requires (Dev)
- phpunit/phpunit: 4.*
- scrutinizer/ocular: ~1.1
- squizlabs/php_codesniffer: ~2.3
This package is not auto-updated.
Last update: 2024-09-14 18:42:16 UTC
README
通过 REST API 查询和转换 eXist-db 的结果的 Laravel 客户端。
要求
- Laravel 5
- PHP 5.5
- PHP XSLT 扩展
sudo apt-get install php5-xsl
安装
####1. 将服务提供者添加到 config/app.php
BCDH\ExistDbRestClient\ExistDbServiceProvider::class
####2. 发布你的配置文件
php artisan vendor:publish
####3. 编辑 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'=>'https://:8080/exist/rest/'
'xsl' => 'no',
'indent' => 'yes',
'howMany' => 10,
'start' => 1,
'wrap' => 'yes'
]
使用方法
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();
结果格式化
sabre/xml 库用于解析 XML 结果。您可以将带有您自己的(反)序列化器的 \Sabre\Xml\Service 实例传递给查询请求方法
结果示例
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 转换
- 单个结果
$result = $query->get(); $document = $result->getDocument(); $singleCd = $document[0]; $html = $result->transform(__DIR__ . '/xml/cd_catalog_simplified.xsl', $singleCd);
- 结果
$result = $query->get(); $document = $result->getDocument(); $rootTagName = '{}catalog'; $html = $result->transform(__DIR__ . '/xml/cd_catalog_simplified.xsl', $document, $rootTagName);