The official PHP SDK for the BioLogreen Facial Authentication API.

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/biologreen/sdk

dev-main 2025-09-21 09:53 UTC

This package is auto-updated.

Last update: 2025-12-21 10:39:41 UTC


README

The official PHP SDK for the BioLogreen Facial Authentication API.

This SDK provides a modern, robust, and PSR-4 compliant way for PHP developers to integrate face-based signup and login into their backend applications (e.g., Laravel, Symfony, or any Composer-based project).

Features

  • Modern PHP: Uses namespaces, type-hinting, and PSR-4 autoloading.
  • Robust: Built on the industry-standard Guzzle HTTP client.
  • Clean & Object-Oriented: Provides a simple client and immutable Data Transfer Objects (DTOs).
  • Graceful Error Handling: Throws a custom BioLogreenApiException for predictable error management.

Installation

The recommended way to install the SDK is through Composer.

Run the following command in your project's root directory:

composer require biologreen/sdk

This will download the SDK and automatically configure the autoloader in your vendor/autoload.php file.

Usage
Make sure to include Composer's autoloader at the beginning of your PHP script.

Here is a basic example of how to use the client:

PHP

<?php

// 1. Include the Composer autoloader
require_once __DIR__ . '/vendor/autoload.php';

use BioLogreen\Sdk\BioLogreenClient;
use BioLogreen\Sdk\Exception\BioLogreenApiException;

// It is highly recommended to load your API key from environment variables (.env file)
$apiKey = 'YOUR_SECRET_API_KEY';
$localApiUrl = 'http://localhost:8000/v1'; // Use for local testing

// 2. Create a new client instance
$client = new BioLogreenClient($apiKey, $localApiUrl);

try {
    // --- Example: Signing up a new user ---
    echo "Attempting to sign up a new user...\n";
    $signupImagePath = 'path/to/user_signup_image.jpg';
    $customFields = ['plan' => 'premium', 'userId' => 'user-php-123'];
    
    $signupResponse = $client->signupWithFace($signupImagePath, $customFields);

    echo "Signup Successful!\n";
    echo "New User ID: " . $signupResponse->getUserId() . "\n";
    // Using a ternary operator to print a boolean nicely
    echo "Is New User: " . ($signupResponse->isNewUser() ? 'Yes' : 'No') . "\n";
    print_r($signupResponse->getCustomFields());


    // --- Example: Logging in an existing user ---
    echo "\nAttempting to log in the user...\n";
    $loginImagePath = 'path/to/user_login_image.jpg';
    
    $loginResponse = $client->loginWithFace($loginImagePath);

    echo "Login Successful!\n";
    echo "User ID: " . $loginResponse->getUserId() . "\n";

} catch (BioLogreenApiException $e) {
    // Handle specific API errors
    echo "API Error: " . $e->getMessage() . " (Status Code: " . $e->getStatusCode() . ")\n";
} catch (\Exception $e) {
    // Handle other errors (e.g., file not found, network issues)
    echo "An unexpected error occurred: " . $e->getMessage() . "\n";
}
Contributing
Suggestions and contributions are welcome. Please open an issue or a pull request on the GitHub repository to suggest changes.

License

This SDK is licensed under the MIT License with The Commons Clause. See the LICENSE file for more details.