1. Go to this page and download the library: Download bella-baxter/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/ */
bella-baxter / sdk example snippets
use BellaBaxter\BaxterClient;
use BellaBaxter\BaxterClientOptions;
$client = new BaxterClient(new BaxterClientOptions(
baxterUrl: 'https://baxter.example.com',
apiKey: getenv('BELLA_BAXTER_API_KEY'), // bax-<keyId>-<secret>, from: bella apikeys create
));
// Project and environment come from the API key itself (GET /api/v1/keys/me).
$secrets = $client->getAllSecrets();
echo $secrets['DATABASE_URL'];
use BellaBaxter\BaxterClient;
use BellaBaxter\BaxterClientOptions;
use BellaBaxter\E2EEResponseException;
// Present a registered device key instead of an ephemeral one.
$client = new BaxterClient(new BaxterClientOptions(
apiKey: getenv('BELLA_BAXTER_API_KEY'),
privateKey: getenv('BELLA_BAXTER_PRIVATE_KEY') ?: null, // PKCS#8 PEM; this env var is also read automatically
onWrappedDekReceived: function (string $wrappedDek, ?string $leaseExpires): void {
// Device key wrapping: persist the wrapped DEK for offline use
},
));
try {
$secrets = $client->getAllSecrets();
} catch (E2EEResponseException $e) {
error_log('refused: ' . $e->getErrorCode()); // never the body or any key
throw $e;
}
// AppServiceProvider::register()
$this->app->singleton(BaxterClient::class, function () {
return new BaxterClient(new BaxterClientOptions(
baxterUrl: config('services.bella.url'),
apiKey: config('services.bella.api_key'),
));
});
// Auto-generated by bella secrets generate php — do not edit manually.
class AppSecrets
{
public function getDatabaseUrl(): string
{
$v = getenv('DATABASE_URL');
if ($v === false) throw new \RuntimeException("Secret 'DATABASE_URL' is not set.");
return $v;
}
public function getPort(): int
{
$v = getenv('PORT');
if ($v === false) throw new \RuntimeException("Secret 'PORT' is not set.");
return (int) $v;
}
public function isEnableFeatureX(): bool
{
$v = getenv('ENABLE_FEATURE_X');
if ($v === false) throw new \RuntimeException("Secret 'ENABLE_FEATURE_X' is not set.");
return filter_var($v, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ?? false;
}
}
// Secrets must be in the environment before accessing.
// Use bella run, the SDK (BaxterClient), or a .env file loaded at bootstrap.
$secrets = new AppSecrets();
$dbUrl = $secrets->getDatabaseUrl(); // string — throws if missing
$port = $secrets->getPort(); // int — parsed automatically