PHP code example of raise-studio / license-client

1. Go to this page and download the library: Download raise-studio/license-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

raise-studio / license-client example snippets


use RaiseStudio\License\LicenseClient;
use RaiseStudio\License\FeatureGate;
use RaiseStudio\License\Adapters\Laravel\LaravelCache;
use RaiseStudio\License\Adapters\Laravel\LaravelHttp;

// Laravel ServiceProvider 中注册
$this->app->singleton(LicenseClient::class, function () {
    $config = 
if ($gate->canUse('pipeline')) { /* Pro 功能 */ }

use RaiseStudio\License\LicenseClient;
use RaiseStudio\License\FeatureGate;
use RaiseStudio\License\Adapters\WordPress\WordPressCache;
use RaiseStudio\License\Adapters\WordPress\WordPressHttp;

$client = new LicenseClient(
    productCode: 'raise-import',
    publicKeyBase64: 'YOUR_PUBLIC_KEY_BASE64',
    cache: new WordPressCache(),
    http: new WordPressHttp(),
);

$gate = new FeatureGate($client);
$gate->setFreeFeatures(['basic_import', 'csv_support']);
$gate->setAllProFeatures(['pipeline', 'advanced_mapping', 'queue']);

if ($gate->canUse('pipeline')) {
    // Pro 功能
}

use RaiseStudio\License\LicenseClient;
use RaiseStudio\License\Adapters\Native\FileCache;
use RaiseStudio\License\Adapters\Native\CurlHttp;

$client = new LicenseClient(
    productCode: 'raise-import',
    publicKeyBase64: 'YOUR_PUBLIC_KEY_BASE64',
    cache: new FileCache(),
    http: new CurlHttp(),
    siteUrl: 'https://example.com',  // 显式指定站点 URL
);

use RaiseStudio\License\Contracts\CacheInterface;
use RaiseStudio\License\Contracts\HttpClientInterface;
use RaiseStudio\License\Contracts\HttpClientResponse;

// 自定义 Redis 缓存
class RedisCache implements CacheInterface { /* ... */ }

// 自定义 Guzzle HTTP
class GuzzleHttp implements HttpClientInterface { /* ... */ }

$client = new LicenseClient(
    productCode: 'my-product',
    publicKeyBase64: '...',
    cache: new RedisCache(),
    http: new GuzzleHttp(),
);

return [
    'product_code'      => 'raise-import',
    'public_key_base64' => 'YOUR_PUBLIC_KEY_BASE64',
    'api_base_url'      => 'https://admin.raisestudio.dev/api/v1',
    'free_features'     => ['basic_import', 'csv_support'],
    'all_pro_features'  => ['pipeline', 'advanced_mapping', 'queue'],
];

use RaiseStudio\License\Messages;

// 切换到中文
Messages::setLocale('zh');

// 或注入自定义翻译
Messages::add('fr', [
    'activation.invalid_format' => 'Format de clé de licence invalide.',
    // ...
]);

use RaiseStudio\License\FileLogger;

$logger = new FileLogger(__DIR__ . '/raise-license.log', 'debug', 'raise-license');
$client->setLogger($logger);   // 同步透传给 JwtVerifier
$gate->setLogger($logger);     // 同步透传给 IntegrityCheck