# PHP

The Comfortable PHP SDK can be installed with [Composer](https://getcomposer.org/). Run this command:

```bash
composer require comfortable/php-sdk
```

### Usage

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

#### Include the dependency:

```php
<?php
require_once __DIR__ . '/vendor/autoload.php'; // change path as needed

use Comfortable;
```

#### Connect to your Repository and make your first request: <a href="#connect-to-your-repository-and-make-your-first-request" id="connect-to-your-repository-and-make-your-first-request"></a>

```php
$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

```php
<?php

use Comfortable\Api;
use Comfortable\Filter;
use Comfortable\Sorting;
use Comfortable\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(
    (new Includer)
      ->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(
    (new Sorting)
      ->add('id', 'ASC', 'meta') // sort the result ascending by id
      ->add('title', 'DESC') // sort the result descending by title
   )
   ->filter(
     (new Filter)
       ->addAnd('date', 'greaterThan', '01-02-2018') // return only documents greaterThan given date
     )
   ->execute();
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.comfortable.io/sdk/php.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
