PHP code example of bcdh / exist-db-rest-client

1. Go to this page and download the library: Download bcdh/exist-db-rest-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bcdh / exist-db-rest-client example snippets


BCDH\ExistDbRestClient\ExistDbServiceProvider::class,

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

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

    // Alternatively, provide the full base URI.
    // 'uri' => 'http://localhost:8080/exist/rest/',

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

use BCDH\ExistDbRestClient\ExistDbRestClient;

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

$client = new ExistDbRestClient();
$query = $client->prepareQuery();

$query->setCollection('CDCatalog');
$query->setQuery($xquery);
$query->bindVariable('artist', 'Bonnie Tyler');

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

use BCDH\ExistDbRestClient\ExistDbRestClient;

$client = new ExistDbRestClient([
    'uri' => 'http://localhost:8080/exist/rest/',
    'user' => 'admin',
    'password' => 'admin',
    'xsl' => 'no',
    'indent' => 'yes',
    'howMany' => 0,
    'start' => 1,
    'wrap' => 'yes',
]);

$query = $client->prepareQuery();
$query->setStoredQuery('cd.xql');
$query->bindParam('price', 7.9);

$result = $query->get();

$query = $client->prepareQuery();
$query->setCollection('CDCatalog');
$query->setResource('new-record.xml');
$query->setBody($xml);

$query->put();

use Sabre\Xml\Service;

$service = new Service();

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

[
    [
        'name' => '{}CD',
        'value' => [
            [
                'name' => '{}TITLE',
                'value' => 'Empire Burlesque',
                'attributes' => [],
            ],
            [
                'name' => '{}ARTIST',
                'value' => 'Bob Dylan',
                'attributes' => [],
            ],
        ],
        'attributes' => [
            'favourite' => '1',
        ],
    ],
]

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

$html = $result->transform(
    __DIR__ . '/xml/cd_catalog_simplified.xsl',
    $document,
    '{}catalog'
);
bash
php artisan vendor:publish --provider="BCDH\ExistDbRestClient\ExistDbServiceProvider"