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()->get

Fetch full details for a single word.

php
$client->words()->get(string $slug): Word
ParamTypeReqDescription
slugstringYesWord slug or ID
php
$word = $client->words()->get('كتب');echo $word->meaning_en; // 'to write'
$client->words()->daily

Get the word of the day.

php
$client->words()->daily(): Word
php
$word = $client->words()->daily();echo $word->word; // 'الأَمَل'
$client->words()->validate

Validate Arabic words against the database.

php
$client->words()->validate(array $words): ValidationResult
ParamTypeReqDescription
wordsstring[]YesUp to 100 words
php
$result = $client->words()->validate(['كتب', 'xyz', 'مدرسة']);print_r($result->valid);   // ['كتب', 'مدرسة']print_r($result->invalid); // ['xyz']
$client->text()->analyze

Analyze a passage of Arabic text.

php
$client->text()->analyze(string $text): TextAnalysis
ParamTypeReqDescription
textstringYesArabic text (max 5,000 characters)
php
$analysis = $client->text()->analyze('بسم الله الرحمن الرحيم');echo $analysis->word_count; // 4

Error 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();}