The Comfortable PHP SDK can be installed with Composer. Run this command:
composerrequirecomfortable/php-sdk
Usage
Note: This version of the SDK requires PHP 5.6 or greater.
Include the dependency:
<?phprequire_once__DIR__.'/vendor/autoload.php'; // change path as neededuseComfortable;
Connect to your Repository and make your first request:
$api =Comfortable\Api::connect('<repository-api-id>','<api-key>');try {// get all documents stored in comfortable (default limit: 25) $results = $api->getDocuments()->execute(); } catch (\RuntimeException $e) {echo'Comfortalbe SDK returned an error: '. $e->getMessage();exit;}
Full usage Example
<?phpuseComfortable\Api;useComfortable\Filter;useComfortable\Sorting;useComfortable\Includer;// connect to your repository$api =Api::connect('<repository-api-id>','<api-key>');$results = $api->getDocuments()->limit(10)// limits the result to 10->offset(25)// skip the first 25 documents->locale('en')// receive the document in english->includes(2)// includes 2 levels of relations->includeByFields( (newIncluder)->add('relatedNews')// include only the relatedNews instead of all relations)->embedAssets(true)// embed assets directly inside a document instead of using them as includes->includeTags(["include","me"])// include documents with the "include" or "me" tag->excludeTags(["exclude"])// exclude documents with the "exclude" tag->search('this is a fulltext search')// perform a fulltext search->fields('fields(title)')// name the fields you want to receive by the api->sorting( (newSorting)->add('id','ASC','meta')// sort the result ascending by id->add('title','DESC')// sort the result descending by title)->filter( (newFilter)->addAnd('date','greaterThan','01-02-2018')// return only documents greaterThan given date)->execute();