Skip to content

Commit

Permalink
docs, tests, fixes, refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
zaxbux committed Jul 7, 2021
1 parent a355cfa commit 28cf527
Show file tree
Hide file tree
Showing 95 changed files with 1,343 additions and 746 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor
composer.lock
.phpunit*
/docs/build/
19 changes: 19 additions & 0 deletions phpdoc.dist.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<phpdocumentor
configVersion="3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://www.phpdoc.org"
xsi:noNamespaceSchemaLocation="https://docs.phpdoc.org/latest/phpdoc.xsd"
>
<paths>
<output>docs/build/api</output>
<cache>docs/build/cache</cache>
</paths>
<version number="2.0.0">
<api>
<source dsn=".">
<path>src</path>
</source>
</api>
</version>
</phpdocumentor>
8 changes: 1 addition & 7 deletions src/Classes/AbstractObjectInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,15 @@
use function sizeof;
use function rawurlencode;

//use ArrayAccess;
//use JsonSerializable;
use RuntimeException;

//use Zaxbux\BackblazeB2\Traits\ProxyArrayAccessToPropertiesTrait;

/**
* @link https://www.backblaze.com/b2/docs/files.html#fileInfo
*
* @package Zaxbux\BackblazeB2\Classes
*/
abstract class AbstractObjectInfo
{
//final class FileInfo implements ArrayAccess, JsonSerializable {
//use ProxyArrayAccessToPropertiesTrait;

public const HEADER_PREFIX = 'X-Bz-Info-';

Expand Down
1 change: 1 addition & 0 deletions src/Classes/FilePathInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use function pathinfo;


/** @package Zaxbux\BackblazeB2\Classes */
final class FilePathInfo
{

Expand Down
32 changes: 22 additions & 10 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,23 @@
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\ClientInterface;
use Zaxbux\BackblazeB2\Config;
use Zaxbux\BackblazeB2\Http\Middleware\ApplyAuthorizationMiddleware;
use Zaxbux\BackblazeB2\Http\Middleware\ExceptionMiddleware;
use Zaxbux\BackblazeB2\Http\Middleware\RetryMiddleware;
use Zaxbux\BackblazeB2\Http\Endpoint;
use Zaxbux\BackblazeB2\Http\Middleware\{
ApplyAuthorizationMiddleware,
ExceptionMiddleware,
RetryMiddleware,
};
use Zaxbux\BackblazeB2\Operations\{
ApplicationKeyOperationsTrait,
BucketOperationsTrait,
DownloadOperationsTrait,
FileOperationsTrait,
LargeFileOperationsTrait,
UploadOperationsTrait,
};
use Zaxbux\BackblazeB2\Interfaces\AuthorizationCacheInterface;
use Zaxbux\BackblazeB2\Object\AccountAuthorization;
use Zaxbux\BackblazeB2\Operations\ApplicationKeyOperationsTrait;
use Zaxbux\BackblazeB2\Operations\BucketOperationsTrait;
use Zaxbux\BackblazeB2\Operations\FileOperationsTrait;
use Zaxbux\BackblazeB2\Traits\ApplyToAllFileVersionsTrait;

/**
* API Client for Backblaze B2.
Expand All @@ -30,8 +39,12 @@ class Client
public const B2_API_VERSION = 'b2api/v2/';

use FileOperationsTrait;
use LargeFileOperationsTrait;
use BucketOperationsTrait;
use ApplicationKeyOperationsTrait;
use UploadOperationsTrait;
use DownloadOperationsTrait;
use ApplyToAllFileVersionsTrait;

/** @var \Zaxbux\BackblazeB2\Config */
protected $config;
Expand Down Expand Up @@ -92,7 +105,7 @@ public function __construct($config)
* @param ClientInterface $client
*/
public function authorizeAccount(): AccountAuthorization {
$response = $this->http->request('GET', Client::BASE_URI . Client::B2_API_VERSION . 'b2_authorize_account', [
$response = $this->http->request('GET', Client::BASE_URI . Client::B2_API_VERSION . Endpoint::AUTHORIZE_ACCOUNT, [
'headers' => [
'Authorization' => Utils::basicAuthorization($this->config->applicationKeyId(), $this->config->applicationKey()),
],
Expand Down Expand Up @@ -134,7 +147,7 @@ protected function createDefaultHttpClient(): ClientInterface {
}*/

$stack->push(new ExceptionMiddleware(), 'exception_handler');
$stack->push(new ApplyAuthorizationMiddleware($this), 'b2_auth');
$stack->push(new ApplyAuthorizationMiddleware($this), 'b2_authorization');
$stack->push(new RetryMiddleware($this->config), 'retry');

$client = new GuzzleClient([
Expand All @@ -143,7 +156,6 @@ protected function createDefaultHttpClient(): ClientInterface {
'allow_redirects' => false,
'handler' => $stack,
'headers' => [
//'Accept' => 'application/json, */*;q=0.8',
'User-Agent' => Utils::getUserAgent($this->config->applicationName()),
],
]);
Expand All @@ -164,7 +176,7 @@ public function getAllowedBucketName(): ?string
/**
* @see __construct()
*/
public static function instance($config): Client
public static function create($config): Client
{
return new static($config);
}
Expand Down
36 changes: 25 additions & 11 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
*/
class Config
{
public const DEFAULTS = [
'applicationName' => '',
'handler' => null,
'middleware' => [],
'useHttpErrors' => null,
'maxRetries' => 4,
'maxRetryDelay' => 64,
'maxFileCount' => 1000,
'maxKeyCount' => 1000,
'useSSEHeaders' => false,
];

/**
* The identifier for the key. The account ID can also be used.
Expand All @@ -30,7 +41,7 @@ class Config
* Application name, included in the User-Agent HTTP header.
* @var string
*/
private $applicationName = '';
private $applicationName;

/**
* Custom Guzzle handler or handler stack.
Expand All @@ -48,16 +59,16 @@ class Config
* Optional middleware to add to the GuzzleHttp handler stack.
* @var array
*/
public $middleware = [];
public $middleware;

/** @var bool */
public $useHttpErrors = false;
public $useHttpErrors;

/**
* Number of times to retry an API call before throwing an exception.
* @var int
*/
public $maxRetries = 4;
public $maxRetries;

/**
* Maximum amount of time, in seconds, to wait before retrying a failed request.
Expand All @@ -66,31 +77,31 @@ class Config
*
* @var int
*/
public $maxRetryDelay = 64;
public $maxRetryDelay;

/**
* Download files with Server-Side Encryption headers instead of using query parameters.
* @var false
*/
public $useSSEHeaders = false;
public $useSSEHeaders;

/**
* Maximum number of application keys to return per call.
* @var int
*/
public $maxKeyCount = 1000;
public $maxKeyCount;

/**
* Maximum number of files to return per call.
* @var int
*/
public $maxFileCount = 1000;
public $maxFileCount;

/**
* Size limit to determine if the upload will use the large-file process.
* @var int
*/
public $largeFileUploadCustomMinimum = null; //200 * 1024 * 1024;
public $largeFileUploadCustomMinimum; //200 * 1024 * 1024;

/**
* An object that implements `AuthorizationCacheInterface` for caching
Expand Down Expand Up @@ -179,8 +190,11 @@ public static function fromArray($data): Config
}

private function setOptions(array $options) {
$this->handler = $options['handler'] ?? null;
$this->maxRetries = $options['maxRetries'] ?? 4;
$options = array_merge(static::DEFAULTS, $options);

$this->handler = $options['handler'];
$this->maxRetries = $options['maxRetries'];
$this->applicationName = $options['applicationName'];
$this->authorizationCache = $options['authorizationCache'] ?? new BuiltinAuthorizationCache();
}
}
1 change: 1 addition & 0 deletions src/Exceptions/NotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Zaxbux\BackblazeB2\Exceptions;

/** @package Zaxbux\BackblazeB2\Exceptions */
class NotFoundException extends \Exception {

}
1 change: 1 addition & 0 deletions src/Exceptions/Request/AccessDeniedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

namespace Zaxbux\BackblazeB2\Exceptions\Request;

/** @package Zaxbux\BackblazeB2\Exceptions\Request */
class AccessDeniedException extends B2APIException {}
1 change: 1 addition & 0 deletions src/Exceptions/Request/B2APIException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Psr\Http\Message\ResponseInterface;
use Throwable;

/** @package Zaxbux\BackblazeB2\Exceptions\Request */
class B2APIException extends RequestException {

private $statusCode;
Expand Down
1 change: 1 addition & 0 deletions src/Exceptions/Request/BadAuthTokenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

namespace Zaxbux\BackblazeB2\Exceptions\Request;

/** @package Zaxbux\BackblazeB2\Exceptions\Request */
class BadAuthTokenException extends B2APIException {}
1 change: 1 addition & 0 deletions src/Exceptions/Request/BadRequestException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

namespace Zaxbux\BackblazeB2\Exceptions\Request;

/** @package Zaxbux\BackblazeB2\Exceptions\Request */
class BadRequestException extends B2APIException {}
1 change: 1 addition & 0 deletions src/Exceptions/Request/CapExceededException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

namespace Zaxbux\BackblazeB2\Exceptions\Request;

/** @package Zaxbux\BackblazeB2\Exceptions\Request */
class CapExceededException extends B2APIException {}
1 change: 1 addition & 0 deletions src/Exceptions/Request/ConflictException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

namespace Zaxbux\BackblazeB2\Exceptions\Request;

/** @package Zaxbux\BackblazeB2\Exceptions\Request */
class ConflictException extends B2APIException {}
1 change: 1 addition & 0 deletions src/Exceptions/Request/DownloadCapExceededException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

namespace Zaxbux\BackblazeB2\Exceptions\Request;

/** @package Zaxbux\BackblazeB2\Exceptions\Request */
class DownloadCapExceededException extends CapExceededException {}
1 change: 1 addition & 0 deletions src/Exceptions/Request/DuplicateBucketNameException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

namespace Zaxbux\BackblazeB2\Exceptions\Request;

/** @package Zaxbux\BackblazeB2\Exceptions\Request */
class DuplicateBucketNameException extends B2APIException {}
1 change: 1 addition & 0 deletions src/Exceptions/Request/ExpiredAuthTokenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

namespace Zaxbux\BackblazeB2\Exceptions\Request;

/** @package Zaxbux\BackblazeB2\Exceptions\Request */
class ExpiredAuthTokenException extends B2APIException {}
1 change: 1 addition & 0 deletions src/Exceptions/Request/FileNotPresentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

namespace Zaxbux\BackblazeB2\Exceptions\Request;

/** @package Zaxbux\BackblazeB2\Exceptions\Request */
class FileNotPresentException extends B2APIException {}
1 change: 1 addition & 0 deletions src/Exceptions/Request/InvalidBucketIdException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

namespace Zaxbux\BackblazeB2\Exceptions\Request;

/** @package Zaxbux\BackblazeB2\Exceptions\Request */
class InvalidBucketIdException extends B2APIException {}
1 change: 1 addition & 0 deletions src/Exceptions/Request/InvalidFileIdException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

namespace Zaxbux\BackblazeB2\Exceptions\Request;

/** @package Zaxbux\BackblazeB2\Exceptions\Request */
class InvalidFileIdException extends B2APIException {}
1 change: 1 addition & 0 deletions src/Exceptions/Request/MethodNotAllowedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

namespace Zaxbux\BackblazeB2\Exceptions\Request;

/** @package Zaxbux\BackblazeB2\Exceptions\Request */
class MethodNotAllowedException extends B2APIException {}
1 change: 1 addition & 0 deletions src/Exceptions/Request/NotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

namespace Zaxbux\BackblazeB2\Exceptions\Request;

/** @package Zaxbux\BackblazeB2\Exceptions\Request */
class NotFoundException extends B2APIException {}
1 change: 1 addition & 0 deletions src/Exceptions/Request/OutOfRangeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

namespace Zaxbux\BackblazeB2\Exceptions\Request;

/** @package Zaxbux\BackblazeB2\Exceptions\Request */
class OutOfRangeException extends B2APIException {}
1 change: 1 addition & 0 deletions src/Exceptions/Request/RangeNotSatisfiableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

namespace Zaxbux\BackblazeB2\Exceptions\Request;

/** @package Zaxbux\BackblazeB2\Exceptions\Request */
class RangeNotSatisfiableException extends B2APIException {}
1 change: 1 addition & 0 deletions src/Exceptions/Request/RequestTimeoutException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

namespace Zaxbux\BackblazeB2\Exceptions\Request;

/** @package Zaxbux\BackblazeB2\Exceptions\Request */
class RequestTimeoutException extends B2APIException {}
1 change: 1 addition & 0 deletions src/Exceptions/Request/ServiceUnavailableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

namespace Zaxbux\BackblazeB2\Exceptions\Request;

/** @package Zaxbux\BackblazeB2\Exceptions\Request */
class ServiceUnavailableException extends B2APIException {}
1 change: 1 addition & 0 deletions src/Exceptions/Request/StorageCapExceededException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

namespace Zaxbux\BackblazeB2\Exceptions\Request;

/** @package Zaxbux\BackblazeB2\Exceptions\Request */
class StorageCapExceededException extends CapExceededException {}
1 change: 1 addition & 0 deletions src/Exceptions/Request/TooManyBucketsException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

namespace Zaxbux\BackblazeB2\Exceptions\Request;

/** @package Zaxbux\BackblazeB2\Exceptions\Request */
class TooManyBucketsException extends B2APIException {}
1 change: 1 addition & 0 deletions src/Exceptions/Request/TransactionCapExceededException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

namespace Zaxbux\BackblazeB2\Exceptions\Request;

/** @package Zaxbux\BackblazeB2\Exceptions\Request */
class TransactionCapExceededException extends CapExceededException {}
1 change: 1 addition & 0 deletions src/Exceptions/Request/UnauthorizedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

namespace Zaxbux\BackblazeB2\Exceptions\Request;

/** @package Zaxbux\BackblazeB2\Exceptions\Request */
class UnauthorizedException extends B2APIException {}
1 change: 1 addition & 0 deletions src/Exceptions/Request/UnsupportedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

namespace Zaxbux\BackblazeB2\Exceptions\Request;

/** @package Zaxbux\BackblazeB2\Exceptions\Request */
class UnsupportedException extends B2APIException {}
1 change: 1 addition & 0 deletions src/Helpers/AbstractHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Zaxbux\BackblazeB2\Client;
use Zaxbux\BackblazeB2\Interfaces\HelperInterface;

/** @package Zaxbux\BackblazeB2\Helpers */
abstract class AbstractHelper implements HelperInterface
{
/** @var \Zaxbux\BackblazeB2\Client */
Expand Down
Loading

0 comments on commit 28cf527

Please sign in to comment.