b2-sdk-php
is a client library for working with Backblaze's B2 storage service.
Full documentation of the Backblaze B2 API can be found here.
Each method is well documented in src/client.php
.
For examples and options that are specific to this library, please see docs/
:
Installation is via Composer:
$ composer require zaxbux/b2-sdk-php
<?php
use Zaxbux\BackblazeB2\Client;
$accountId = '...';
$applicationKey = '...';
$client = new Client($accountId, $applicationKey);
// Retrieve an array of Bucket objects on your account.
$buckets = $client->listBuckets();
If you want to cache the authorization token to reduce the number of API calls, create a class that implements Zaxbux\BackblazeB2\AuthorizationCacheInterface
.
<?php
use Zaxbux\BackblazeB2\Client;
$authCache = new AuthorizationCacheExample;
$client = new Client($accountId, $applicationKey, $authCache);
<?php
use Zaxbux\BackblazeB2\AuthorizationCacheInterface;
class AuthorizationCacheExample implements AuthorizationCacheInterface {
public function cache($key, $value) {
$myCache->remember($key, $value, AuthorizationCacheInterface::EXPIRES)
}
public function get($key) {
$myCache->get($key);
}
}
The AuthorizationCacheInterface::EXPIRES
constant is how long the authorization token is valid for, in seconds. Currently, this is equivalent to 24 hours. Requests made after the token expires will result in an ExpiredAuthTokenException
exception being thrown. You will need to get a new authorization token with authorizeAccount()
.
Tests are run with PHPUnit. After installing PHPUnit via Composer:
$ vendor/bin/phpunit
Feel free to contribute in any way by reporting an issue, making a suggestion, or submitting a pull request.
MIT