PHP
The Comfortable PHP SDK can be installed with Composer. Run this command:
1
composer require comfortable/php-sdk
Copied!

Usage

Note: This version of the SDK requires PHP 5.6 or greater.

Include the dependency:

1
<?php
2
require_once __DIR__ . '/vendor/autoload.php'; // change path as needed
3
4
use Comfortable;
Copied!

Connect to your Repository and make your first request:

1
$api = Comfortable\Api::connect('<repository-api-id>', '<api-key>');
2
3
try {
4
// get all documents stored in comfortable (default limit: 25)
5
$results = $api->getDocuments()->execute();
6
} catch (\RuntimeException $e) {
7
echo 'Comfortalbe SDK returned an error: ' . $e->getMessage();
8
exit;
9
}
Copied!

Full usage Example

1
<?php
2
3
use Comfortable\Api;
4
use Comfortable\Filter;
5
use Comfortable\Sorting;
6
use Comfortable\Includer;
7
8
// connect to your repository
9
$api = Api::connect('<repository-api-id>', '<api-key>');
10
11
$results = $api->getDocuments()
12
->limit(10) // limits the result to 10
13
->offset(25) // skip the first 25 documents
14
->locale('en') // receive the document in english
15
->includes(2) // includes 2 levels of relations
16
->includeByFields(
17
(new Includer)
18
->add('relatedNews') // include only the relatedNews instead of all relations
19
)
20
->embedAssets(true) // embed assets directly inside a document instead of using them as includes
21
->includeTags(["include", "me"]) // include documents with the "include" or "me" tag
22
->excludeTags(["exclude"]) // exclude documents with the "exclude" tag
23
->search('this is a fulltext search') // perform a fulltext search
24
->fields('fields(title)') // name the fields you want to receive by the api
25
->sorting(
26
(new Sorting)
27
->add('id', 'ASC', 'meta') // sort the result ascending by id
28
->add('title', 'DESC') // sort the result descending by title
29
)
30
->filter(
31
(new Filter)
32
->addAnd('date', 'greaterThan', '01-02-2018') // return only documents greaterThan given date
33
)
34
->execute();
Copied!
Last modified 3yr ago
Copy link
Contents
Usage