Framework-agnostic, modular server-side SDK for CodeLockPro. Module one: Knowledge base. Pure library — no framework binding, no routing.

Maintainers

Package info

github.com/mbos01/codelockpro-sdk-php

Homepage

Issues

pkg:composer/codelockpro/sdk

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.4 2026-05-10 08:51 UTC

This package is auto-updated.

Last update: 2026-05-10 12:36:04 UTC


README

Pure server-side, modular PHP SDK — the CodeLockPro client framework on the server. Ships with the knowledge base as a built-in module; additional modules plug into the same CodeLockPro instance through the same registration surface.

Install

composer require codelockpro/sdk

Source repository. This package is published to Packagist from a read-only subtree mirror at mbos01/codelockpro-sdk-php. The canonical source lives in mbos01/codelockpro under sdk/php/ — open issues and PRs there.

License. The SDK is proprietary and may only be used in combination with an active CodeLockPro account. See LICENSE.

Architecture invariants

  1. Modular foundation. The core has no per-module coupling.
  2. Pure library. No framework binding (Laravel, Symfony, vanilla PHP — the developer wires the routes).
  3. Zero web-framework dependencies. Only ext-curl and ext-json.

Usage

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']}");
});

$client->kb() is a convenience accessor for $client->module('kb'). The core has no KB-specific code path.

Registering more modules

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');

Module author contract

A module factory is any callable(ModuleContext): object. The context exposes:

  • $ctx->name — the registered name ("kb", "checkout", …)
  • $ctx->client — back-reference to CodeLockPro (use request() for HTTP)
  • $ctx->bus — shared event bus (on / off / emit)

Modules namespace their events as <ctx->name>.<event> so listeners stay unambiguous when many modules are registered.

Knowledge base — module one

Mapped to the unified, secured KB REST surface (every call requires an OAuth bearer carrying kb:read for reads and kb:write for writes; view tracking is kb:read):

GET  /v1/kb/{application_id}/articles
GET  /v1/kb/{application_id}/articles/{id_or_slug}
GET  /v1/kb/{application_id}/categories
GET  /v1/kb/{application_id}/search?q=…
POST /v1/kb/{application_id}/articles/{id}/track-view

Each call returns the raw decoded JSON body as an associative array. On a non-2xx response the client throws CodeLockPro\CodeLockProApiException carrying the HTTP status and response body.