diff --git a/Storage/MetaBucket.php b/Storage/MetaBucket.php index 97f0e82..fb79686 100644 --- a/Storage/MetaBucket.php +++ b/Storage/MetaBucket.php @@ -2,13 +2,19 @@ namespace TechDyn\GoogleStorageMetaBucket\Storage; +use Google\Cloud\Core\Upload\ResumableUploader; +use Google\Cloud\Core\Upload\StreamableUploader; use Google\Cloud\Storage\Bucket; use Google\Cloud\Storage\Connection\ConnectionInterface; use Google\Cloud\Storage\StorageObject; +use GuzzleHttp\Promise\PromiseInterface; use Psr\Http\Message\StreamInterface; class MetaBucket extends Bucket { + /** + * @var array + */ protected $metadata; /** @@ -20,7 +26,6 @@ class MetaBucket extends Bucket public function __construct(ConnectionInterface $connection, $name, array $info = []) { parent::__construct($connection, $name, $info); - $this->metadata = []; } @@ -31,9 +36,48 @@ public function __construct(ConnectionInterface $connection, $name, array $info */ public function upload($data, array $options = []) { - $metadata = $this->metadata ? [ 'metadata' => $this->metadata ] : []; + return parent::upload($data, $this->populateOptions($options)); + } - return parent::upload($data, array_replace_recursive($metadata, $options)); + /** + * @param StreamInterface|resource|string|null $data + * @param array $options + * @return PromiseInterface + */ + public function uploadAsync($data, array $options = []) + { + return parent::uploadAsync($data, $this->populateOptions($options)); + } + + /** + * @param array $sourceObjects + * @param string $name + * @param array $options + * @return StorageObject + */ + public function compose(array $sourceObjects, $name, array $options = []) + { + return parent::compose($sourceObjects, $name, $this->populateOptions($options)); + } + + /** + * @param StreamInterface|resource|string $data + * @param array $options + * @return StreamableUploader + */ + public function getStreamableUploader($data, array $options = []) + { + return parent::getStreamableUploader($data, $this->populateOptions($options)); + } + + /** + * @param StreamInterface|resource|string|null $data + * @param array $options + * @return ResumableUploader + */ + public function getResumableUploader($data, array $options = []) + { + return parent::getResumableUploader($data, $this->populateOptions($options)); } /** @@ -47,4 +91,16 @@ public function setOption(string $name, $value) return $this; } + + /** + * @param $options + * @return array + */ + private function populateOptions($options) + { + return array_replace_recursive( + $this->metadata ? + [ 'metadata' => $this->metadata ] : [] + , $options); + } }