PHP code example of customy / access
1. Go to this page and download the library: Download customy/access 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/ */
customy / access example snippets
use Customy\Access\CustomyAccessClient;
$access = new CustomyAccessClient([
'base_url' => 'https://access.customy.ai',
'api_key' => getenv('CUSTOMY_ACCESS_API_KEY'),
'environment_id' => getenv('CUSTOMY_ACCESS_ENVIRONMENT_ID'),
]);
$users = $access->users()->list([
'limit' => 50,
]);
use Customy\Access\Flags\FlagsClient;
use Customy\Access\MachineTokenProvider;
$flags = new FlagsClient([
'base_url' => 'https://access-api.customy.ai',
'token_provider' => new MachineTokenProvider('https://access-api.customy.ai', getenv('CUSTOMY_CLIENT_ID'), getenv('CUSTOMY_CLIENT_SECRET'), scopes: ['flags:read']),
'verify_signature' => true, // snapshot signed by the Access issuer (JWKS), content checked
'snapshot' => apcu_fetch('customy.flags') ?: null, // PHP keeps nothing between requests
]);
$flags->refresh(); // 304 when unchanged
apcu_store('customy.flags', $flags->snapshot());
if ($flags->getBooleanValue('checkout.new_flow', false, ['key' => $userId])) {
// …
}
$flags->trackConversion('checkout.new_flow', ['key' => $userId], value: 49.9, metric: 'purchase');
$flags->flush(); // impressions (one per flag/key/treatment/hour) and conversions