PHP SDK Documentation Documentation du SDK PHP

Requirements Prérequis

  • PHP 8.1 or higher PHP 8.1 ou supérieur
  • Composer
  • ext-curl or Guzzle ext-curl ou Guzzle

Installation Installation

composer require unikhorn/php-sdk

Configuration Configuration

<?php
require_once 'vendor/autoload.php';

use Unikhorn\SDK\UnikhornClient;
use Unikhorn\SDK\Exception\UnikhornException;

// Initialize the client with your API key
$client = new UnikhornClient([
    'api_key' => 'votre-cle-api',
    'base_url' => 'https://api.unikhorn.com', // Optionnel
    'timeout' => 30, // Optionnel, timeout en secondes
    'language' => 'fr' // Optional, default language
]);

Usage Examples Exemples d'utilisation

Calculate a Coat Calculer une robe

<?php

try {
    // Simple calculation with base genes only
    $result = $client->calculateCoat([
        'base' => [
            'agouti' => ['A','A'],
            'extension' => ['E','E']
        ],
        'lang' => 'fr' // Optionnel
    ]);

    echo "Calculated coat: " . $result->getTranslate() . "\n";
    echo "Complete genotype: \n";
    print_r($result->getBase());

} catch (UnikhornException $e) {
    echo "Error: " . $e->getMessage();
}

Calculation with Modifier Genes Calcul avec gènes modificateurs

<?php

try {
    $result = $client->calculateCoat([
        'base' => [
            'agouti' => ['A','a'],
            'extension' => ['E','e']
        ],
        'others' => [
            // Dilution genes
            'matp' => ['Cr','n'],         // MATP (cream/pearl)
            'dun' => ['D','nd2'],         // Dun gene
            'silver' => ['Z','n'],        // Silver gene
            'champagne' => ['Ch','n'],    // Champagne gene
            'grey' => ['G','n'],          // Grey gene
            
            // Pattern/white genes
            'kit' => ['DW2','n'],         // KIT Dominant White 2
            'lp' => ['Lp','n'],           // Leopard Complex
            'lwo' => ['n','n'],           // Lethal White Overo
            'mushroom' => ['Mu','n'],     // Mushroom
            'splash_mift' => ['n','n'],   // Splash MIFT
            'splash_pax3' => ['SW1','n']  // Splash PAX3
        ],
        'lang' => 'fr'
    ]);

    echo "Coat: " . $result->getTranslate() . "\n";
    echo "Base genes: \n";
    print_r($result->getBase());
    echo "Modifier genes: \n";
    print_r($result->getOthers());

} catch (UnikhornException $e) {
    echo "Error: " . $e->getMessage();
}

Generate Offspring Possibilities Générer les possibilités de descendance

<?php

try {
    $offspring = $client->generateOffspring([
        'mother' => [
            'base' => [
                'agouti' => ['A','a'],
                'extension' => ['E','e']
            ],
            'others' => [
                'matp' => ['Cr','n'],
                'dun' => ['D','nd1']
            ]
        ],
        'father' => [
            'base' => [
                'agouti' => ['A','A'],
                'extension' => ['e','e']
            ],
            'others' => [
                'matp' => ['n','n'],
                'dun' => ['D','D']
            ]
        ],
        'lang' => 'fr'
    ]);

    echo "Number of possibilities: " . count($offspring->getResults()) . "\n\n";

    foreach ($offspring->getResults() as $possibility) {
        echo sprintf(
            "- %s (%.2f%%)\n  Genotype: %s %s\n",
            $possibility['coat'],
            $possibility['percentage'],
            $possibility['genotype']['agouti'],
            $possibility['genotype']['extension']
        );
    }

    // Display possibilities grouped by coat
    $grouped = $offspring->getGroupedByCoat();
    foreach ($grouped as $coat => $percentage) {
        echo sprintf("%s : %.2f%%\n", $coat, $percentage);
    }

} catch (UnikhornException $e) {
    echo "Error: " . $e->getMessage();
}

KIT Genetic Linkage Liaison génétique KIT

<?php

// For horses with KIT-linked genes (tobiano, sabino, etc.)
try {
    $offspring = $client->generateOffspring([
        'mother' => [
            'base' => [
                'agouti' => ['A','a'],
                'extension' => ['E','e']
            ],
            'others' => [
                'kit' => ['DW2','n']
            ]
        ],
        'father' => [
            'base' => [
                'agouti' => ['A','A'],
                'extension' => ['e','e']
            ],
            'others' => [
                'kit' => ['n','n']
            ]
        ],
        'kit_linkage' => [
            'mother' => ['E', 'DW2'], // Extension E linked with DW2
            'father' => []
        ],
        'lang' => 'fr'
    ]);

    if ($offspring->hasKitLinkage()) {
        echo "⚠️ KIT genetic linkage detected\n";
        echo "Results account for genetic linkage.\n\n";
    }

    foreach ($offspring->getResults() as $result) {
        echo sprintf("%s : %.2f%%\n", $result['coat'], $result['percentage']);
    }

} catch (UnikhornException $e) {
    echo "Error: " . $e->getMessage();
}

Available Methods Méthodes disponibles

UnikhornClient

Method Méthode Description Description Return Retour
calculateCoat(array $data) Calculate a horse's coat Calcule la robe d'un cheval CoatResult
generateOffspring(array $data) Generate offspring possibilities Génère les possibilités de descendance OffspringResult
getApiKeyInfo() Retrieve API key information Récupère les informations de la clé API ApiKeyInfo
setLanguage(string $lang) Set default language Définit la langue par défaut void

CoatResult

Method Méthode Description Description Return Retour
getTranslate() Translated coat name Nom de la robe traduit string
getBase() Base genes (agouti, extension) Gènes de base (agouti, extension) array
getOthers() Modifier genes Gènes modificateurs array

OffspringResult

Method Méthode Description Description Return Retour
getResults() Complete list of possibilities Liste complète des possibilités array
getGroupedByCoat() Results grouped by coat Résultats groupés par robe array
hasKitLinkage() Indicates if KIT linkage present Indique si liaison KIT présente bool
hasIDK() Indicates if unknown genes present Indique si gènes inconnus présents bool

Error Handling Gestion des erreurs

<?php

use Unikhorn\SDK\Exception\UnikhornException;
use Unikhorn\SDK\Exception\AuthenticationException;
use Unikhorn\SDK\Exception\ValidationException;
use Unikhorn\SDK\Exception\RateLimitException;

try {
    $result = $client->calculateCoat($data);
} catch (AuthenticationException $e) {
    // Authentication error (invalid API key)
    echo "Authentication error: " . $e->getMessage();
} catch (ValidationException $e) {
    // Data validation error
    echo "Invalid data: " . $e->getMessage();
    print_r($e->getErrors()); // Validation error details
} catch (RateLimitException $e) {
    // Rate limit exceeded
    echo "Too many requests. Retry in " . $e->getRetryAfter() . " seconds.";
} catch (UnikhornException $e) {
    // Other API error
    echo "API error: " . $e->getMessage();
} catch (\Exception $e) {
    // General error
    echo "Unexpected error: " . $e->getMessage();
}