PHP SDK
PSR-18 compatible PHP client with strict types. Requires PHP 8.1+.
Installation
bash
composer require kalimalab/kalimalab-phpℹRequirements
PHP 8.1+ with ext-json and a PSR-18 compatible HTTP client (Guzzle or Symfony HttpClient).
Client initialization
php
<?phpuse KalimaLab\Client;$client = new Client($_ENV['KALIMALAB_API_KEY']);Methods
$client->words()->searchSearch Arabic words with optional filters.
php
$client->words()->search(array $params): SearchResult| Param | Type | Req | Description |
|---|---|---|---|
q | string | Yes | Search query |
limit | int | No | 1–100. Default: 20 |
offset | int | No | Pagination offset |
root | string | No | Filter by root |
pos | string | No | Part-of-speech filter |
php
$result = $client->words()->search([ 'q' => 'كتب', 'limit' => 10,]);echo $result->total; // 47echo $result->data[0]->word; // 'كتب'$client->words()->getFetch full details for a single word.
php
$client->words()->get(string $slug): Word| Param | Type | Req | Description |
|---|---|---|---|
slug | string | Yes | Word slug or ID |
php
$word = $client->words()->get('كتب');echo $word->meaning_en; // 'to write'$client->words()->dailyGet the word of the day.
php
$client->words()->daily(): Wordphp
$word = $client->words()->daily();echo $word->word; // 'الأَمَل'$client->words()->validateValidate Arabic words against the database.
php
$client->words()->validate(array $words): ValidationResult| Param | Type | Req | Description |
|---|---|---|---|
words | string[] | Yes | Up to 100 words |
php
$result = $client->words()->validate(['كتب', 'xyz', 'مدرسة']);print_r($result->valid); // ['كتب', 'مدرسة']print_r($result->invalid); // ['xyz']$client->text()->analyzeAnalyze a passage of Arabic text.
php
$client->text()->analyze(string $text): TextAnalysis| Param | Type | Req | Description |
|---|---|---|---|
text | string | Yes | Arabic text (max 5,000 characters) |
php
$analysis = $client->text()->analyze('بسم الله الرحمن الرحيم');echo $analysis->word_count; // 4Error handling
php
use KalimaLab\Exception\KalimaLabException;try { $result = $client->words()->search(['q' => 'كتب']);} catch (KalimaLabException $e) { echo $e->getStatus(); // 401, 429, 500 echo $e->getCode(); // 'unauthorized', 'rate_limited' echo $e->getMessage();}