PHP SDK
عميل PHP متوافق مع PSR-18 بأنواع صارمة. يدعم PHP 8.1+.
التثبيت
composer require kalimalab/kalimalab-phpℹالمتطلبات
PHP 8.1+ مع ext-json وعميل HTTP متوافق مع PSR-18 (Guzzle أو Symfony HttpClient).
تهيئة العميل
<?phpuse KalimaLab\Client;$client = new Client($_ENV['KALIMALAB_API_KEY']);الطرق
$client->words()->searchابحث في الكلمات العربية مع فلاتر اختيارية.
$client->words()->search(array $params): SearchResult| Param | Type | Req | Description |
|---|---|---|---|
q | string | Yes | استعلام البحث |
limit | int | No | 1-100. الافتراضي: 20 |
offset | int | No | إزاحة الترقيم |
root | string | No | فلتر بالجذر |
pos | string | No | فلتر تصنيف الكلام |
$result = $client->words()->search([ 'q' => 'كتب', 'limit' => 10,]);echo $result->total; // 47echo $result->data[0]->word; // 'كتب'$client->words()->getجلب التفاصيل الكاملة لكلمة واحدة.
$client->words()->get(string $slug): Word| Param | Type | Req | Description |
|---|---|---|---|
slug | string | Yes | slug الكلمة أو معرّفها |
$word = $client->words()->get('كتب');echo $word->meaning_en; // 'to write'$client->words()->dailyاحصل على كلمة اليوم.
$client->words()->daily(): Word$word = $client->words()->daily();echo $word->word; // 'الأَمَل'$client->words()->validateتحقق من صحة الكلمات العربية في قاعدة البيانات.
$client->words()->validate(array $words): ValidationResult| Param | Type | Req | Description |
|---|---|---|---|
words | string[] | Yes | حتى 100 كلمة |
$result = $client->words()->validate(['كتب', 'xyz', 'مدرسة']);print_r($result->valid); // ['كتب', 'مدرسة']print_r($result->invalid); // ['xyz']$client->text()->analyzeحلّل مقطعاً من النص العربي.
$client->text()->analyze(string $text): TextAnalysis| Param | Type | Req | Description |
|---|---|---|---|
text | string | Yes | نص عربي (حد أقصى 5,000 حرف) |
$analysis = $client->text()->analyze('بسم الله الرحمن الرحيم');echo $analysis->word_count; // 4معالجة الأخطاء
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();}