1. Go to this page and download the library: Download allus/company-data 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/ */
allus / company-data example snippets
Allus\CompanyData\Client;
use Allus\CompanyData\Model\Change;
$client = Client::fromConfig('config.json');
$client->processChanges(function (Change $change): void {
// one update at a time: event, person, slug, value, live, at
printf("%s %s %s %s %s %s\n",
$change->event, $change->personId, $change->slug ?? '—',
is_scalar($change->value) ? (string) $change->value : '…',
$change->live ? 'live' : 'snapshot',
$change->at?->format('c') ?? '—',
);
}); // returns when the feed is empty
Allus\CompanyData\Client;
$client = Client::fromConfig('allus.json');
// Iterate every connected person (lazy, auto-paged Generator).
foreach ($client->connections() as $conn) {
echo $conn->displayName, ' ', $conn->personId, PHP_EOL;
foreach ($conn->values as $slug => $val) {
printf(" %s = %s (live=%s, updated=%s)\n",
$slug,
is_scalar($val->value) ? (string) $val->value : json_encode($val->value),
$val->live ? 'true' : 'false',
$val->updatedAt?->format('c') ?? '—',
);
}
break; // just the first one for the demo
}
// Initial full sync, streaming so a 100k-connection book never lands in memory.
foreach ($client->connections(limit: 200) as $conn) {
upsertLocalRecord($conn);
}
$handle = $conn->values['passport_scan']->value; // BinaryHandle (no network yet)
$data = $handle->bytes(); // GET the slot file → decrypt → file bytes (string)
$n = $handle->save('/tmp/passport.jpg'); // same, written to disk; returns bytes written
echo $handle->valueUrl(); // the opaque slot-keyed URL it fetches from
Allus\CompanyData\Client;
use Allus\CompanyData\Model\Change;
$client = Client::fromConfig('allus.json');
$handle = function (Change $change): void {
if (seen($change->id)) { // idempotent: skip anything already applied
return;
}
match ($change->event) {
'field_updated' => storeValue($change->personId, $change->slug, $change->value, $change->live),
'field_deleted' => clearValue($change->personId, $change->slug),
'connection_deleted' => dropPerson($change->personId),
'connection_created', 'consent_accepted', 'consent_declined'
=> noteEvent($change->personId, $change->event, $change->at),
default => null,
};
recordSeen($change->id);
};
// Schedule your own re-runs; processChanges itself returns when empty.
while (true) {
$client->processChanges($handle, batchSize: 200, maxRetries: 5);
sleep(5);
}
Allus\CompanyData\Client;
use Allus\CompanyData\Errors\WebhookError;
$client = Client::fromConfig('allus.json');
$rawBody = file_get_contents('php://input');
$headers = function_exists('getallheaders') ? getallheaders() : []; // ['X-Allus-Signature' => '…', …]
try {
$change = $client->handleWebhook($rawBody, $headers);
} catch (WebhookError) {
http_response_code(401); // bad / unknown signature, or unparseable envelope
exit;
}
// Same idempotency rule as the pump: dedup on $change->id.
if (!seen($change->id)) {
applyChange($change);
recordSeen($change->id);
}
http_response_code(204);
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Allus\CompanyData\Errors\WebhookError;
$app->post('/allus/webhook', function (Request $request, Response $response) use ($client) {
$rawBody = (string) $request->getBody();
// PSR-7 getHeaders() returns array<string, string[]>; the SDK looks up
// X-Allus-* case-insensitively and takes the first value of an array.
try {
$change = $client->handleWebhook($rawBody, $request->getHeaders());
} catch (WebhookError) {
return $response->withStatus(401);
}
if (!seen($change->id)) {
applyChange($change);
recordSeen($change->id);
}
return $response->withStatus(204);
});