PHP code example of jamescarr / ankusa

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

    

jamescarr / ankusa example snippets


use Ankusa\ClaimCheck\ClaimCheckClient;
use Ankusa\ClaimCheck\ClaimCheckError;

$claimCheck = new ClaimCheckClient(getenv('CLAIM_CHECK_URL') ?: 'http://localhost:4001');

// A queue message that carries a claim also carries its sha256:
//   "claim":  "urn:ankusa:claim:v1:<tenant>:<claim_id>"  (claim_id: uppercase ULID)
//   "sha256": 64-char lowercase hex of the claim's bytes
function resolveBody(ClaimCheckClient $claimCheck, array $message): string
{
    try {
        return $claimCheck->redeem($message['claim'], $message['sha256']);
    } catch (ClaimCheckError $err) {
        if (! $err->isRetryable()) {
            // bad ref/sha256, 404, or an integrity mismatch: dead-letter, don't requeue
            throw $err;
        }
        // gateway unreachable or 5xx: safe to retry
        throw $err;
    }
}

use Ankusa\Webhook\HookHeaders;
use Ankusa\Webhook\MissingHookIdError;

try {
    $hook = HookHeaders::fromHeaders(getallheaders());
} catch (MissingHookIdError) {
    http_response_code(400);

    return;
}

$body = file_get_contents('php://input');
// $hook->id, $hook->source, $hook->tenant, $hook->contentType

use Ankusa\Routes\RoutesClient;

$routes = new RoutesClient(getenv('ROUTES_URL') ?: 'http://localhost:4003');

$routes->createRoute(['id' => 'stripe', 'path' => '/webhooks/stripe']);
$routes->getIpRules();   // ['default' => 'allow', 'rules' => []]
$routes->testRoute(['method' => 'POST', 'path' => '/webhooks/stripe', 'ip' => '203.0.113.7']);

use Ankusa\Admin\AdminClient;

$admin = new AdminClient(getenv('ADMIN_URL') ?: 'http://localhost:4002');

$admin->health();                          // ['status' => 'ok', 'instance' => ..., 'roles' => [...]]
$admin->listDeadLetters(['limit' => 10]);  // ['total' => ..., 'entries' => [...]]
$admin->replayDeadLetters(['source_id' => 'demo']);
$admin->listQuarantined();

use Ankusa\Sources\SourcesClient;
use Ankusa\Sources\SourceSpec;

$sources = new SourcesClient(getenv('ADMIN_URL') ?: 'http://localhost:4002');

$sources->listSources('acme');                                   // Source[]
$sources->getSource('acme', 'billing');                          // Source
$sources->createSource('acme', 'billing', new SourceSpec(sinks: [['type' => 'log']]));
$sources->updateSource(
    'acme',
    'billing',
    new SourceSpec(sinks: [['type' => 'log']], onVerifyFailure: 'reject'),
);
$sources->deleteSource('acme', 'billing');
sh
composer install
composer test          # PHPUnit: unit + conformance
composer conformance   # PHPUnit: only the conformance vectors in ../conformance
composer analyse       # PHPStan, level 10
composer lint          # php-cs-fixer check --diff
composer fix           # php-cs-fixer fix