makina-corpus / nucliadb-php-client
PHP client for NucliaDB API
Requires
- php: >=7.4
- symfony/http-client: ~5.4
This package is not auto-updated.
Last update: 2025-05-07 22:45:25 UTC
README
Disclaimer : This library still in development. It had been setup in order to develop some PHP CMS specific modules, while keeping in common any possible part of code. At this state, the library implements only a small subset of the web api calls. Feel free to PR unimplemented ones to make this lib grow up. Some useful contributors' documentation can be found in this repository's docs/contributors directory.
Usage
Initialize client API
use Nuclia\ApiClient; $token = '<your-nucliadb-token>'; $kbid = '<your-nucliadb-knoledgebox-id>'; $zone = '<your-nucliadb-zone>'; //Such as 'europe-1' $apiClient = new ApiClient($zone, $token, $kbid);
Using search API
The search API aims to reflect NucliaDB search web API
Create a search API instance
$searchApi = $apiClient->createSearchApi();
Run a simple full text search
use Nuclia\Query\SearchQuery; $response = $searchApi->search((new SearchQuery())->setQuery('you+shall+not+pass'));
$response
returns an instance of Symfony HTTP Client response
Using resources API
The resources API aims to reflect NucliaDB resources web API
Create a resource API instance
$resourcesApi = $apiClient->createResourcesApi();
Get resource.
use Nuclia\Query\GetResourceQuery; $rid = '<resource-id>' $response = $resourcesApi->getResource($rid,(new GetResourceQuery() ->setShow(EnumArray::show([ShowEnum::VALUES, ShowEnum::BASIC])) );
Create resource.
$response = $resourcesApi->createResource([ 'title' => 'The Fellowship of the Ring', 'links' => [ 'link-1' => [ 'uri' => 'https://en.wikipedia.org/wiki/The_Lord_of_the_Rings:_The_Fellowship_of_the_Ring' ] ] ]);
Update resource.
$rid = '<resource-id>' $response = $resourcesApi->modifyResource( $rid, [ 'title' => 'The Fellowship of the Ring (Updated)', 'links' => [ 'link-1' => [ 'uri' => 'https://www.rottentomatoes.com/m/the_lord_of_the_rings_the_fellowship_of_the_ring' ] ] ]);
Delete resource.
$rid = '<resource-id>' $resourcesApi->deleteResource($rid);
Using resource fields API
The resource fields API aims to reflect NucliaDB resource fields web API
Create a resource fields API instance
$resourceFieldsApi = $apiClient->createResourceFieldsApi();
Upload a binary File as a resource field
$body = file_get_contents('The-Fellowship-Of-The-Ring.jpg', 'r'); $md5 = md5($body); $rid = '<resource-id>' $fieldId = '<field-id>' // A free string used to identify your file field in resource. $response = $resourceFieldsApi->uploadBinaryFile($rid, $fieldId, $body, (new UploadBinaryFileHeaders())->setMd5($md5));