PHP code example of calvery / sdk

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

    

calvery / sdk example snippets



ent = new \Calvery\Client(getenv('CVSM_TOKEN'), 'acme-corp');

// Single secret
$dbUrl = $client->get('DATABASE_URL');

// All secrets as array
$all = $client->getAll();

// Inject into $_ENV + putenv()
$injected = $client->inject(overwrite: false);
echo "Injected " . count($injected) . " vars\n";

$client = new \Calvery\Client(
    getenv('CVSM_TOKEN'),
    'acme-corp',
    [
        'base_url'    => 'https://vault.your-company.internal',
        'environment' => 'staging',
        'cache_ttl'   => 60,   // seconds, 0 to disable
        'max_retries' => 5,
        'timeout'     => 30,   // seconds
    ]
);

use Calvery\Exception;

try {
    $val = $client->get('DATABASE_URL');
} catch (Exception\NotFound $e) {
    error_log("secret missing: " . $e->getMessage());
} catch (Exception\AuthError $e) {
    error_log("token invalid: " . $e->getMessage());
} catch (Exception\NetworkError $e) {
    error_log("network: " . $e->getMessage());
} catch (Exception\ServerError $e) {
    error_log("HTTP {$e->statusCode}: " . $e->getMessage());
}

$this->app->singleton(\Calvery\Client::class, fn() =>
    new \Calvery\Client(config('services.calvery.token'), config('services.calvery.team'))
);