PHP code example of codelockpro / sdk

1. Go to this page and download the library: Download codelockpro/sdk 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/ */

    

codelockpro / sdk example snippets


use CodeLockPro\CodeLockPro;

$client = new CodeLockPro(
    baseUrl: 'https://api.codelock.pro',
    applicationId: '01H…',
);

// Data
$articles = $client->kb()->getArticles();
$article  = $client->kb()->getArticle('how-to-reset-password');

// Actions (server-side: emits the bus event)
$client->kb()->trackView($article['id'], $article['slug']);

// Events
$client->on('kb.article.viewed', function (array $payload): void {
    error_log("viewed {$payload['article_id']}");
});
$client->on('kb.search.performed', function (array $payload): void {
    error_log("{$payload['count']} results for {$payload['query']}");
});

use CodeLockPro\CodeLockPro;
use CodeLockPro\Core\ModuleContext;

$client = new CodeLockPro(
    baseUrl: 'https://api.codelock.pro',
    applicationId: '01H…',
    modules: false,  // opt out of the default KB registration
);

$client->register('kb',       [\CodeLockPro\Modules\KnowledgeBase::class, 'create']);
$client->register('checkout', function (ModuleContext $ctx) {
    return new class($ctx) {
        public function __construct(public ModuleContext $ctx) {}
        public function start(string $productId): array {
            $session = $this->ctx->client->request(
                'POST', "/v1/checkout/sessions", ['product_id' => $productId],
            );
            $this->ctx->bus->emit("{$this->ctx->name}.session.created", [
                'product_id' => $productId,
            ]);
            return $session;
        }
    };
});

$checkout = $client->module('checkout');
$session  = $checkout->start('pro-monthly');

$client->register('portal', [\CodeLockPro\Modules\Portal::class, 'create']);

$threads = $client->portal()->getThreads(['limit' => 20]);
$post    = $client->portal()->createPost('thread_123', ['body' => 'I hit this too']);

$client->register('community', [\CodeLockPro\Modules\Community::class, 'create']);

$threads = $client->community()->getThreads(['limit' => 20]);
$post    = $client->community()->createPost('thread_123', ['body' => 'I hit this too']);