getkeymanager / codeigniter-sdk
Official CodeIgniter 4 SDK for License Management Platform - Easy license validation, activation, and management for CodeIgniter applications
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/getkeymanager/codeigniter-sdk
Requires
- php: ^7.4 || ^8.0
- codeigniter4/framework: ^4.0
- getkeymanager/php-sdk: ^2.0
Requires (Dev)
- phpstan/phpstan: ^1.8
- phpunit/phpunit: ^9.5
README
Official CodeIgniter 4 SDK for License Management Platform. Easy license validation, activation, and management for CodeIgniter applications with library support and helper functions.
Features
- 🚀 Easy Integration - Simple library and helper functions
- 🎨 CodeIgniter-Native - Follows CodeIgniter 4 conventions
- 🛠️ Helper Functions - Convenient global functions
- 📝 Full Logging - Optional CodeIgniter logging integration
- ⚡ Response Caching - Automatic caching support
- 🔄 CodeIgniter 4.x - Full compatibility
- ✨ NEW: State-Based Validation - Enterprise-grade state management
- 🛡️ NEW: Grace Period Support - 72-hour failover protection
- 🔐 NEW: Enhanced Security - RSA-4096 signature verification
- 📊 NEW: API Response Codes - Standardized error handling
🆕 What's New in v2.0
The CodeIgniter SDK has been hardened with enterprise-grade features:
State-Based Validation
Instead of raw API responses, use typed LicenseState objects:
helper('getkeymanager'); $state = resolve_license_state($key); if ($state->isActive()) { // License is fully active } elseif ($state->isInGracePeriod()) { // Grace period - network issues } else { // Invalid }
Grace Period Protection
Automatic 72-hour grace period when API is unreachable:
- Prevents service disruption from network issues
- Cached licenses remain valid temporarily
- Configurable duration
Enhanced Error Handling
use GetKeyManager\CodeIgniter\Core\ApiResponseCode; use GetKeyManager\CodeIgniter\Core\LicenseException; try { $state = resolve_license_state($key); } catch (LicenseException $e) { $code = $e->getApiCode(); $name = $e->getApiCodeName(); $message = ApiResponseCode::getMessage($code); }
New State-Based Helpers
// Check license status is_license_active($key); is_license_in_grace_period($key); // Feature checking can_use_feature($key, 'premium_reports'); // State management $state = get_license_state($key); // Get cached state clear_license_state($key); // Clear cache
👉 See HARDENING_COMPLETE.md for full documentation
✅ 100% Backward Compatible - All existing code continues to work!
Requirements
- PHP 7.4 or higher
- CodeIgniter 4.0 or higher
- ext-json, ext-openssl, ext-curl
Installation
Install via Composer:
composer require getkeymanager/codeigniter-sdk
Configuration
Copy the configuration file to your app/Config directory:
cp vendor/getkeymanager/codeigniter-sdk/src/Config/GetKeyManager.php app/Config/
Edit app/Config/GetKeyManager.php:
<?php namespace Config; use GetKeyManager\CodeIgniter\Config\GetKeyManager as BaseGetKeyManager; class GetKeyManager extends BaseGetKeyManager { public string $apiKey = 'your-api-key-here'; public string $baseUrl = 'https://api.getkeymanager.com'; public string $environment = 'production'; public bool $verifySignatures = true; public ?string $publicKey = '-----BEGIN PUBLIC KEY----- ... -----END PUBLIC KEY-----'; // ... other settings }
Using Environment Variables
You can also use .env file:
LICENSE_MANAGER_API_KEY=your-api-key-here LICENSE_MANAGER_BASE_URL=https://api.getkeymanager.com LICENSE_MANAGER_ENVIRONMENT=production LICENSE_MANAGER_VERIFY_SIGNATURES=true LICENSE_MANAGER_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----\n...\n-----END PUBLIC KEY-----"
And load them in config:
public string $apiKey; public function __construct() { parent::__construct(); $this->apiKey = getenv('LICENSE_MANAGER_API_KEY'); }
Quick Start
Using the Library
<?php namespace App\Controllers; use GetKeyManager\CodeIgniter\Libraries\GetKeyManagerLibrary; class License extends BaseController { private GetKeyManagerLibrary $getkeymanager; public function __construct() { $this->getkeymanager = new GetKeyManagerLibrary(); } public function validate() { $licenseKey = $this->request->getPost('license_key'); $result = $this->getkeymanager->validateLicense($licenseKey, [ 'hardwareId' => $this->getkeymanager->generateHardwareId() ]); if ($result['success']) { return $this->response->setJSON([ 'status' => 'valid', 'data' => $result['data'] ]); } else { return $this->response->setJSON([ 'status' => 'invalid', 'message' => $result['message'] ], 400); } } }
Using Helper Functions
<?php namespace App\Controllers; class Dashboard extends BaseController { public function index() { // Load the helper helper('getkeymanager'); $licenseKey = session()->get('license_key'); // Simple validation check if (!is_license_valid($licenseKey)) { return redirect()->to('/license-required'); } // Check feature if (is_feature_enabled($licenseKey, 'advanced-reports')) { $data['show_advanced_reports'] = true; } // Get full details $licenseDetails = get_license_details($licenseKey); $data['license'] = $licenseDetails['data'] ?? []; return view('dashboard', $data); } }
Library Usage
Basic Operations
use GetKeyManager\CodeIgniter\Libraries\GetKeyManagerLibrary; $license = new GetKeyManagerLibrary(); // Validate license $result = $license->validateLicense('XXXXX-XXXXX-XXXXX-XXXXX'); // Activate license $result = $license->activateLicense('XXXXX-XXXXX-XXXXX-XXXXX', [ 'hardwareId' => $license->generateHardwareId(), 'name' => 'Production Server' ]); // Deactivate license $result = $license->deactivateLicense('XXXXX-XXXXX-XXXXX-XXXXX', [ 'hardwareId' => $license->generateHardwareId() ]); // Check feature $result = $license->checkFeature('XXXXX-XXXXX-XXXXX-XXXXX', 'premium-features');
Offline Validation
// Read offline license file $offlineLicense = file_get_contents(WRITEPATH . 'licenses/offline.lic'); $result = $license->validateOfflineLicense($offlineLicense, [ 'hardwareId' => $license->generateHardwareId() ]);
Creating Licenses
$result = $license->createLicenseKeys( 'product-uuid', 'generator-uuid', [ ['activation_limit' => 5, 'validity_days' => 365], ['activation_limit' => 1, 'validity_days' => 30] ], 'customer@example.com' ); foreach ($result['data']['licenses'] as $lic) { echo "Created: " . $lic['license_key'] . "\n"; }
Helper Functions Reference
Load the helper in your controller or view:
helper('getkeymanager');
Available Functions
getkeymanager(): GetKeyManagerLibrary
Get the library instance.
$license = getkeymanager();
validate_license(string $licenseKey, array $options = []): array
Validate a license key.
$result = validate_license('XXXXX-XXXXX-XXXXX-XXXXX', [ 'hardwareId' => generate_hardware_id() ]);
is_license_valid(string $licenseKey, array $options = []): bool
Quick boolean check if license is valid.
if (is_license_valid($licenseKey)) { // License is valid }
activate_license(string $licenseKey, array $options = []): array
Activate a license.
$result = activate_license('XXXXX-XXXXX-XXXXX-XXXXX', [ 'hardwareId' => generate_hardware_id() ]);
deactivate_license(string $licenseKey, array $options = []): array
Deactivate a license.
$result = deactivate_license('XXXXX-XXXXX-XXXXX-XXXXX', [ 'hardwareId' => generate_hardware_id() ]);
check_feature(string $licenseKey, string $featureName): array
Check if a feature is enabled.
$result = check_feature('XXXXX-XXXXX-XXXXX-XXXXX', 'api-access');
is_feature_enabled(string $licenseKey, string $featureName): bool
Quick boolean check if feature is enabled.
if (is_feature_enabled($licenseKey, 'exports')) { // Show export button }
get_license_details(string $licenseKey): array
Get detailed license information.
$details = get_license_details('XXXXX-XXXXX-XXXXX-XXXXX');
generate_hardware_id(): string
Generate a hardware ID for this device.
$hwid = generate_hardware_id();
generate_uuid(): string
Generate a UUID v4.
$uuid = generate_uuid();
validate_offline_license($offlineLicenseData, array $options = []): array
Validate an offline license file.
$offlineData = file_get_contents('license.lic'); $result = validate_offline_license($offlineData);
Filter/Middleware Example
Create a filter for route protection:
<?php namespace App\Filters; use CodeIgniter\Filters\FilterInterface; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; class LicenseFilter implements FilterInterface { public function before(RequestInterface $request, $arguments = null) { helper('getkeymanager'); $licenseKey = session()->get('license_key'); if (!$licenseKey || !is_license_valid($licenseKey)) { return redirect()->to('/license-required') ->with('error', 'Valid license required'); } // Check specific feature if provided if ($arguments && is_feature_enabled($licenseKey, $arguments[0]) === false) { return redirect()->to('/upgrade-required') ->with('error', 'This feature requires an upgrade'); } } public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) { // Do nothing } }
Register in app/Config/Filters.php:
public array $aliases = [ 'license' => \App\Filters\LicenseFilter::class, ];
Use in routes:
$routes->group('dashboard', ['filter' => 'license'], function($routes) { $routes->get('/', 'Dashboard::index'); $routes->get('reports', 'Dashboard::reports', ['filter' => 'license:advanced-reports']); });
Advanced Usage
License Management
use GetKeyManager\CodeIgniter\Libraries\GetKeyManagerLibrary; $license = new GetKeyManagerLibrary(); // Get license details $details = $license->getLicenseDetails('XXXXX-XXXXX-XXXXX-XXXXX'); // Get activations $activations = $license->getLicenseActivations('XXXXX-XXXXX-XXXXX-XXXXX'); // Suspend license $license->suspendLicense('XXXXX-XXXXX-XXXXX-XXXXX'); // Resume license $license->resumeLicense('XXXXX-XXXXX-XXXXX-XXXXX'); // Revoke license (permanent) $license->revokeLicense('XXXXX-XXXXX-XXXXX-XXXXX');
Metadata Operations
// Update metadata $license->updateLicenseMetadata('XXXXX-XXXXX-XXXXX-XXXXX', [ 'server_name' => 'prod-01', 'deployed_at' => date('Y-m-d H:i:s') ]); // Get metadata $metadata = $license->getLicenseMetadata('XXXXX-XXXXX-XXXXX-XXXXX'); // Delete metadata key $license->deleteLicenseMetadata('XXXXX-XXXXX-XXXXX-XXXXX', 'server_name');
Telemetry
$license->sendTelemetry('XXXXX-XXXXX-XXXXX-XXXXX', [ 'event' => 'export_completed', 'format' => 'pdf', 'records' => 1500, 'timestamp' => date('c') ]);
Downloadables
// Get product downloadables $downloads = $license->getDownloadables('product-uuid'); // Get download URL $result = $license->getDownloadUrl('downloadable-uuid', 'XXXXX-XXXXX-XXXXX-XXXXX'); // Redirect to download return redirect()->to($result['data']['download_url']);
Error Handling
use GetKeyManager\CodeIgniter\Libraries\GetKeyManagerLibrary; $license = new GetKeyManagerLibrary(); try { $result = $license->validateLicense($licenseKey); if (!$result['success']) { // Handle validation failure $errorCode = $result['code'] ?? 0; $message = $result['message'] ?? 'Validation failed'; switch ($errorCode) { case 4001: return "License not found"; case 4003: return "License has expired"; case 4006: return "Activation limit reached"; default: return $message; } } } catch (\Exception $e) { log_message('error', 'License validation error: ' . $e->getMessage()); return "Unable to validate license"; }
Testing
<?php namespace GetKeyManager\CodeIgniter\Tests; use CodeIgniter\Test\CIUnitTestCase; use GetKeyManager\CodeIgniter\Libraries\GetKeyManagerLibrary; class LicenseTest extends CIUnitTestCase { public function testCanInstantiateLibrary() { $license = new GetKeyManagerLibrary(); $this->assertInstanceOf(GetKeyManagerLibrary::class, $license); } public function testCanGenerateHardwareId() { helper('getkeymanager'); $hwid = generate_hardware_id(); $this->assertIsString($hwid); $this->assertNotEmpty($hwid); } }
Configuration Reference
All configuration options in app/Config/GetKeyManager.php:
| Option | Type | Default | Description |
|---|---|---|---|
apiKey |
string | '' | Your API key |
baseUrl |
string | https://api.getkeymanager.com | API base URL |
environment |
string | 'production' | Environment (production/staging/development) |
verifySignatures |
bool | true | Enable signature verification |
publicKey |
string|null | null | RSA public key for verification |
timeout |
int | 30 | HTTP timeout in seconds |
cacheEnabled |
bool | true | Enable response caching |
cacheTtl |
int | 300 | Cache TTL in seconds |
retryAttempts |
int | 3 | Number of retry attempts |
retryDelay |
int | 1000 | Retry delay in milliseconds |
loggingEnabled |
bool | false | Enable logging |
logThreshold |
int | 1 | Log threshold level (1-4) |
Examples
See the examples directory for complete working examples.
API Reference
The CodeIgniter SDK proxies all methods from the base PHP SDK. See the full API reference.
Support
- 📧 Email: support@getkeymanager.com
- 📚 Documentation: https://docs.getkeymanager.com
- 🐛 Issues: https://github.com/getkeymanager/codeigniter-sdk/issues
License
This SDK is open-sourced software licensed under the MIT license.