From 74d64157ab48767e80391e8c11228afba9ac7e24 Mon Sep 17 00:00:00 2001 From: "Vincent Jiang (LEI)" Date: Thu, 11 Jan 2018 09:54:52 +0800 Subject: [PATCH] source code copied from azure-storage-php for v1.0.0-blob release. --- BreakingChanges.md | 5 + CONTRIBUTING.md | 1 + ChangeLog.md | 8 + LICENSE | 34 +- README.md | 157 +- composer.json | 22 + src/Blob/BlobRestProxy.php | 4562 +++++++++++++++++ src/Blob/BlobSharedAccessSignatureHelper.php | 213 + src/Blob/Internal/BlobResources.php | 106 + src/Blob/Internal/IBlob.php | 1555 ++++++ src/Blob/Models/AccessCondition.php | 355 ++ src/Blob/Models/AppendBlockOptions.php | 108 + src/Blob/Models/AppendBlockResult.php | 244 + src/Blob/Models/Blob.php | 153 + src/Blob/Models/BlobAccessPolicy.php | 61 + src/Blob/Models/BlobBlockType.php | 64 + src/Blob/Models/BlobPrefix.php | 62 + src/Blob/Models/BlobProperties.php | 663 +++ src/Blob/Models/BlobServiceOptions.php | 92 + src/Blob/Models/BlobType.php | 42 + src/Blob/Models/Block.php | 97 + src/Blob/Models/BlockList.php | 172 + src/Blob/Models/BreakLeaseResult.php | 83 + src/Blob/Models/CommitBlobBlocksOptions.php | 223 + src/Blob/Models/Container.php | 131 + src/Blob/Models/ContainerACL.php | 164 + src/Blob/Models/ContainerAccessPolicy.php | 61 + src/Blob/Models/ContainerProperties.php | 184 + src/Blob/Models/CopyBlobFromURLOptions.php | 136 + src/Blob/Models/CopyBlobOptions.php | 62 + src/Blob/Models/CopyBlobResult.php | 179 + src/Blob/Models/CopyState.php | 294 ++ src/Blob/Models/CreateBlobBlockOptions.php | 101 + src/Blob/Models/CreateBlobOptions.php | 247 + src/Blob/Models/CreateBlobPagesOptions.php | 62 + src/Blob/Models/CreateBlobPagesResult.php | 207 + src/Blob/Models/CreateBlobSnapshotOptions.php | 62 + src/Blob/Models/CreateBlobSnapshotResult.php | 139 + src/Blob/Models/CreateBlockBlobOptions.php | 42 + src/Blob/Models/CreateContainerOptions.php | 113 + .../CreatePageBlobFromContentOptions.php | 42 + src/Blob/Models/DeleteBlobOptions.php | 88 + src/Blob/Models/GetBlobMetadataOptions.php | 62 + src/Blob/Models/GetBlobMetadataResult.php | 54 + src/Blob/Models/GetBlobOptions.php | 112 + src/Blob/Models/GetBlobPropertiesOptions.php | 62 + src/Blob/Models/GetBlobPropertiesResult.php | 84 + src/Blob/Models/GetBlobResult.php | 134 + src/Blob/Models/GetContainerACLResult.php | 137 + .../Models/GetContainerPropertiesResult.php | 175 + src/Blob/Models/LeaseMode.php | 44 + src/Blob/Models/LeaseResult.php | 85 + src/Blob/Models/ListBlobBlocksOptions.php | 141 + src/Blob/Models/ListBlobBlocksResult.php | 252 + src/Blob/Models/ListBlobsOptions.php | 212 + src/Blob/Models/ListBlobsResult.php | 313 ++ src/Blob/Models/ListContainersOptions.php | 126 + src/Blob/Models/ListContainersResult.php | 251 + .../Models/ListPageBlobRangesDiffResult.php | 101 + src/Blob/Models/ListPageBlobRangesOptions.php | 90 + src/Blob/Models/ListPageBlobRangesResult.php | 182 + src/Blob/Models/PageWriteOption.php | 41 + src/Blob/Models/PublicAccessType.php | 67 + src/Blob/Models/PutBlobResult.php | 182 + src/Blob/Models/PutBlockResult.php | 118 + src/Blob/Models/SetBlobMetadataResult.php | 151 + src/Blob/Models/SetBlobPropertiesOptions.php | 252 + src/Blob/Models/SetBlobPropertiesResult.php | 144 + 68 files changed, 14941 insertions(+), 27 deletions(-) create mode 100644 BreakingChanges.md create mode 100644 CONTRIBUTING.md create mode 100644 ChangeLog.md create mode 100644 composer.json create mode 100644 src/Blob/BlobRestProxy.php create mode 100644 src/Blob/BlobSharedAccessSignatureHelper.php create mode 100644 src/Blob/Internal/BlobResources.php create mode 100644 src/Blob/Internal/IBlob.php create mode 100644 src/Blob/Models/AccessCondition.php create mode 100644 src/Blob/Models/AppendBlockOptions.php create mode 100644 src/Blob/Models/AppendBlockResult.php create mode 100644 src/Blob/Models/Blob.php create mode 100644 src/Blob/Models/BlobAccessPolicy.php create mode 100644 src/Blob/Models/BlobBlockType.php create mode 100644 src/Blob/Models/BlobPrefix.php create mode 100644 src/Blob/Models/BlobProperties.php create mode 100644 src/Blob/Models/BlobServiceOptions.php create mode 100644 src/Blob/Models/BlobType.php create mode 100644 src/Blob/Models/Block.php create mode 100644 src/Blob/Models/BlockList.php create mode 100644 src/Blob/Models/BreakLeaseResult.php create mode 100644 src/Blob/Models/CommitBlobBlocksOptions.php create mode 100644 src/Blob/Models/Container.php create mode 100644 src/Blob/Models/ContainerACL.php create mode 100644 src/Blob/Models/ContainerAccessPolicy.php create mode 100644 src/Blob/Models/ContainerProperties.php create mode 100644 src/Blob/Models/CopyBlobFromURLOptions.php create mode 100644 src/Blob/Models/CopyBlobOptions.php create mode 100644 src/Blob/Models/CopyBlobResult.php create mode 100644 src/Blob/Models/CopyState.php create mode 100644 src/Blob/Models/CreateBlobBlockOptions.php create mode 100644 src/Blob/Models/CreateBlobOptions.php create mode 100644 src/Blob/Models/CreateBlobPagesOptions.php create mode 100644 src/Blob/Models/CreateBlobPagesResult.php create mode 100644 src/Blob/Models/CreateBlobSnapshotOptions.php create mode 100644 src/Blob/Models/CreateBlobSnapshotResult.php create mode 100644 src/Blob/Models/CreateBlockBlobOptions.php create mode 100644 src/Blob/Models/CreateContainerOptions.php create mode 100644 src/Blob/Models/CreatePageBlobFromContentOptions.php create mode 100644 src/Blob/Models/DeleteBlobOptions.php create mode 100644 src/Blob/Models/GetBlobMetadataOptions.php create mode 100644 src/Blob/Models/GetBlobMetadataResult.php create mode 100644 src/Blob/Models/GetBlobOptions.php create mode 100644 src/Blob/Models/GetBlobPropertiesOptions.php create mode 100644 src/Blob/Models/GetBlobPropertiesResult.php create mode 100644 src/Blob/Models/GetBlobResult.php create mode 100644 src/Blob/Models/GetContainerACLResult.php create mode 100644 src/Blob/Models/GetContainerPropertiesResult.php create mode 100644 src/Blob/Models/LeaseMode.php create mode 100644 src/Blob/Models/LeaseResult.php create mode 100644 src/Blob/Models/ListBlobBlocksOptions.php create mode 100644 src/Blob/Models/ListBlobBlocksResult.php create mode 100644 src/Blob/Models/ListBlobsOptions.php create mode 100644 src/Blob/Models/ListBlobsResult.php create mode 100644 src/Blob/Models/ListContainersOptions.php create mode 100644 src/Blob/Models/ListContainersResult.php create mode 100644 src/Blob/Models/ListPageBlobRangesDiffResult.php create mode 100644 src/Blob/Models/ListPageBlobRangesOptions.php create mode 100644 src/Blob/Models/ListPageBlobRangesResult.php create mode 100644 src/Blob/Models/PageWriteOption.php create mode 100644 src/Blob/Models/PublicAccessType.php create mode 100644 src/Blob/Models/PutBlobResult.php create mode 100644 src/Blob/Models/PutBlockResult.php create mode 100644 src/Blob/Models/SetBlobMetadataResult.php create mode 100644 src/Blob/Models/SetBlobPropertiesOptions.php create mode 100644 src/Blob/Models/SetBlobPropertiesResult.php diff --git a/BreakingChanges.md b/BreakingChanges.md new file mode 100644 index 0000000..0bb7f8c --- /dev/null +++ b/BreakingChanges.md @@ -0,0 +1,5 @@ +Tracking Breaking changes in 1.0.0 + +* Removed `dataSerializer` parameter from `BlobRextProxy` constructor. +* Option parameter type of `BlobRestProxy::CreateBlockBlob` and `BlobRestProxy::CreatePageBlobFromContent` changed and added `setUseTransactionalMD5` method. +* Deprecated PHP 5.5 support. \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..3dac3d6 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1 @@ +This [repository](https://github.com/azure/azure-storage-blob-php) is currently used for releasing only, please go to [azure-storage-php](https://github.com/azure/azure-storage-php) for submitting issues or contribution. \ No newline at end of file diff --git a/ChangeLog.md b/ChangeLog.md new file mode 100644 index 0000000..29ad42b --- /dev/null +++ b/ChangeLog.md @@ -0,0 +1,8 @@ +2018.01 - version 1.0.0 + +* Created `BlobSharedAccessSignatureHelper` and moved method `SharedAccessSignatureHelper::generateBlobServiceSharedAccessSignatureToken()` into `BlobSharedAccessSignatureHelper`. +* Added static builder methods `createBlobService` and `createContainerAnonymousAccess` into `BlobRestProxy`. +* Removed `dataSerializer` parameter from `BlobRextProxy` constructor. +* Added `setUseTransactionalMD5` method for options of `BlobRestProxy::CreateBlockBlob` and `BlobRestProxy::CreatePageBlobFromContent`. Default false, enabling transactional MD5 validation will take more cpu and memory resources. +* Fixed a bug that CopyBlobFromURLOptions not found. +* Deprecated PHP 5.5 support. \ No newline at end of file diff --git a/LICENSE b/LICENSE index 2107107..7928860 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,21 @@ - MIT License +The MIT License (MIT) - Copyright (c) Microsoft Corporation. All rights reserved. +Copyright (c) 2016 Microsoft Corporation - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 72f1506..fef071c 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,151 @@ +# Microsoft Azure Storage Blob PHP Client Library -# Contributing +This project provides a PHP client library that makes it easy to access Microsoft Azure Storage blob services. For documentation on how to host PHP applications on Microsoft Azure, please see the [Microsoft Azure PHP Developer Center](http://www.windowsazure.com/en-us/develop/php/). -This project welcomes contributions and suggestions. Most contributions require you to agree to a -Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us -the rights to use your contribution. For details, visit https://cla.microsoft.com. +[![Latest Stable Version](https://poser.pugx.org/microsoft/azure-storage-blob/v/stable)](https://packagist.org/packages/microsoft/azure-storage-blob) -When you submit a pull request, a CLA-bot will automatically determine whether you need to provide -a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions -provided by the bot. You will only need to do this once across all repos using our CLA. +> **Note** +> +> * This [repository](https://github.com/azure/azure-storage-blob-php) is currently used for releasing only, please go to [azure-storage-php](https://github.com/azure/azure-storage-php) for submitting issues or contribution. +> * If you are looking for the Service Bus, Service Runtime, Service Management or Media Services libraries, please visit https://github.com/Azure/azure-sdk-for-php. +> * If you need big file (larger than 2GB) or 64-bit integer support, please install PHP 7 64-bit version. -This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). -For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or -contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. +# Features + +* Blobs + * create, list, and delete containers, work with container metadata and permissions, list blobs in container + * create block and page blobs (from a stream or a string), work with blob blocks and pages, delete blobs + * work with blob properties, metadata, leases, snapshot a blob + +Please check details on [API reference documents](http://azure.github.io/azure-storage-php). + +# Getting Started +## Minimum Requirements + +* PHP 5.6 or above +* See [composer.json](composer.json) for dependencies +* Required extension for PHP: + php_fileinfo.dll + php_mbstring.dll + php_openssl.dll + php_xsl.dll + +* Recommended extension for PHP: + php_curl.dll + +## Download Source Code + +To get the source code from GitHub, type + + git clone https://github.com/Azure/azure-storage-php.git + cd ./azure-storage-php + + +## Install via Composer + +1. Create a file named **composer.json** in the root of your project and add the following code to it: +```json + { + "require": { + "microsoft/azure-storage-blob": "*" + } + } +``` +2. Download **[composer.phar](http://getcomposer.org/composer.phar)** in your project root. + +3. Open a command prompt and execute this in your project root + + php composer.phar install + +## Usage + +There are four basic steps that have to be performed before you can make a call to any Microsoft Azure Storage API when using the libraries. + +* First, include the autoloader script: + + require_once "vendor/autoload.php"; + +* Include the namespaces you are going to use. + + To create any Microsoft Azure service client you need to use the rest proxy classes, such as **BlobRestProxy** class: + + use MicrosoftAzure\Storage\Blob\BlobRestProxy; + + To process exceptions you need: + + use MicrosoftAzure\Storage\Common\ServiceException; + + +* To instantiate the service client you will also need a valid [connection string](https://azure.microsoft.com/en-us/documentation/articles/storage-configure-connection-string/). The format is: + + DefaultEndpointsProtocol=[http|https];AccountName=[yourAccount];AccountKey=[yourKey] + + or: + + BlobEndpoint=[myBlobEndpoint];SharedAccessSignature=[sasToken] + +* Instantiate a client object - a wrapper around the available calls for the given service. + + ```PHP + $blobClient = BlobRestProxy::createBlobService($connectionString); + ``` +### Using Middlewares +To specify the middlewares, user have to create an array with middlewares +and put it in the `$requestOptions` with key 'middlewares'. The sequence of +the array will affect the sequence in which the middleware is invoked. The +`$requestOptions` can usually be set in the options of an API call, such as +`MicrosoftAzure\Storage\Blob\Models\ListBlobOptions`. + +The user can push the middleware into the array with key 'middlewares' in +services' `$_options` instead when creating them if the middleware is to be +applied to each of the API call for a rest proxy. These middlewares will always +be invoked after the middlewares in the `$requestOptions`. +e.g.: +``` +$blobClient = BlobRestProxy::createBlobService( + $connectionString, + $optionsWithMiddlewares +); +``` + +Each of the middleware should be either an instance of a sub-class that +implements `MicrosoftAzure\Storage\Common\Internal\IMiddleware`, or a +`callable` that follows the Guzzle middleware implementation convention. + +User can create self-defined middleware that inherits from `MicrosoftAzure\Storage\Common\Internal\Middlewares\MiddlewareBase`. + +### Using proxies +To use proxies during HTTP requests, set system variable `HTTP_PROXY` and the proxy will be used. + +## Troubleshooting +### Error: Unable to get local issuer certificate +cURL can't verify the validity of Microsoft certificate when trying to issue a request call to Azure Storage Services. You must configure cURL to use a certificate when issuing https requests by the following steps: + +1. Download the cacert.pem file from [cURL site](http://curl.haxx.se/docs/caextract.html). +2. Open your php.ini file and add the following line: + + ``` + curl.cainfo = "" + ``` + +## Code samples + +You can find samples in the [sample folder](samples) + + +# Migrate from [Azure SDK for PHP](https://github.com/Azure/azure-sdk-for-php/) + +If you are using [Azure SDK for PHP](https://github.com/Azure/azure-sdk-for-php/) to access Azure Storage Service, we highly recommend you to migrate to this SDK for faster issue resolution and quicker feature implementation. We are working on supporting the latest service features as well as improvement on existing APIs. + +For now, Microsoft Azure Storage PHP client libraries share almost the same interface as the storage blobs, tables, queues and files APIs in Azure SDK for PHP. However, there are some minor breaking changes need to be addressed during your migration. You can find the details in [BreakingChanges.md](BreakingChanges.md). + +# Need Help? + +Be sure to check out the Microsoft Azure [Developer Forums on Stack Overflow](http://go.microsoft.com/fwlink/?LinkId=234489) and [github issues](https://github.com/Azure/azure-storage-php/issues) if you have trouble with the provided code. + +# Contribute Code or Provide Feedback + +If you would like to become an active contributor to this project please follow the instructions provided in [Azure Projects Contribution Guidelines](http://azure.github.io/guidelines/). +You can find more details for contributing in the [CONTRIBUTING.md](CONTRIBUTING.md). + +If you encounter any bugs with the library please file an issue in the [Issues](https://github.com/Azure/azure-storage-php/issues) section of the project. \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..1b13690 --- /dev/null +++ b/composer.json @@ -0,0 +1,22 @@ +{ + "name": "microsoft/azure-storage-blob", + "version": "1.0.0", + "description": "This project provides a set of PHP client libraries that make it easy to access Microsoft Azure Storage Blob APIs.", + "keywords": [ "php", "azure", "storage", "sdk", "blob" ], + "license": "MIT", + "authors": [ + { + "name": "Azure Storage PHP Client Library", + "email": "dmsh@microsoft.com" + } + ], + "require": { + "php": ">=5.6.0", + "microsoft/azure-storage-common": "~1.0" + }, + "autoload": { + "psr-4": { + "MicrosoftAzure\\Storage\\Blob\\": "src/Blob" + } + } +} \ No newline at end of file diff --git a/src/Blob/BlobRestProxy.php b/src/Blob/BlobRestProxy.php new file mode 100644 index 0000000..8672950 --- /dev/null +++ b/src/Blob/BlobRestProxy.php @@ -0,0 +1,4562 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob; + +use GuzzleHttp\Psr7; +use MicrosoftAzure\Storage\Blob\Internal\IBlob; +use MicrosoftAzure\Storage\Blob\Internal\BlobResources as Resources; +use MicrosoftAzure\Storage\Blob\Models\AppendBlockOptions; +use MicrosoftAzure\Storage\Blob\Models\AppendBlockResult; +use MicrosoftAzure\Storage\Blob\Models\BlobServiceOptions; +use MicrosoftAzure\Storage\Blob\Models\BlobType; +use MicrosoftAzure\Storage\Blob\Models\Block; +use MicrosoftAzure\Storage\Blob\Models\BlockList; +use MicrosoftAzure\Storage\Blob\Models\BreakLeaseResult; +use MicrosoftAzure\Storage\Blob\Models\CommitBlobBlocksOptions; +use MicrosoftAzure\Storage\Blob\Models\CopyBlobFromURLOptions; +use MicrosoftAzure\Storage\Blob\Models\CopyBlobOptions; +use MicrosoftAzure\Storage\Blob\Models\CopyBlobResult; +use MicrosoftAzure\Storage\Blob\Models\CreateBlobBlockOptions; +use MicrosoftAzure\Storage\Blob\Models\CreateBlobOptions; +use MicrosoftAzure\Storage\Blob\Models\CreateBlobPagesOptions; +use MicrosoftAzure\Storage\Blob\Models\CreateBlobPagesResult; +use MicrosoftAzure\Storage\Blob\Models\CreateBlobSnapshotOptions; +use MicrosoftAzure\Storage\Blob\Models\CreateBlobSnapshotResult; +use MicrosoftAzure\Storage\Blob\Models\CreateContainerOptions; +use MicrosoftAzure\Storage\Blob\Models\DeleteBlobOptions; +use MicrosoftAzure\Storage\Blob\Models\GetBlobMetadataOptions; +use MicrosoftAzure\Storage\Blob\Models\GetBlobMetadataResult; +use MicrosoftAzure\Storage\Blob\Models\GetBlobOptions; +use MicrosoftAzure\Storage\Blob\Models\GetBlobPropertiesOptions; +use MicrosoftAzure\Storage\Blob\Models\GetBlobPropertiesResult; +use MicrosoftAzure\Storage\Blob\Models\GetBlobResult; +use MicrosoftAzure\Storage\Blob\Models\GetContainerACLResult; +use MicrosoftAzure\Storage\Blob\Models\GetContainerPropertiesResult; +use MicrosoftAzure\Storage\Blob\Models\LeaseMode; +use MicrosoftAzure\Storage\Blob\Models\LeaseResult; +use MicrosoftAzure\Storage\Blob\Models\ListBlobBlocksOptions; +use MicrosoftAzure\Storage\Blob\Models\ListBlobBlocksResult; +use MicrosoftAzure\Storage\Blob\Models\ListBlobsOptions; +use MicrosoftAzure\Storage\Blob\Models\ListBlobsResult; +use MicrosoftAzure\Storage\Blob\Models\ListContainersOptions; +use MicrosoftAzure\Storage\Blob\Models\ListContainersResult; +use MicrosoftAzure\Storage\Blob\Models\ListPageBlobRangesDiffResult; +use MicrosoftAzure\Storage\Blob\Models\ListPageBlobRangesOptions; +use MicrosoftAzure\Storage\Blob\Models\ListPageBlobRangesResult; +use MicrosoftAzure\Storage\Blob\Models\PageWriteOption; +use MicrosoftAzure\Storage\Blob\Models\PutBlobResult; +use MicrosoftAzure\Storage\Blob\Models\PutBlockResult; +use MicrosoftAzure\Storage\Blob\Models\SetBlobMetadataResult; +use MicrosoftAzure\Storage\Blob\Models\SetBlobPropertiesOptions; +use MicrosoftAzure\Storage\Blob\Models\SetBlobPropertiesResult; +use MicrosoftAzure\Storage\Common\Internal\Authentication\SharedAccessSignatureAuthScheme; +use MicrosoftAzure\Storage\Common\Internal\Authentication\SharedKeyAuthScheme; +use MicrosoftAzure\Storage\Common\Internal\Http\HttpFormatter; +use MicrosoftAzure\Storage\Common\Internal\Middlewares\CommonRequestMiddleware; +use MicrosoftAzure\Storage\Common\Internal\Serialization\XmlSerializer; +use MicrosoftAzure\Storage\Common\Internal\ServiceRestProxy; +use MicrosoftAzure\Storage\Common\Internal\ServiceRestTrait; +use MicrosoftAzure\Storage\Common\Internal\StorageServiceSettings; +use MicrosoftAzure\Storage\Common\Internal\Utilities; +use MicrosoftAzure\Storage\Common\Internal\Validate; +use MicrosoftAzure\Storage\Common\LocationMode; +use MicrosoftAzure\Storage\Common\Models\Range; +use MicrosoftAzure\Storage\Common\SharedAccessSignatureHelper; +use Psr\Http\Message\StreamInterface; + +/** + * This class constructs HTTP requests and receive HTTP responses for blob + * service layer. + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class BlobRestProxy extends ServiceRestProxy implements IBlob +{ + use ServiceRestTrait; + + private $singleBlobUploadThresholdInBytes = Resources::MB_IN_BYTES_32; + private $blockSize = Resources::MB_IN_BYTES_4; + + /** + * Builds a blob service object, it accepts the following + * options: + * + * - http: (array) the underlying guzzle options. refer to + * http://docs.guzzlephp.org/en/latest/request-options.html for detailed available options + * - middlewares: (mixed) the middleware should be either an instance of a sub-class that + * implements {@see MicrosoftAzure\Storage\Common\Middlewares\IMiddleware}, or a + * `callable` that follows the Guzzle middleware implementation convention + * + * Please refer to + * https://azure.microsoft.com/en-us/documentation/articles/storage-configure-connection-string + * for how to construct a connection string with storage account name/key, or with a shared + * access signature (SAS Token). + * + * @param string $connectionString The configuration connection string. + * @param array $options Array of options to pass to the service + * @return BlobRestProxy + */ + public static function createBlobService( + $connectionString, + array $options = [] + ) { + $settings = StorageServiceSettings::createFromConnectionString( + $connectionString + ); + + $primaryUri = Utilities::tryAddUrlScheme( + $settings->getBlobEndpointUri() + ); + + $secondaryUri = Utilities::tryAddUrlScheme( + $settings->getBlobSecondaryEndpointUri() + ); + + $blobWrapper = new BlobRestProxy( + $primaryUri, + $secondaryUri, + $settings->getName(), + $options + ); + + // Getting authentication scheme + if ($settings->hasSasToken()) { + $authScheme = new SharedAccessSignatureAuthScheme( + $settings->getSasToken() + ); + } else { + $authScheme = new SharedKeyAuthScheme( + $settings->getName(), + $settings->getKey() + ); + } + + // Adding common request middleware + $commonRequestMiddleware = new CommonRequestMiddleware( + $authScheme, + Resources::STORAGE_API_LATEST_VERSION, + Resources::BLOB_SDK_VERSION + ); + $blobWrapper->pushMiddleware($commonRequestMiddleware); + + return $blobWrapper; + } + + /** + * Builds an anonymous access object with given primary service + * endpoint. The service endpoint should contain a scheme and a + * host, e.g.: + * http://mystorageaccount.blob.core.windows.net + * + * @param string $primaryServiceEndpoint Primary service endpoint. + * @param array $options Optional request options. + * + * @return BlobRestProxy + */ + public static function createContainerAnonymousAccess( + $primaryServiceEndpoint, + array $options = [] + ) { + Validate::canCastAsString($primaryServiceEndpoint, '$primaryServiceEndpoint'); + + $secondaryServiceEndpoint = Utilities::tryGetSecondaryEndpointFromPrimaryEndpoint( + $primaryServiceEndpoint + ); + + $blobWrapper = new BlobRestProxy( + $primaryServiceEndpoint, + $secondaryServiceEndpoint, + Utilities::tryParseAccountNameFromUrl($primaryServiceEndpoint), + $options + ); + + $blobWrapper->pushMiddleware(new CommonRequestMiddleware( + null, + Resources::STORAGE_API_LATEST_VERSION, + Resources::BLOB_SDK_VERSION + )); + + return $blobWrapper; + } + + /** + * Get the value for SingleBlobUploadThresholdInBytes + * + * @return int + */ + public function getSingleBlobUploadThresholdInBytes() + { + return $this->singleBlobUploadThresholdInBytes; + } + + /** + * Get the value for blockSize + * + * @return int + */ + public function getBlockSize() + { + return $this->blockSize; + } + + /** + * Set the value for SingleBlobUploadThresholdInBytes, Max 256MB + * + * @param int $val The max size to send as a single blob block + * + * @return void + */ + public function setSingleBlobUploadThresholdInBytes($val) + { + if ($val > Resources::MB_IN_BYTES_256) { + // What should the proper action here be? + $val = Resources::MB_IN_BYTES_256; + } elseif ($val < 1) { + // another spot that could use looking at + $val = Resources::MB_IN_BYTES_32; + } + $this->singleBlobUploadThresholdInBytes = $val; + //If block size is larger than singleBlobUploadThresholdInBytes, honor + //threshold. + $this->blockSize = $val > $this->blockSize ? $this->blockSize : $val; + } + + /** + * Set the value for block size, Max 100MB + * + * @param int $val The max size for each block to be sent. + * + * @return void + */ + public function setBlockSize($val) + { + if ($val > Resources::MB_IN_BYTES_100) { + // What should the proper action here be? + $val = Resources::MB_IN_BYTES_100; + } elseif ($val < 1) { + // another spot that could use looking at + $val = Resources::MB_IN_BYTES_4; + } + //If block size is larger than singleBlobUploadThresholdInBytes, honor + //threshold. + $val = $val > $this->singleBlobUploadThresholdInBytes ? + $this->singleBlobUploadThresholdInBytes : $val; + $this->blockSize = $val; + } + + /** + * Get the block size of multiple upload block size using the provided + * content + * + * @param StreamInterface $content The content of the blocks. + * + * @return int + */ + private function getMultipleUploadBlockSizeUsingContent($content) + { + //Default value is 100 MB. + $result = Resources::MB_IN_BYTES_100; + //PHP must be ran in 64bit environment so content->getSize() could + //return a guaranteed accurate size. + if (Utilities::is64BitPHP()) { + //Content must be seekable to determine the size. + if ($content->isSeekable()) { + $size = $content->getSize(); + //When threshold is lower than 100MB, assume maximum number of + //block is used for the block blob, if the blockSize is still + //smaller than the assumed size, it means assumed size should + //be hornored, otherwise the blocks count will exceed maximum + //value allowed. + if ($this->blockSize < $result) { + $assumedSize = ceil((float)$size / + (float)(Resources::MAX_BLOB_BLOCKS)); + if ($this->blockSize <= $assumedSize) { + $result = $assumedSize; + } else { + $result = $this->blockSize; + } + } + } + } else { + // If not, we could only honor user's setting to determine + // chunk size. + $result = $this->blockSize; + } + return $result; + } + + /** + * Gets the copy blob source name with specified parameters. + * + * @param string $containerName The name of the container. + * @param string $blobName The name of the blob. + * @param Models\CopyBlobOptions $options The optional parameters. + * + * @return string + */ + private function getCopyBlobSourceName( + $containerName, + $blobName, + Models\CopyBlobOptions $options + ) { + $sourceName = $this->getBlobUrl($containerName, $blobName); + + if (!is_null($options->getSourceSnapshot())) { + $sourceName .= '?snapshot=' . $options->getSourceSnapshot(); + } + + return $sourceName; + } + + /** + * Creates URI path for blob or container. + * + * @param string $container The container name. + * @param string $blob The blob name. + * + * @return string + */ + private function createPath($container, $blob = '') + { + if (empty($blob)) { + if (!empty($container)) { + return $container; + } else { + return '/' . $container; + } + } else { + $encodedBlob = urlencode($blob); + // Unencode the forward slashes to match what the server expects. + $encodedBlob = str_replace('%2F', '/', $encodedBlob); + // Unencode the backward slashes to match what the server expects. + $encodedBlob = str_replace('%5C', '/', $encodedBlob); + // Re-encode the spaces (encoded as space) to the % encoding. + $encodedBlob = str_replace('+', '%20', $encodedBlob); + // Empty container means accessing default container + if (empty($container)) { + return $encodedBlob; + } else { + return '/' . $container . '/' . $encodedBlob; + } + } + } + + /** + * Creates full URI to the given blob. + * + * @param string $container The container name. + * @param string $blob The blob name. + * + * @return string + */ + private function getBlobUrl($container, $blob) + { + $encodedBlob = $this->createPath($container, $blob); + + return (string)($this->getPsrPrimaryUri()->withPath($encodedBlob)); + } + + /** + * Helper method to create promise for getContainerProperties API call. + * + * @param string $container The container name. + * @param Models\BlobServiceOptions $options The optional parameters. + * @param string $operation The operation string. Should be + * 'metadata' to get metadata. + * + * @return \GuzzleHttp\Promise\PromiseInterface + */ + private function getContainerPropertiesAsyncImpl( + $container, + Models\BlobServiceOptions $options = null, + $operation = null + ) { + Validate::canCastAsString($container, 'container'); + + $method = Resources::HTTP_GET; + $headers = array(); + $queryParams = array(); + $postParams = array(); + $path = $this->createPath($container); + + if (is_null($options)) { + $options = new BlobServiceOptions(); + } + + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_REST_TYPE, + 'container' + ); + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_COMP, + $operation + ); + + $this->addOptionalHeader( + $headers, + Resources::X_MS_LEASE_ID, + $options->getLeaseId() + ); + $this->addOptionalAccessConditionHeader( + $headers, + $options->getAccessConditions() + ); + + return $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $path, + Resources::STATUS_OK, + Resources::EMPTY_STRING, + $options + )->then(function ($response) { + $responseHeaders = HttpFormatter::formatHeaders($response->getHeaders()); + return GetContainerPropertiesResult::create($responseHeaders); + }, null); + } + + /** + * Adds optional create blob headers. + * + * @param CreateBlobOptions $options The optional parameters. + * @param array $headers The HTTP request headers. + * + * @return array + */ + private function addCreateBlobOptionalHeaders( + CreateBlobOptions $options, + array $headers + ) { + $headers = $this->addOptionalAccessConditionHeader( + $headers, + $options->getAccessConditions() + ); + + $this->addOptionalHeader( + $headers, + Resources::X_MS_LEASE_ID, + $options->getLeaseId() + ); + + $headers = $this->addMetadataHeaders( + $headers, + $options->getMetadata() + ); + + $contentType = $options->getContentType(); + if (is_null($contentType)) { + $contentType = Resources::BINARY_FILE_TYPE; + } + + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_CONTENT_TYPE, + $contentType + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_CONTENT_ENCODING, + $options->getContentEncoding() + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_CONTENT_LANGUAGE, + $options->getContentLanguage() + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_CONTENT_MD5, + $options->getContentMD5() + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_CACHE_CONTROL, + $options->getCacheControl() + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_CONTENT_DISPOSITION, + $options->getContentDisposition() + ); + $this->addOptionalHeader( + $headers, + Resources::CONTENT_TYPE, + Resources::URL_ENCODED_CONTENT_TYPE + ); + + return $headers; + } + + /** + * Adds Range header to the headers array. + * + * @param array $headers The HTTP request headers. + * @param integer $start The start byte. + * @param integer $end The end byte. + * + * @return array + */ + private function addOptionalRangeHeader(array $headers, $start, $end) + { + if (!is_null($start) || !is_null($end)) { + $range = $start . '-' . $end; + $rangeValue = 'bytes=' . $range; + $this->addOptionalHeader($headers, Resources::RANGE, $rangeValue); + } + + return $headers; + } + + /** + * Get the expected status code of a given lease action. + * + * @param string $leaseAction The given lease action + * @return string + * @throws \Exception + */ + private static function getStatusCodeOfLeaseAction($leaseAction) + { + $statusCode = Resources::EMPTY_STRING; + switch ($leaseAction) { + case LeaseMode::ACQUIRE_ACTION: + $statusCode = Resources::STATUS_CREATED; + break; + case LeaseMode::RENEW_ACTION: + $statusCode = Resources::STATUS_OK; + break; + case LeaseMode::RELEASE_ACTION: + $statusCode = Resources::STATUS_OK; + break; + case LeaseMode::BREAK_ACTION: + $statusCode = Resources::STATUS_ACCEPTED; + break; + default: + throw new \Exception(Resources::NOT_IMPLEMENTED_MSG); + } + + return $statusCode; + } + + /** + * Creates promise that does the actual work for leasing a blob. + * + * @param string $leaseAction Lease action string. + * @param string $container Container name. + * @param string $blob Blob to lease name. + * @param string $proposedLeaseId Proposed lease id. + * @param int $leaseDuration Lease duration, in seconds. + * @param string $leaseId Existing lease id. + * @param int $breakPeriod Break period, in seconds. + * @param string $expectedStatusCode Expected status code. + * @param Models\BlobServiceOptions $options Optional parameters. + * @param Models\AccessCondition $accessCondition Access conditions. + * + * @return \GuzzleHttp\Promise\PromiseInterface + */ + private function putLeaseAsyncImpl( + $leaseAction, + $container, + $blob, + $proposedLeaseId, + $leaseDuration, + $leaseId, + $breakPeriod, + $expectedStatusCode, + Models\BlobServiceOptions $options, + Models\AccessCondition $accessCondition = null + ) { + Validate::canCastAsString($blob, 'blob'); + Validate::canCastAsString($container, 'container'); + Validate::notNullOrEmpty($container, 'container'); + + $method = Resources::HTTP_PUT; + $headers = array(); + $queryParams = array(); + $postParams = array(); + + if (empty($blob)) { + $path = $this->createPath($container); + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_REST_TYPE, + 'container' + ); + } else { + $path = $this->createPath($container, $blob); + } + $this->addOptionalQueryParam($queryParams, Resources::QP_COMP, 'lease'); + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_TIMEOUT, + $options->getTimeout() + ); + + $this->addOptionalHeader($headers, Resources::X_MS_LEASE_ID, $leaseId); + $this->addOptionalHeader( + $headers, + Resources::X_MS_LEASE_ACTION, + $leaseAction + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_LEASE_BREAK_PERIOD, + $breakPeriod + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_LEASE_DURATION, + $leaseDuration + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_PROPOSED_LEASE_ID, + $proposedLeaseId + ); + $this->addOptionalAccessConditionHeader($headers, $accessCondition); + + if (!is_null($options)) { + $options = new BlobServiceOptions(); + } + + $options->setLocationMode(LocationMode::PRIMARY_ONLY); + + return $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $path, + $expectedStatusCode, + Resources::EMPTY_STRING, + $options + ); + } + + /** + * Creates promise that does actual work for create and clear blob pages. + * + * @param string $action Either clear or create. + * @param string $container The container name. + * @param string $blob The blob name. + * @param Range $range The page ranges. + * @param string $content The content string. + * @param CreateBlobPagesOptions $options The optional parameters. + * + * @return \GuzzleHttp\Promise\PromiseInterface + */ + private function updatePageBlobPagesAsyncImpl( + $action, + $container, + $blob, + Range $range, + $content, + CreateBlobPagesOptions $options = null + ) { + Validate::canCastAsString($blob, 'blob'); + Validate::notNullOrEmpty($blob, 'blob'); + Validate::canCastAsString($container, 'container'); + Validate::canCastAsString($content, 'content'); + Validate::isTrue( + $range instanceof Range, + sprintf( + Resources::INVALID_PARAM_MSG, + 'range', + get_class(new Range(0)) + ) + ); + $body = Psr7\stream_for($content); + + $method = Resources::HTTP_PUT; + $headers = array(); + $queryParams = array(); + $postParams = array(); + $path = $this->createPath($container, $blob); + + if (is_null($options)) { + $options = new CreateBlobPagesOptions(); + } + + $headers = $this->addOptionalRangeHeader( + $headers, + $range->getStart(), + $range->getEnd() + ); + + $headers = $this->addOptionalAccessConditionHeader( + $headers, + $options->getAccessConditions() + ); + + $this->addOptionalHeader( + $headers, + Resources::X_MS_LEASE_ID, + $options->getLeaseId() + ); + $this->addOptionalHeader( + $headers, + Resources::CONTENT_MD5, + $options->getContentMD5() + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_PAGE_WRITE, + $action + ); + $this->addOptionalHeader( + $headers, + Resources::CONTENT_TYPE, + Resources::URL_ENCODED_CONTENT_TYPE + ); + $this->addOptionalQueryParam($queryParams, Resources::QP_COMP, 'page'); + + $options->setLocationMode(LocationMode::PRIMARY_ONLY); + + return $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $path, + Resources::STATUS_CREATED, + $body, + $options + )->then(function ($response) { + return CreateBlobPagesResult::create( + HttpFormatter::formatHeaders($response->getHeaders()) + ); + }, null); + } + + /** + * Lists all of the containers in the given storage account. + * + * @param ListContainersOptions $options The optional parameters. + * + * @return ListContainersResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179352.aspx + */ + public function listContainers(ListContainersOptions $options = null) + { + return $this->listContainersAsync($options)->wait(); + } + + /** + * Create a promise for lists all of the containers in the given + * storage account. + * + * @param ListContainersOptions $options The optional parameters. + * + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function listContainersAsync( + ListContainersOptions $options = null + ) { + $method = Resources::HTTP_GET; + $headers = array(); + $queryParams = array(); + $postParams = array(); + $path = Resources::EMPTY_STRING; + + if (is_null($options)) { + $options = new ListContainersOptions(); + } + + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_COMP, + 'list' + ); + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_PREFIX, + $options->getPrefix() + ); + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_MARKER, + $options->getNextMarker() + ); + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_MAX_RESULTS, + $options->getMaxResults() + ); + $isInclude = $options->getIncludeMetadata(); + $isInclude = $isInclude ? 'metadata' : null; + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_INCLUDE, + $isInclude + ); + + $dataSerializer = $this->dataSerializer; + + return $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $path, + Resources::STATUS_OK, + Resources::EMPTY_STRING, + $options + )->then(function ($response) use ($dataSerializer) { + $parsed = $this->dataSerializer->unserialize($response->getBody()); + return ListContainersResult::create( + $parsed, + Utilities::getLocationFromHeaders($response->getHeaders()) + ); + }); + } + + /** + * Creates a new container in the given storage account. + * + * @param string $container The container name. + * @param Models\CreateContainerOptions $options The optional parameters. + * + * @return void + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179468.aspx + */ + public function createContainer( + $container, + Models\CreateContainerOptions $options = null + ) { + $this->createContainerAsync($container, $options)->wait(); + } + + /** + * Creates a new container in the given storage account. + * + * @param string $container The container name. + * @param Models\CreateContainerOptions $options The optional parameters. + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179468.aspx + */ + public function createContainerAsync( + $container, + Models\CreateContainerOptions $options = null + ) { + Validate::canCastAsString($container, 'container'); + Validate::notNullOrEmpty($container, 'container'); + + $method = Resources::HTTP_PUT; + $headers = array(); + $postParams = array(); + $queryParams = array(Resources::QP_REST_TYPE => 'container'); + $path = $this->createPath($container); + + if (is_null($options)) { + $options = new CreateContainerOptions(); + } + + $metadata = $options->getMetadata(); + $headers = $this->generateMetadataHeaders($metadata); + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_PUBLIC_ACCESS, + $options->getPublicAccess() + ); + + $options->setLocationMode(LocationMode::PRIMARY_ONLY); + + return $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $path, + Resources::STATUS_CREATED, + Resources::EMPTY_STRING, + $options + ); + } + + /** + * Deletes a container in the given storage account. + * + * @param string $container The container name. + * @param Models\BlobServiceOptions $options The optional parameters. + * + * @return void + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179408.aspx + */ + public function deleteContainer( + $container, + Models\BlobServiceOptions $options = null + ) { + $this->deleteContainerAsync($container, $options)->wait(); + } + + /** + * Create a promise for deleting a container. + * + * @param string $container name of the container + * @param Models\BlobServiceOptions|null $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function deleteContainerAsync( + $container, + Models\BlobServiceOptions $options = null + ) { + Validate::canCastAsString($container, 'container'); + Validate::notNullOrEmpty($container, 'container'); + + $method = Resources::HTTP_DELETE; + $headers = array(); + $postParams = array(); + $queryParams = array(); + $path = $this->createPath($container); + + if (is_null($options)) { + $options = new BlobServiceOptions(); + } + + $this->addOptionalHeader( + $headers, + Resources::X_MS_LEASE_ID, + $options->getLeaseId() + ); + $headers = $this->addOptionalAccessConditionHeader( + $headers, + $options->getAccessConditions() + ); + + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_REST_TYPE, + 'container' + ); + + $options->setLocationMode(LocationMode::PRIMARY_ONLY); + + return $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $path, + Resources::STATUS_ACCEPTED, + Resources::EMPTY_STRING, + $options + ); + } + + /** + * Returns all properties and metadata on the container. + * + * @param string $container name + * @param Models\BlobServiceOptions $options optional parameters + * + * @return Models\GetContainerPropertiesResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179370.aspx + */ + public function getContainerProperties( + $container, + Models\BlobServiceOptions $options = null + ) { + return $this->getContainerPropertiesAsync($container, $options)->wait(); + } + + /** + * Create promise to return all properties and metadata on the container. + * + * @param string $container name + * @param Models\BlobServiceOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179370.aspx + */ + public function getContainerPropertiesAsync( + $container, + Models\BlobServiceOptions $options = null + ) { + return $this->getContainerPropertiesAsyncImpl($container, $options); + } + + /** + * Returns only user-defined metadata for the specified container. + * + * @param string $container name + * @param Models\BlobServiceOptions $options optional parameters + * + * @return Models\GetContainerPropertiesResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691976.aspx + */ + public function getContainerMetadata( + $container, + Models\BlobServiceOptions $options = null + ) { + return $this->getContainerMetadataAsync($container, $options)->wait(); + } + + /** + * Create promise to return only user-defined metadata for the specified + * container. + * + * @param string $container name + * @param Models\BlobServiceOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691976.aspx + */ + public function getContainerMetadataAsync( + $container, + Models\BlobServiceOptions $options = null + ) { + return $this->getContainerPropertiesAsyncImpl($container, $options, 'metadata'); + } + + /** + * Gets the access control list (ACL) and any container-level access policies + * for the container. + * + * @param string $container The container name. + * @param Models\BlobServiceOptions $options The optional parameters. + * + * @return Models\GetContainerACLResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179469.aspx + */ + public function getContainerAcl( + $container, + Models\BlobServiceOptions $options = null + ) { + return $this->getContainerAclAsync($container, $options)->wait(); + } + + /** + * Creates the promise to get the access control list (ACL) and any + * container-level access policies for the container. + * + * @param string $container The container name. + * @param Models\BlobServiceOptions $options The optional parameters. + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179469.aspx + */ + public function getContainerAclAsync( + $container, + Models\BlobServiceOptions $options = null + ) { + Validate::canCastAsString($container, 'container'); + + $method = Resources::HTTP_GET; + $headers = array(); + $postParams = array(); + $queryParams = array(); + $path = $this->createPath($container); + $statusCode = Resources::STATUS_OK; + + if (is_null($options)) { + $options = new BlobServiceOptions(); + } + + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_REST_TYPE, + 'container' + ); + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_COMP, + 'acl' + ); + + $this->addOptionalHeader( + $headers, + Resources::X_MS_LEASE_ID, + $options->getLeaseId() + ); + $this->addOptionalAccessConditionHeader( + $headers, + $options->getAccessConditions() + ); + + $dataSerializer = $this->dataSerializer; + + $promise = $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $path, + Resources::STATUS_OK, + Resources::EMPTY_STRING, + $options + ); + + return $promise->then(function ($response) use ($dataSerializer) { + $responseHeaders = HttpFormatter::formatHeaders($response->getHeaders()); + + $access = Utilities::tryGetValue( + $responseHeaders, + Resources::X_MS_BLOB_PUBLIC_ACCESS + ); + $etag = Utilities::tryGetValue($responseHeaders, Resources::ETAG); + $modified = Utilities::tryGetValue( + $responseHeaders, + Resources::LAST_MODIFIED + ); + $modifiedDate = Utilities::convertToDateTime($modified); + $parsed = $dataSerializer->unserialize($response->getBody()); + + return GetContainerAclResult::create( + $access, + $etag, + $modifiedDate, + $parsed + ); + }, null); + } + + /** + * Sets the ACL and any container-level access policies for the container. + * + * @param string $container name + * @param Models\ContainerACL $acl access control list for container + * @param Models\BlobServiceOptions $options optional parameters + * + * @return void + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179391.aspx + */ + public function setContainerAcl( + $container, + Models\ContainerACL $acl, + Models\BlobServiceOptions $options = null + ) { + $this->setContainerAclAsync($container, $acl, $options)->wait(); + } + + /** + * Creates promise to set the ACL and any container-level access policies + * for the container. + * + * @param string $container name + * @param Models\ContainerACL $acl access control list for container + * @param Models\BlobServiceOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179391.aspx + */ + public function setContainerAclAsync( + $container, + Models\ContainerACL $acl, + Models\BlobServiceOptions $options = null + ) { + Validate::canCastAsString($container, 'container'); + Validate::notNullOrEmpty($acl, 'acl'); + + $method = Resources::HTTP_PUT; + $headers = array(); + $postParams = array(); + $queryParams = array(); + $path = $this->createPath($container); + $body = $acl->toXml($this->dataSerializer); + + if (is_null($options)) { + $options = new BlobServiceOptions(); + } + + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_REST_TYPE, + 'container' + ); + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_COMP, + 'acl' + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_PUBLIC_ACCESS, + $acl->getPublicAccess() + ); + $this->addOptionalHeader( + $headers, + Resources::CONTENT_TYPE, + Resources::URL_ENCODED_CONTENT_TYPE + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_LEASE_ID, + $options->getLeaseId() + ); + $this->addOptionalAccessConditionHeader( + $headers, + $options->getAccessConditions() + ); + + $options->setLocationMode(LocationMode::PRIMARY_ONLY); + + return $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $path, + Resources::STATUS_OK, + $body, + $options + ); + } + + /** + * Sets metadata headers on the container. + * + * @param string $container name + * @param array $metadata metadata key/value pair. + * @param Models\BlobServiceOptions $options optional parameters + * + * @return void + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179362.aspx + */ + public function setContainerMetadata( + $container, + array $metadata, + Models\BlobServiceOptions $options = null + ) { + $this->setContainerMetadataAsync($container, $metadata, $options)->wait(); + } + + /** + * Sets metadata headers on the container. + * + * @param string $container name + * @param array $metadata metadata key/value pair. + * @param Models\BlobServiceOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179362.aspx + */ + public function setContainerMetadataAsync( + $container, + array $metadata, + Models\BlobServiceOptions $options = null + ) { + Validate::canCastAsString($container, 'container'); + Utilities::validateMetadata($metadata); + + $method = Resources::HTTP_PUT; + $headers = $this->generateMetadataHeaders($metadata); + $postParams = array(); + $queryParams = array(); + $path = $this->createPath($container); + + if (is_null($options)) { + $options = new BlobServiceOptions(); + } + + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_REST_TYPE, + 'container' + ); + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_COMP, + 'metadata' + ); + + $this->addOptionalHeader( + $headers, + Resources::X_MS_LEASE_ID, + $options->getLeaseId() + ); + + $headers = $this->addOptionalAccessConditionHeader( + $headers, + $options->getAccessConditions() + ); + + $options->setLocationMode(LocationMode::PRIMARY_ONLY); + + return $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $path, + Resources::STATUS_OK, + Resources::EMPTY_STRING, + $options + ); + } + + /** + * Lists all of the blobs in the given container. + * + * @param string $container The container name. + * @param Models\ListBlobsOptions $options The optional parameters. + * + * @return Models\ListBlobsResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd135734.aspx + */ + public function listBlobs($container, Models\ListBlobsOptions $options = null) + { + return $this->listBlobsAsync($container, $options)->wait(); + } + + /** + * Creates promise to list all of the blobs in the given container. + * + * @param string $container The container name. + * @param Models\ListBlobsOptions $options The optional parameters. + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd135734.aspx + */ + public function listBlobsAsync( + $container, + Models\ListBlobsOptions $options = null + ) { + Validate::notNull($container, 'container'); + Validate::canCastAsString($container, 'container'); + + $method = Resources::HTTP_GET; + $headers = array(); + $postParams = array(); + $queryParams = array(); + $path = $this->createPath($container); + + if (is_null($options)) { + $options = new ListBlobsOptions(); + } + + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_REST_TYPE, + 'container' + ); + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_COMP, + 'list' + ); + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_PREFIX, + str_replace('\\', '/', $options->getPrefix()) + ); + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_MARKER, + $options->getNextMarker() + ); + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_DELIMITER, + $options->getDelimiter() + ); + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_MAX_RESULTS, + $options->getMaxResults() + ); + + $includeMetadata = $options->getIncludeMetadata(); + $includeSnapshots = $options->getIncludeSnapshots(); + $includeUncommittedBlobs = $options->getIncludeUncommittedBlobs(); + $includecopy = $options->getIncludeCopy(); + + $includeValue = static::groupQueryValues( + array( + $includeMetadata ? 'metadata' : null, + $includeSnapshots ? 'snapshots' : null, + $includeUncommittedBlobs ? 'uncommittedblobs' : null, + $includecopy ? 'copy' : null + ) + ); + + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_INCLUDE, + $includeValue + ); + + $dataSerializer = $this->dataSerializer; + + return $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $path, + Resources::STATUS_OK, + Resources::EMPTY_STRING, + $options + )->then(function ($response) use ($dataSerializer) { + $parsed = $dataSerializer->unserialize($response->getBody()); + return ListBlobsResult::create( + $parsed, + Utilities::getLocationFromHeaders($response->getHeaders()) + ); + }, null); + } + + /** + * Creates a new page blob. Note that calling createPageBlob to create a page + * blob only initializes the blob. + * To add content to a page blob, call createBlobPages method. + * + * @param string $container The container name. + * @param string $blob The blob name. + * @param integer $length Specifies the maximum size + * for the page blob, up to 1 TB. + * The page blob size must be + * aligned to a 512-byte + * boundary. + * @param Models\CreateBlobOptions $options The optional parameters. + * + * @return Models\PutBlobResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179451.aspx + */ + public function createPageBlob( + $container, + $blob, + $length, + Models\CreateBlobOptions $options = null + ) { + return $this->createPageBlobAsync( + $container, + $blob, + $length, + $options + )->wait(); + } + + /** + * Creates promise to create a new page blob. Note that calling + * createPageBlob to create a page blob only initializes the blob. + * To add content to a page blob, call createBlobPages method. + * + * @param string $container The container name. + * @param string $blob The blob name. + * @param integer $length Specifies the maximum size + * for the page blob, up to 1 TB. + * The page blob size must be + * aligned to a 512-byte + * boundary. + * @param Models\CreateBlobOptions $options The optional parameters. + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179451.aspx + */ + public function createPageBlobAsync( + $container, + $blob, + $length, + Models\CreateBlobOptions $options = null + ) { + Validate::canCastAsString($container, 'container'); + Validate::canCastAsString($blob, 'blob'); + Validate::notNullOrEmpty($blob, 'blob'); + Validate::isInteger($length, 'length'); + Validate::notNull($length, 'length'); + + $method = Resources::HTTP_PUT; + $headers = array(); + $postParams = array(); + $queryParams = array(); + $path = $this->createPath($container, $blob); + + if (is_null($options)) { + $options = new CreateBlobOptions(); + } + + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_TYPE, + BlobType::PAGE_BLOB + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_CONTENT_LENGTH, + $length + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_SEQUENCE_NUMBER, + $options->getSequenceNumber() + ); + $headers = $this->addCreateBlobOptionalHeaders($options, $headers); + + $options->setLocationMode(LocationMode::PRIMARY_ONLY); + + return $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $path, + Resources::STATUS_CREATED, + Resources::EMPTY_STRING, + $options + )->then(function ($response) { + return PutBlobResult::create( + HttpFormatter::formatHeaders($response->getHeaders()) + ); + }, null); + } + + /** + * Create a new append blob. + * If the blob already exists on the service, it will be overwritten. + * + * @param string $container The container name. + * @param string $blob The blob name. + * @param Models\CreateBlobOptions $options The optional parameters. + * + * @return Models\PutBlobResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179451.aspx + */ + public function createAppendBlob( + $container, + $blob, + Models\CreateBlobOptions $options = null + ) { + return $this->createAppendBlobAsync( + $container, + $blob, + $options + )->wait(); + } + + /** + * Creates promise to create a new append blob. + * If the blob already exists on the service, it will be overwritten. + * + * @param string $container The container name. + * @param string $blob The blob name. + * @param Models\CreateBlobOptions $options The optional parameters. + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179451.aspx + */ + public function createAppendBlobAsync( + $container, + $blob, + Models\CreateBlobOptions $options = null + ) { + Validate::canCastAsString($container, 'container'); + Validate::notNullOrEmpty($container, 'container'); + Validate::canCastAsString($blob, 'blob'); + Validate::notNullOrEmpty($blob, 'blob'); + + $method = Resources::HTTP_PUT; + $headers = array(); + $postParams = array(); + $queryParams = array(); + $path = $this->createPath($container, $blob); + $statusCode = Resources::STATUS_CREATED; + + if (is_null($options)) { + $options = new CreateBlobOptions(); + } + + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_TYPE, + BlobType::APPEND_BLOB + ); + $headers = $this->addCreateBlobOptionalHeaders($options, $headers); + + $options->setLocationMode(LocationMode::PRIMARY_ONLY); + + return $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $path, + Resources::STATUS_CREATED, + Resources::EMPTY_STRING, + $options + )->then(function ($response) { + return PutBlobResult::create( + HttpFormatter::formatHeaders($response->getHeaders()) + ); + }, null); + } + + /** + * Creates a new block blob or updates the content of an existing block blob. + * + * Updating an existing block blob overwrites any existing metadata on the blob. + * Partial updates are not supported with createBlockBlob the content of the + * existing blob is overwritten with the content of the new blob. To perform a + * partial update of the content of a block blob, use the createBlockList + * method. + * Note that the default content type is application/octet-stream. + * + * @param string $container The name of the container. + * @param string $blob The name of the blob. + * @param string|resource|StreamInterface $content The content of the blob. + * @param Models\CreateBlockBlobOptions $options The optional parameters. + * + * @return Models\PutBlobResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179451.aspx + */ + public function createBlockBlob( + $container, + $blob, + $content, + Models\CreateBlockBlobOptions $options = null + ) { + return $this->createBlockBlobAsync( + $container, + $blob, + $content, + $options + )->wait(); + } + + /** + * Creates a promise to create a new block blob or updates the content of + * an existing block blob. + * + * Updating an existing block blob overwrites any existing metadata on the blob. + * Partial updates are not supported with createBlockBlob the content of the + * existing blob is overwritten with the content of the new blob. To perform a + * partial update of the content of a block blob, use the createBlockList + * method. + * + * @param string $container The name of the container. + * @param string $blob The name of the blob. + * @param string|resource|StreamInterface $content The content of the blob. + * @param Models\CreateBlockBlobOptions $options The optional parameters. + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179451.aspx + */ + public function createBlockBlobAsync( + $container, + $blob, + $content, + Models\CreateBlockBlobOptions $options = null + ) { + $body = Psr7\stream_for($content); + + //If the size of the stream is not seekable or larger than the single + //upload threshold then call concurrent upload. Otherwise call putBlob. + $promise = null; + if (!Utilities::isStreamLargerThanSizeOrNotSeekable( + $body, + $this->singleBlobUploadThresholdInBytes + )) { + $promise = $this->createBlockBlobBySingleUploadAsync( + $container, + $blob, + $body, + $options + ); + } else { + // This is for large or failsafe upload + $promise = $this->createBlockBlobByMultipleUploadAsync( + $container, + $blob, + $body, + $options + ); + } + + //return the parsed result, instead of the raw response. + return $promise; + } + + /** + * Create a new page blob and upload the content to the page blob. + * + * @param string $container The name of the container. + * @param string $blob The name of the blob. + * @param int $length The length of the blob. + * @param string|resource|StreamInterface $content The content of the blob. + * @param Models\CreatePageBlobFromContentOptions + * $options The optional parameters. + * + * @return Models\GetBlobPropertiesResult + * + * @see https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/get-blob-properties + */ + public function createPageBlobFromContent( + $container, + $blob, + $length, + $content, + Models\CreatePageBlobFromContentOptions $options = null + ) { + return $this->createPageBlobFromContentAsync( + $container, + $blob, + $length, + $content, + $options + )->wait(); + } + + /** + * Creates a promise to create a new page blob and upload the content + * to the page blob. + * + * @param string $container The name of the container. + * @param string $blob The name of the blob. + * @param int $length The length of the blob. + * @param string|resource|StreamInterface $content The content of the blob. + * @param Models\CreatePageBlobFromContentOptions + * $options The optional parameters. + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/get-blob-properties + */ + public function createPageBlobFromContentAsync( + $container, + $blob, + $length, + $content, + Models\CreatePageBlobFromContentOptions $options = null + ) { + $body = Psr7\stream_for($content); + $self = $this; + + if (is_null($options)) { + $options = new Models\CreatePageBlobFromContentOptions(); + } + + $createBlobPromise = $this->createPageBlobAsync( + $container, + $blob, + $length, + $options + ); + + $uploadBlobPromise = $createBlobPromise->then( + function ($value) use ( + $self, + $container, + $blob, + $body, + $options + ) { + $result = $value; + return $self->uploadPageBlobAsync( + $container, + $blob, + $body, + $options + ); + }, + null + ); + + return $uploadBlobPromise->then( + function ($value) use ( + $self, + $container, + $blob, + $options + ) { + $getBlobPropertiesOptions = new GetBlobPropertiesOptions(); + $getBlobPropertiesOptions->setLeaseId($options->getLeaseId()); + + return $self->getBlobPropertiesAsync( + $container, + $blob, + $getBlobPropertiesOptions + ); + }, + null + ); + } + + /** + * Creates promise to create a new block blob or updates the content of an + * existing block blob. This only supports contents smaller than single + * upload threashold. + * + * Updating an existing block blob overwrites any existing metadata on + * the blob. + * + * @param string $container The name of the container. + * @param string $blob The name of the blob. + * @param StreamInterface $content The content of the blob. + * @param Models\CreateBlobOptions $options The optional parameters. + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179451.aspx + */ + protected function createBlockBlobBySingleUploadAsync( + $container, + $blob, + $content, + Models\CreateBlobOptions $options = null + ) { + Validate::canCastAsString($container, 'container'); + Validate::canCastAsString($blob, 'blob'); + Validate::notNullOrEmpty($blob, 'blob'); + Validate::isTrue( + $options == null || + $options instanceof CreateBlobOptions, + sprintf( + Resources::INVALID_PARAM_MSG, + 'options', + get_class(new CreateBlobOptions()) + ) + ); + + $method = Resources::HTTP_PUT; + $headers = array(); + $postParams = array(); + $queryParams = array(); + $path = $this->createPath($container, $blob); + + if (is_null($options)) { + $options = new CreateBlobOptions(); + } + + $headers = $this->addCreateBlobOptionalHeaders($options, $headers); + + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_TYPE, + BlobType::BLOCK_BLOB + ); + + $options->setLocationMode(LocationMode::PRIMARY_ONLY); + + return $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $path, + Resources::STATUS_CREATED, + $content, + $options + )->then( + function ($response) { + return PutBlobResult::create( + HttpFormatter::formatHeaders($response->getHeaders()) + ); + }, + null + ); + } + + /** + * This method creates the blob blocks. This method will send the request + * concurrently for better performance. + * + * @param string $container Name of the container + * @param string $blob Name of the blob + * @param StreamInterface $content Content's stream + * @param Models\CreateBlockBlobOptions $options Array that contains + * all the option + * + * @return \GuzzleHttp\Promise\PromiseInterface + */ + protected function createBlockBlobByMultipleUploadAsync( + $container, + $blob, + $content, + Models\CreateBlockBlobOptions $options = null + ) { + Validate::canCastAsString($container, 'container'); + Validate::canCastAsString($blob, 'blob'); + + if ($content->isSeekable() && Utilities::is64BitPHP()) { + Validate::isTrue( + $content->getSize() <= Resources::MAX_BLOCK_BLOB_SIZE, + Resources::CONTENT_SIZE_TOO_LARGE + ); + } + + if (is_null($options)) { + $options = new Models\CreateBlockBlobOptions(); + } + + $createBlobBlockOptions = CreateBlobBlockOptions::create($options); + $selfInstance = $this; + + $method = Resources::HTTP_PUT; + $headers = $this->createBlobBlockHeader($createBlobBlockOptions); + $postParams = array(); + $path = $this->createPath($container, $blob); + $useTransactionalMD5 = $options->getUseTransactionalMD5(); + + $blockIds = array(); + //Determine the block size according to the content and threshold. + $blockSize = $this->getMultipleUploadBlockSizeUsingContent($content); + $counter = 0; + //create the generator for requests. + //this generator also constructs the blockId array on the fly. + $generator = function () use ( + $content, + &$blockIds, + $blockSize, + $createBlobBlockOptions, + $method, + $headers, + $postParams, + $path, + $useTransactionalMD5, + &$counter, + $selfInstance + ) { + //read the content. + $blockContent = $content->read($blockSize); + //construct the blockId + $blockId = base64_encode( + str_pad($counter++, 6, '0', STR_PAD_LEFT) + ); + $size = strlen($blockContent); + if ($size == 0) { + return null; + } + + if ($useTransactionalMD5) { + $contentMD5 = base64_encode(md5($blockContent, true)); + $selfInstance->addOptionalHeader( + $headers, + Resources::CONTENT_MD5, + $contentMD5 + ); + } + + //add the id to array. + array_push($blockIds, new Block($blockId, 'Uncommitted')); + $queryParams = $selfInstance->createBlobBlockQueryParams( + $createBlobBlockOptions, + $blockId, + true + ); + //return the array of requests. + return $selfInstance->createRequest( + $method, + $headers, + $queryParams, + $postParams, + $path, + LocationMode::PRIMARY_ONLY, + $blockContent + ); + }; + + //Send the request concurrently. + //Does not need to evaluate the results. If operation not successful, + //exception will be thrown. + $putBlobPromise = $this->sendConcurrentAsync( + $generator, + Resources::STATUS_CREATED, + $options + ); + + $commitBlobPromise = $putBlobPromise->then( + function ($value) use ( + $selfInstance, + $container, + $blob, + &$blockIds, + $putBlobPromise, + $options + ) { + return $selfInstance->commitBlobBlocksAsync( + $container, + $blob, + $blockIds, + CommitBlobBlocksOptions::create($options) + ); + }, + null + ); + + return $commitBlobPromise; + } + + + /** + * This method upload the page blob pages. This method will send the request + * concurrently for better performance. + * + * @param string $container Name of the container + * @param string $blob Name of the blob + * @param StreamInterface $content Content's stream + * @param Models\CreatePageBlobFromContentOptions + * $options Array that contains + * all the option + * + * @return \GuzzleHttp\Promise\PromiseInterface + */ + private function uploadPageBlobAsync( + $container, + $blob, + $content, + Models\CreatePageBlobFromContentOptions $options = null + ) { + Validate::canCastAsString($container, 'container'); + Validate::notNullOrEmpty($container, 'container'); + + Validate::canCastAsString($blob, 'blob'); + Validate::notNullOrEmpty($blob, 'blob'); + + if (is_null($options)) { + $options = new Models\CreatePageBlobFromContentOptions(); + } + + $method = Resources::HTTP_PUT; + $postParams = array(); + $queryParams = array(); + $path = $this->createPath($container, $blob); + $useTransactionalMD5 = $options->getUseTransactionalMD5(); + + $this->addOptionalQueryParam($queryParams, Resources::QP_COMP, 'page'); + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_TIMEOUT, + $options->getTimeout() + ); + + $pageSize = Resources::MB_IN_BYTES_4; + $start = 0; + $end = -1; + + //create the generator for requests. + $generator = function () use ( + $content, + $pageSize, + $method, + $postParams, + $queryParams, + $path, + $useTransactionalMD5, + &$start, + &$end, + $options + ) { + //read the content. + do { + $pageContent = $content->read($pageSize); + $size = strlen($pageContent); + + if ($size == 0) { + return null; + } + + $end += $size; + $start = ($end - $size + 1); + + // If all Zero, skip this range + } while (Utilities::allZero($pageContent)); + + $headers = array(); + $headers = $this->addOptionalRangeHeader( + $headers, + $start, + $end + ); + $headers = $this->addOptionalAccessConditionHeader( + $headers, + $options->getAccessConditions() + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_LEASE_ID, + $options->getLeaseId() + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_PAGE_WRITE, + PageWriteOption::UPDATE_OPTION + ); + + if ($useTransactionalMD5) { + $contentMD5 = base64_encode(md5($pageContent, true)); + $this->addOptionalHeader( + $headers, + Resources::CONTENT_MD5, + $contentMD5 + ); + } + + //return the array of requests. + return $this->createRequest( + $method, + $headers, + $queryParams, + $postParams, + $path, + LocationMode::PRIMARY_ONLY, + $pageContent + ); + }; + + //Send the request concurrently. + //Does not need to evaluate the results. If operation is not successful, + //exception will be thrown. + return $this->sendConcurrentAsync( + $generator, + Resources::STATUS_CREATED, + $options + ); + } + + /** + * Clears a range of pages from the blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param Range $range Can be up to the value of + * the blob's full size. + * Note that ranges must be + * aligned to 512 (0-511, + * 512-1023) + * @param Models\CreateBlobPagesOptions $options optional parameters + * + * @return Models\CreateBlobPagesResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691975.aspx + */ + public function clearBlobPages( + $container, + $blob, + Range $range, + Models\CreateBlobPagesOptions $options = null + ) { + return $this->clearBlobPagesAsync( + $container, + $blob, + $range, + $options + )->wait(); + } + + /** + * Creates promise to clear a range of pages from the blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param Range $range Can be up to the value of + * the blob's full size. + * Note that ranges must be + * aligned to 512 (0-511, + * 512-1023) + * @param Models\CreateBlobPagesOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691975.aspx + */ + public function clearBlobPagesAsync( + $container, + $blob, + Range $range, + Models\CreateBlobPagesOptions $options = null + ) { + return $this->updatePageBlobPagesAsyncImpl( + PageWriteOption::CLEAR_OPTION, + $container, + $blob, + $range, + Resources::EMPTY_STRING, + $options + ); + } + + /** + * Creates a range of pages to a page blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param Range $range Can be up to 4 MB in + * size. Note that ranges + * must be aligned to 512 + * (0-511, 512-1023) + * @param string|resource|StreamInterface $content the blob contents. + * @param Models\CreateBlobPagesOptions $options optional parameters + * + * @return Models\CreateBlobPagesResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691975.aspx + */ + public function createBlobPages( + $container, + $blob, + Range $range, + $content, + Models\CreateBlobPagesOptions $options = null + ) { + return $this->createBlobPagesAsync( + $container, + $blob, + $range, + $content, + $options + )->wait(); + } + + /** + * Creates promise to create a range of pages to a page blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param Range $range Can be up to 4 MB in + * size. Note that ranges + * must be aligned to 512 + * (0-511, 512-1023) + * @param string|resource|StreamInterface $content the blob contents. + * @param Models\CreateBlobPagesOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691975.aspx + */ + public function createBlobPagesAsync( + $container, + $blob, + Range $range, + $content, + Models\CreateBlobPagesOptions $options = null + ) { + $contentStream = Psr7\stream_for($content); + //because the content is at most 4MB long, can retrieve all the data + //here at once. + $body = $contentStream->getContents(); + + //if the range is not align to 512, throw exception. + $chunks = (int)($range->getLength() / 512); + if ($chunks * 512 != $range->getLength()) { + throw new \RuntimeException(Resources::ERROR_RANGE_NOT_ALIGN_TO_512); + } + + return $this->updatePageBlobPagesAsyncImpl( + PageWriteOption::UPDATE_OPTION, + $container, + $blob, + $range, + $body, + $options + ); + } + + /** + * Creates a new block to be committed as part of a block blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $blockId must be less than or + * equal to 64 bytes in + * size. For a given blob, + * the length of the value + * specified for the + * blockid parameter must + * be the same size for + * each block. + * @param resource|string|StreamInterface $content the blob block contents + * @param Models\CreateBlobBlockOptions $options optional parameters + * + * @return Models\PutBlockResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd135726.aspx + */ + public function createBlobBlock( + $container, + $blob, + $blockId, + $content, + Models\CreateBlobBlockOptions $options = null + ) { + return $this->createBlobBlockAsync( + $container, + $blob, + $blockId, + $content, + $options + )->wait(); + } + + /** + * Creates a new block to be committed as part of a block blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $blockId must be less than or + * equal to 64 bytes in + * size. For a given blob, + * the length of the value + * specified for the + * blockid parameter must + * be the same size for + * each block. + * @param resource|string|StreamInterface $content the blob block contents + * @param Models\CreateBlobBlockOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd135726.aspx + */ + public function createBlobBlockAsync( + $container, + $blob, + $blockId, + $content, + Models\CreateBlobBlockOptions $options = null + ) { + Validate::canCastAsString($container, 'container'); + Validate::canCastAsString($blob, 'blob'); + Validate::notNullOrEmpty($blob, 'blob'); + Validate::canCastAsString($blockId, 'blockId'); + Validate::notNullOrEmpty($blockId, 'blockId'); + + if (is_null($options)) { + $options = new CreateBlobBlockOptions(); + } + + $method = Resources::HTTP_PUT; + $headers = $this->createBlobBlockHeader($options); + $postParams = array(); + $queryParams = $this->createBlobBlockQueryParams($options, $blockId); + $path = $this->createPath($container, $blob); + $statusCode = Resources::STATUS_CREATED; + $contentStream = Psr7\stream_for($content); + $body = $contentStream->getContents(); + + $options->setLocationMode(LocationMode::PRIMARY_ONLY); + + return $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $path, + Resources::STATUS_CREATED, + $body, + $options + )->then(function ($response) { + return PutBlockResult::create( + HttpFormatter::formatHeaders($response->getHeaders()) + ); + }); + } + + /** + * Commits a new block of data to the end of an existing append blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param resource|string|StreamInterface $content the blob block contents + * @param Models\AppendBlockOptions $options optional parameters + * + * @return Models\AppendBlockResult + * + * @see https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/append-block + */ + public function appendBlock( + $container, + $blob, + $content, + Models\AppendBlockOptions $options = null + ) { + return $this->appendBlockAsync( + $container, + $blob, + $content, + $options + )->wait(); + } + + + /** + * Creates promise to commit a new block of data to the end of an existing append blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param resource|string|StreamInterface $content the blob block contents + * @param Models\AppendBlockOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/append-block + */ + public function appendBlockAsync( + $container, + $blob, + $content, + Models\AppendBlockOptions $options = null + ) { + Validate::canCastAsString($container, 'container'); + Validate::notNullOrEmpty($container, 'container'); + Validate::canCastAsString($blob, 'blob'); + Validate::notNullOrEmpty($blob, 'blob'); + + if (is_null($options)) { + $options = new AppendBlockOptions(); + } + + $method = Resources::HTTP_PUT; + $headers = array(); + $postParams = array(); + $queryParams = array(); + $path = $this->createPath($container, $blob); + $statusCode = Resources::STATUS_CREATED; + + $contentStream = Psr7\stream_for($content); + $length = $contentStream->getSize(); + $body = $contentStream->getContents(); + + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_COMP, + 'appendblock' + ); + + $headers = $this->addOptionalAccessConditionHeader( + $headers, + $options->getAccessConditions() + ); + + $this->addOptionalHeader( + $headers, + Resources::CONTENT_LENGTH, + $length + ); + $this->addOptionalHeader( + $headers, + Resources::CONTENT_MD5, + $options->getContentMD5() + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_CONDITION_MAXSIZE, + $options->getMaxBlobSize() + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_CONDITION_APPENDPOS, + $options->getAppendPosition() + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_LEASE_ID, + $options->getLeaseId() + ); + + $options->setLocationMode(LocationMode::PRIMARY_ONLY); + + return $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $path, + Resources::STATUS_CREATED, + $body, + $options + )->then(function ($response) { + return AppendBlockResult::create( + HttpFormatter::formatHeaders($response->getHeaders()) + ); + }); + } + + /** + * create the header for createBlobBlock(s) + * @param Models\CreateBlobBlockOptions $options the option of the request + * + * @return array + */ + protected function createBlobBlockHeader(Models\CreateBlobBlockOptions $options = null) + { + $headers = array(); + $this->addOptionalHeader( + $headers, + Resources::X_MS_LEASE_ID, + $options->getLeaseId() + ); + $this->addOptionalHeader( + $headers, + Resources::CONTENT_MD5, + $options->getContentMD5() + ); + $this->addOptionalHeader( + $headers, + Resources::CONTENT_TYPE, + Resources::URL_ENCODED_CONTENT_TYPE + ); + + return $headers; + } + + /** + * create the query params for createBlobBlock(s) + * @param Models\CreateBlobBlockOptions $options the option of the + * request + * @param string $blockId the block id of the + * block. + * @param bool $isConcurrent if the query + * parameter is for + * concurrent upload. + * + * @return array the constructed query parameters. + */ + protected function createBlobBlockQueryParams( + Models\CreateBlobBlockOptions $options, + $blockId, + $isConcurrent = false + ) { + $queryParams = array(); + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_COMP, + 'block' + ); + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_BLOCKID, + $blockId + ); + if ($isConcurrent) { + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_TIMEOUT, + $options->getTimeout() + ); + } + + return $queryParams; + } + + /** + * This method writes a blob by specifying the list of block IDs that make up the + * blob. In order to be written as part of a blob, a block must have been + * successfully written to the server in a prior createBlobBlock method. + * + * You can call Put Block List to update a blob by uploading only those blocks + * that have changed, then committing the new and existing blocks together. + * You can do this by specifying whether to commit a block from the committed + * block list or from the uncommitted block list, or to commit the most recently + * uploaded version of the block, whichever list it may belong to. + * + * @param string $container The container name. + * @param string $blob The blob name. + * @param Models\BlockList|Block[] $blockList The block entries. + * @param Models\CommitBlobBlocksOptions $options The optional parameters. + * + * @return Models\PutBlobResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179467.aspx + */ + public function commitBlobBlocks( + $container, + $blob, + $blockList, + Models\CommitBlobBlocksOptions $options = null + ) { + return $this->commitBlobBlocksAsync( + $container, + $blob, + $blockList, + $options + )->wait(); + } + + /** + * This method writes a blob by specifying the list of block IDs that make up the + * blob. In order to be written as part of a blob, a block must have been + * successfully written to the server in a prior createBlobBlock method. + * + * You can call Put Block List to update a blob by uploading only those blocks + * that have changed, then committing the new and existing blocks together. + * You can do this by specifying whether to commit a block from the committed + * block list or from the uncommitted block list, or to commit the most recently + * uploaded version of the block, whichever list it may belong to. + * + * @param string $container The container name. + * @param string $blob The blob name. + * @param Models\BlockList|Block[] $blockList The block entries. + * @param Models\CommitBlobBlocksOptions $options The optional parameters. + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179467.aspx + */ + public function commitBlobBlocksAsync( + $container, + $blob, + $blockList, + Models\CommitBlobBlocksOptions $options = null + ) { + Validate::canCastAsString($container, 'container'); + Validate::canCastAsString($blob, 'blob'); + Validate::notNullOrEmpty($blob, 'blob'); + Validate::isTrue( + $blockList instanceof BlockList || is_array($blockList), + sprintf( + Resources::INVALID_PARAM_MSG, + 'blockList', + get_class(new BlockList()) + ) + ); + + $method = Resources::HTTP_PUT; + $headers = array(); + $postParams = array(); + $queryParams = array(); + $path = $this->createPath($container, $blob); + $isArray = is_array($blockList); + $blockList = $isArray ? BlockList::create($blockList) : $blockList; + $body = $blockList->toXml($this->dataSerializer); + + if (is_null($options)) { + $options = new CommitBlobBlocksOptions(); + } + + $blobContentType = $options->getContentType(); + $blobContentEncoding = $options->getContentEncoding(); + $blobContentLanguage = $options->getContentLanguage(); + $blobContentMD5 = $options->getContentMD5(); + $blobCacheControl = $options->getCacheControl(); + $blobCcontentDisposition = $options->getContentDisposition(); + $leaseId = $options->getLeaseId(); + $contentType = Resources::URL_ENCODED_CONTENT_TYPE; + + $metadata = $options->getMetadata(); + $headers = $this->generateMetadataHeaders($metadata); + $headers = $this->addOptionalAccessConditionHeader( + $headers, + $options->getAccessConditions() + ); + + $this->addOptionalHeader( + $headers, + Resources::X_MS_LEASE_ID, + $leaseId + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_CACHE_CONTROL, + $blobCacheControl + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_CONTENT_DISPOSITION, + $blobCcontentDisposition + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_CONTENT_TYPE, + $blobContentType + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_CONTENT_ENCODING, + $blobContentEncoding + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_CONTENT_LANGUAGE, + $blobContentLanguage + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_CONTENT_MD5, + $blobContentMD5 + ); + $this->addOptionalHeader( + $headers, + Resources::CONTENT_TYPE, + $contentType + ); + + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_COMP, + 'blocklist' + ); + + $options->setLocationMode(LocationMode::PRIMARY_ONLY); + + return $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $path, + Resources::STATUS_CREATED, + $body, + $options + )->then(function ($response) { + return PutBlobResult::create( + HttpFormatter::formatHeaders($response->getHeaders()) + ); + }, null); + } + + /** + * Retrieves the list of blocks that have been uploaded as part of a block blob. + * + * There are two block lists maintained for a blob: + * 1) Committed Block List: The list of blocks that have been successfully + * committed to a given blob with commitBlobBlocks. + * 2) Uncommitted Block List: The list of blocks that have been uploaded for a + * blob using Put Block (REST API), but that have not yet been committed. + * These blocks are stored in Windows Azure in association with a blob, but do + * not yet form part of the blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param Models\ListBlobBlocksOptions $options optional parameters + * + * @return Models\ListBlobBlocksResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179400.aspx + */ + public function listBlobBlocks( + $container, + $blob, + Models\ListBlobBlocksOptions $options = null + ) { + return $this->listBlobBlocksAsync($container, $blob, $options)->wait(); + } + + /** + * Creates promise to retrieve the list of blocks that have been uploaded as + * part of a block blob. + * + * There are two block lists maintained for a blob: + * 1) Committed Block List: The list of blocks that have been successfully + * committed to a given blob with commitBlobBlocks. + * 2) Uncommitted Block List: The list of blocks that have been uploaded for a + * blob using Put Block (REST API), but that have not yet been committed. + * These blocks are stored in Windows Azure in association with a blob, but do + * not yet form part of the blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param Models\ListBlobBlocksOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179400.aspx + */ + public function listBlobBlocksAsync( + $container, + $blob, + Models\ListBlobBlocksOptions $options = null + ) { + Validate::canCastAsString($container, 'container'); + Validate::canCastAsString($blob, 'blob'); + Validate::notNullOrEmpty($blob, 'blob'); + + $method = Resources::HTTP_GET; + $headers = array(); + $postParams = array(); + $queryParams = array(); + $path = $this->createPath($container, $blob); + + if (is_null($options)) { + $options = new ListBlobBlocksOptions(); + } + + $this->addOptionalHeader( + $headers, + Resources::X_MS_LEASE_ID, + $options->getLeaseId() + ); + + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_BLOCK_LIST_TYPE, + $options->getBlockListType() + ); + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_SNAPSHOT, + $options->getSnapshot() + ); + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_COMP, + 'blocklist' + ); + + return $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $path, + Resources::STATUS_OK, + Resources::EMPTY_STRING, + $options + )->then(function ($response) { + $parsed = $this->dataSerializer->unserialize($response->getBody()); + + return ListBlobBlocksResult::create( + HttpFormatter::formatHeaders($response->getHeaders()), + $parsed + ); + }, null); + } + + /** + * Returns all properties and metadata on the blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param Models\GetBlobPropertiesOptions $options optional parameters + * + * @return Models\GetBlobPropertiesResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179394.aspx + */ + public function getBlobProperties( + $container, + $blob, + Models\GetBlobPropertiesOptions $options = null + ) { + return $this->getBlobPropertiesAsync( + $container, + $blob, + $options + )->wait(); + } + + /** + * Creates promise to return all properties and metadata on the blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param Models\GetBlobPropertiesOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179394.aspx + */ + public function getBlobPropertiesAsync( + $container, + $blob, + Models\GetBlobPropertiesOptions $options = null + ) { + Validate::canCastAsString($container, 'container'); + Validate::canCastAsString($blob, 'blob'); + Validate::notNullOrEmpty($blob, 'blob'); + + $method = Resources::HTTP_HEAD; + $headers = array(); + $postParams = array(); + $queryParams = array(); + $path = $this->createPath($container, $blob); + + if (is_null($options)) { + $options = new GetBlobPropertiesOptions(); + } + + $headers = $this->addOptionalAccessConditionHeader( + $headers, + $options->getAccessConditions() + ); + + $this->addOptionalHeader( + $headers, + Resources::X_MS_LEASE_ID, + $options->getLeaseId() + ); + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_SNAPSHOT, + $options->getSnapshot() + ); + + return $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $path, + Resources::STATUS_OK, + Resources::EMPTY_STRING, + $options + )->then(function ($response) { + $formattedHeaders = HttpFormatter::formatHeaders($response->getHeaders()); + return GetBlobPropertiesResult::create($formattedHeaders); + }, null); + } + + /** + * Returns all properties and metadata on the blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param Models\GetBlobMetadataOptions $options optional parameters + * + * @return Models\GetBlobMetadataResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179350.aspx + */ + public function getBlobMetadata( + $container, + $blob, + Models\GetBlobMetadataOptions $options = null + ) { + return $this->getBlobMetadataAsync($container, $blob, $options)->wait(); + } + + /** + * Creates promise to return all properties and metadata on the blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param Models\GetBlobMetadataOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179350.aspx + */ + public function getBlobMetadataAsync( + $container, + $blob, + Models\GetBlobMetadataOptions $options = null + ) { + Validate::canCastAsString($container, 'container'); + Validate::canCastAsString($blob, 'blob'); + Validate::notNullOrEmpty($blob, 'blob'); + + $method = Resources::HTTP_HEAD; + $headers = array(); + $postParams = array(); + $queryParams = array(); + $path = $this->createPath($container, $blob); + + if (is_null($options)) { + $options = new GetBlobMetadataOptions(); + } + + $headers = $this->addOptionalAccessConditionHeader( + $headers, + $options->getAccessConditions() + ); + + $this->addOptionalHeader( + $headers, + Resources::X_MS_LEASE_ID, + $options->getLeaseId() + ); + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_SNAPSHOT, + $options->getSnapshot() + ); + + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_COMP, + 'metadata' + ); + + return $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $path, + Resources::STATUS_OK, + Resources::EMPTY_STRING, + $options + )->then(function ($response) { + $responseHeaders = HttpFormatter::formatHeaders($response->getHeaders()); + return GetBlobMetadataResult::create($responseHeaders); + }); + } + + /** + * Returns a list of active page ranges for a page blob. Active page ranges are + * those that have been populated with data. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param Models\ListPageBlobRangesOptions $options optional parameters + * + * @return Models\ListPageBlobRangesResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691973.aspx + */ + public function listPageBlobRanges( + $container, + $blob, + Models\ListPageBlobRangesOptions $options = null + ) { + return $this->listPageBlobRangesAsync( + $container, + $blob, + $options + )->wait(); + } + + /** + * Creates promise to return a list of active page ranges for a page blob. + * Active page ranges are those that have been populated with data. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param Models\ListPageBlobRangesOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691973.aspx + */ + public function listPageBlobRangesAsync( + $container, + $blob, + Models\ListPageBlobRangesOptions $options = null + ) { + return $this->listPageBlobRangesAsyncImpl($container, $blob, null, $options); + } + + /** + * Returns a list of page ranges that have been updated or cleared. + * + * Returns a list of page ranges that have been updated or cleared since + * the snapshot specified by `previousSnapshotTime`. Gets all of the page + * ranges by default, or only the page ranges over a specific range of + * bytes if `rangeStart` and `rangeEnd` in the `options` are specified. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $previousSnapshotTime previous snapshot time + * for comparison which + * should be prior to the + * snapshot time defined + * in `options` + * @param Models\ListPageBlobRangesOptions $options optional parameters + * + * @return Models\ListPageBlobRangesDiffResult + * + * @see https://docs.microsoft.com/en-us/rest/api/storageservices/version-2015-07-08 + */ + public function listPageBlobRangesDiff( + $container, + $blob, + $previousSnapshotTime, + Models\ListPageBlobRangesOptions $options = null + ) { + return $this->listPageBlobRangesDiffAsync( + $container, + $blob, + $previousSnapshotTime, + $options + )->wait(); + } + + /** + * Creates promise to return a list of page ranges that have been updated + * or cleared. + * + * Creates promise to return a list of page ranges that have been updated + * or cleared since the snapshot specified by `previousSnapshotTime`. Gets + * all of the page ranges by default, or only the page ranges over a specific + * range of bytes if `rangeStart` and `rangeEnd` in the `options` are specified. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $previousSnapshotTime previous snapshot time + * for comparison which + * should be prior to the + * snapshot time defined + * in `options` + * @param Models\ListPageBlobRangesOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691973.aspx + */ + public function listPageBlobRangesDiffAsync( + $container, + $blob, + $previousSnapshotTime, + Models\ListPageBlobRangesOptions $options = null + ) { + return $this->listPageBlobRangesAsyncImpl( + $container, + $blob, + $previousSnapshotTime, + $options + ); + } + + /** + * Creates promise to return a list of page ranges. + + * If `previousSnapshotTime` is specified, the response will include + * only the pages that differ between the target snapshot or blob and + * the previous snapshot. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $previousSnapshotTime previous snapshot time + * for comparison which + * should be prior to the + * snapshot time defined + * in `options` + * @param Models\ListPageBlobRangesOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691973.aspx + */ + private function listPageBlobRangesAsyncImpl( + $container, + $blob, + $previousSnapshotTime = null, + Models\ListPageBlobRangesOptions $options = null + ) { + Validate::canCastAsString($container, 'container'); + Validate::canCastAsString($blob, 'blob'); + Validate::notNullOrEmpty($blob, 'blob'); + + $method = Resources::HTTP_GET; + $headers = array(); + $queryParams = array(); + $postParams = array(); + $path = $this->createPath($container, $blob); + + if (is_null($options)) { + $options = new ListPageBlobRangesOptions(); + } + + $headers = $this->addOptionalAccessConditionHeader( + $headers, + $options->getAccessConditions() + ); + + $range = $options->getRange(); + if ($range) { + $headers = $this->addOptionalRangeHeader( + $headers, + $range->getStart(), + $range->getEnd() + ); + } + + $this->addOptionalHeader( + $headers, + Resources::X_MS_LEASE_ID, + $options->getLeaseId() + ); + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_SNAPSHOT, + $options->getSnapshot() + ); + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_COMP, + 'pagelist' + ); + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_PRE_SNAPSHOT, + $previousSnapshotTime + ); + + $dataSerializer = $this->dataSerializer; + + return $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $path, + Resources::STATUS_OK, + Resources::EMPTY_STRING, + $options + )->then(function ($response) use ($dataSerializer, $previousSnapshotTime) { + $parsed = $dataSerializer->unserialize($response->getBody()); + if (is_null($previousSnapshotTime)) { + return ListPageBlobRangesResult::create( + HttpFormatter::formatHeaders($response->getHeaders()), + $parsed + ); + } else { + return ListPageBlobRangesDiffResult::create( + HttpFormatter::formatHeaders($response->getHeaders()), + $parsed + ); + } + }, null); + } + + /** + * Sets system properties defined for a blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param Models\SetBlobPropertiesOptions $options optional parameters + * + * @return Models\SetBlobPropertiesResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691966.aspx + */ + public function setBlobProperties( + $container, + $blob, + Models\SetBlobPropertiesOptions $options = null + ) { + return $this->setBlobPropertiesAsync( + $container, + $blob, + $options + )->wait(); + } + + /** + * Creates promise to set system properties defined for a blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param Models\SetBlobPropertiesOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691966.aspx + */ + public function setBlobPropertiesAsync( + $container, + $blob, + Models\SetBlobPropertiesOptions $options = null + ) { + Validate::canCastAsString($container, 'container'); + Validate::canCastAsString($blob, 'blob'); + Validate::notNullOrEmpty($blob, 'blob'); + + $method = Resources::HTTP_PUT; + $headers = array(); + $postParams = array(); + $queryParams = array(); + $path = $this->createPath($container, $blob); + + if (is_null($options)) { + $options = new SetBlobPropertiesOptions(); + } + + $blobContentType = $options->getContentType(); + $blobContentEncoding = $options->getContentEncoding(); + $blobContentLanguage = $options->getContentLanguage(); + $blobContentLength = $options->getContentLength(); + $blobContentMD5 = $options->getContentMD5(); + $blobCacheControl = $options->getCacheControl(); + $blobContentDisposition = $options->getContentDisposition(); + $leaseId = $options->getLeaseId(); + $sNumberAction = $options->getSequenceNumberAction(); + $sNumber = $options->getSequenceNumber(); + + $headers = $this->addOptionalAccessConditionHeader( + $headers, + $options->getAccessConditions() + ); + + $this->addOptionalHeader( + $headers, + Resources::X_MS_LEASE_ID, + $leaseId + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_CACHE_CONTROL, + $blobCacheControl + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_CONTENT_DISPOSITION, + $blobContentDisposition + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_CONTENT_TYPE, + $blobContentType + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_CONTENT_ENCODING, + $blobContentEncoding + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_CONTENT_LANGUAGE, + $blobContentLanguage + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_CONTENT_LENGTH, + $blobContentLength + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_CONTENT_MD5, + $blobContentMD5 + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_SEQUENCE_NUMBER_ACTION, + $sNumberAction + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_BLOB_SEQUENCE_NUMBER, + $sNumber + ); + + $this->addOptionalQueryParam($queryParams, Resources::QP_COMP, 'properties'); + + $options->setLocationMode(LocationMode::PRIMARY_ONLY); + + return $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $path, + Resources::STATUS_OK, + Resources::EMPTY_STRING, + $options + )->then(function ($response) { + return SetBlobPropertiesResult::create( + HttpFormatter::formatHeaders($response->getHeaders()) + ); + }, null); + } + + /** + * Sets metadata headers on the blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param array $metadata key/value pair representation + * @param Models\BlobServiceOptions $options optional parameters + * + * @return Models\SetBlobMetadataResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179414.aspx + */ + public function setBlobMetadata( + $container, + $blob, + array $metadata, + Models\BlobServiceOptions $options = null + ) { + return $this->setBlobMetadataAsync( + $container, + $blob, + $metadata, + $options + )->wait(); + } + + /** + * Creates promise to set metadata headers on the blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param array $metadata key/value pair representation + * @param Models\BlobServiceOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179414.aspx + */ + public function setBlobMetadataAsync( + $container, + $blob, + array $metadata, + Models\BlobServiceOptions $options = null + ) { + Validate::canCastAsString($container, 'container'); + Validate::canCastAsString($blob, 'blob'); + Validate::notNullOrEmpty($blob, 'blob'); + Utilities::validateMetadata($metadata); + + $method = Resources::HTTP_PUT; + $headers = array(); + $postParams = array(); + $queryParams = array(); + $path = $this->createPath($container, $blob); + + if (is_null($options)) { + $options = new BlobServiceOptions(); + } + + $headers = $this->addOptionalAccessConditionHeader( + $headers, + $options->getAccessConditions() + ); + $headers = $this->addMetadataHeaders($headers, $metadata); + + $this->addOptionalHeader( + $headers, + Resources::X_MS_LEASE_ID, + $options->getLeaseId() + ); + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_COMP, + 'metadata' + ); + + $options->setLocationMode(LocationMode::PRIMARY_ONLY); + + return $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $path, + Resources::STATUS_OK, + Resources::EMPTY_STRING, + $options + )->then(function ($response) { + return SetBlobMetadataResult::create( + HttpFormatter::formatHeaders($response->getHeaders()) + ); + }, null); + } + + /** + * Downloads a blob to a file, the result contains its metadata and + * properties. The result will not contain a stream pointing to the + * content of the file. + * + * @param string $path The path and name of the file + * @param string $container name of the container + * @param string $blob name of the blob + * @param Models\GetBlobOptions $options optional parameters + * + * @return Models\GetBlobResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179440.aspx + */ + public function saveBlobToFile( + $path, + $container, + $blob, + Models\GetBlobOptions $options = null + ) { + return $this->saveBlobToFileAsync( + $path, + $container, + $blob, + $options + )->wait(); + } + + /** + * Creates promise to download a blob to a file, the result contains its + * metadata and properties. The result will not contain a stream pointing + * to the content of the file. + * + * @param string $path The path and name of the file + * @param string $container name of the container + * @param string $blob name of the blob + * @param Models\GetBlobOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179440.aspx + */ + public function saveBlobToFileAsync( + $path, + $container, + $blob, + Models\GetBlobOptions $options = null + ) { + $resource = fopen($path, 'w+'); + if ($resource == null) { + throw new \Exception(Resources::ERROR_FILE_COULD_NOT_BE_OPENED); + } + return $this->getBlobAsync($container, $blob, $options)->then( + function ($result) use ($path, $resource) { + $content = $result->getContentStream(); + while (!feof($content)) { + fwrite( + $resource, + stream_get_contents($content, Resources::MB_IN_BYTES_4) + ); + } + + $content = null; + fclose($resource); + + return $result; + }, + null + ); + } + + /** + * Reads or downloads a blob from the system, including its metadata and + * properties. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param Models\GetBlobOptions $options optional parameters + * + * @return Models\GetBlobResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179440.aspx + */ + public function getBlob( + $container, + $blob, + Models\GetBlobOptions $options = null + ) { + return $this->getBlobAsync($container, $blob, $options)->wait(); + } + + /** + * Creates promise to read or download a blob from the system, including its + * metadata and properties. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param Models\GetBlobOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179440.aspx + */ + public function getBlobAsync( + $container, + $blob, + Models\GetBlobOptions $options = null + ) { + Validate::canCastAsString($container, 'container'); + Validate::canCastAsString($blob, 'blob'); + + $method = Resources::HTTP_GET; + $headers = array(); + $postParams = array(); + $queryParams = array(); + $path = $this->createPath($container, $blob); + + if (is_null($options)) { + $options = new GetBlobOptions(); + } + + $getMD5 = $options->getRangeGetContentMD5(); + $headers = $this->addOptionalAccessConditionHeader( + $headers, + $options->getAccessConditions() + ); + + $range = $options->getRange(); + if ($range) { + $headers = $this->addOptionalRangeHeader( + $headers, + $range->getStart(), + $range->getEnd() + ); + } + + $this->addOptionalHeader( + $headers, + Resources::X_MS_LEASE_ID, + $options->getLeaseId() + ); + $this->addOptionalHeader( + $headers, + Resources::X_MS_RANGE_GET_CONTENT_MD5, + $getMD5 ? 'true' : null + ); + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_SNAPSHOT, + $options->getSnapshot() + ); + + $options->setIsStreaming(true); + + return $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $path, + array(Resources::STATUS_OK, Resources::STATUS_PARTIAL_CONTENT), + Resources::EMPTY_STRING, + $options + )->then(function ($response) { + $metadata = Utilities::getMetadataArray( + HttpFormatter::formatHeaders($response->getHeaders()) + ); + + return GetBlobResult::create( + HttpFormatter::formatHeaders($response->getHeaders()), + $response->getBody(), + $metadata + ); + }); + } + + /** + * Deletes a blob or blob snapshot. + * + * Note that if the snapshot entry is specified in the $options then only this + * blob snapshot is deleted. To delete all blob snapshots, do not set Snapshot + * and just set getDeleteSnaphotsOnly to true. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param Models\DeleteBlobOptions $options optional parameters + * + * @return void + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179413.aspx + */ + public function deleteBlob( + $container, + $blob, + Models\DeleteBlobOptions $options = null + ) { + $this->deleteBlobAsync($container, $blob, $options)->wait(); + } + + /** + * Creates promise to delete a blob or blob snapshot. + * + * Note that if the snapshot entry is specified in the $options then only this + * blob snapshot is deleted. To delete all blob snapshots, do not set Snapshot + * and just set getDeleteSnaphotsOnly to true. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param Models\DeleteBlobOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179413.aspx + */ + public function deleteBlobAsync( + $container, + $blob, + Models\DeleteBlobOptions $options = null + ) { + Validate::canCastAsString($container, 'container'); + Validate::canCastAsString($blob, 'blob'); + Validate::notNullOrEmpty($blob, 'blob'); + + $method = Resources::HTTP_DELETE; + $headers = array(); + $postParams = array(); + $queryParams = array(); + $path = $this->createPath($container, $blob); + + if (is_null($options)) { + $options = new DeleteBlobOptions(); + } + + if (is_null($options->getSnapshot())) { + $delSnapshots = $options->getDeleteSnaphotsOnly() ? 'only' : 'include'; + $this->addOptionalHeader( + $headers, + Resources::X_MS_DELETE_SNAPSHOTS, + $delSnapshots + ); + } else { + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_SNAPSHOT, + $options->getSnapshot() + ); + } + + $headers = $this->addOptionalAccessConditionHeader( + $headers, + $options->getAccessConditions() + ); + + $this->addOptionalHeader( + $headers, + Resources::X_MS_LEASE_ID, + $options->getLeaseId() + ); + + $options->setLocationMode(LocationMode::PRIMARY_ONLY); + + return $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $path, + Resources::STATUS_ACCEPTED, + Resources::EMPTY_STRING, + $options + ); + } + + /** + * Creates a snapshot of a blob. + * + * @param string $container The name of the container. + * @param string $blob The name of the blob. + * @param Models\CreateBlobSnapshotOptions $options The optional parameters. + * + * @return Models\CreateBlobSnapshotResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691971.aspx + */ + public function createBlobSnapshot( + $container, + $blob, + Models\CreateBlobSnapshotOptions $options = null + ) { + return $this->createBlobSnapshotAsync( + $container, + $blob, + $options + )->wait(); + } + + /** + * Creates promise to create a snapshot of a blob. + * + * @param string $container The name of the container. + * @param string $blob The name of the blob. + * @param Models\CreateBlobSnapshotOptions $options The optional parameters. + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691971.aspx + */ + public function createBlobSnapshotAsync( + $container, + $blob, + Models\CreateBlobSnapshotOptions $options = null + ) { + Validate::canCastAsString($container, 'container'); + Validate::canCastAsString($blob, 'blob'); + Validate::notNullOrEmpty($blob, 'blob'); + + $method = Resources::HTTP_PUT; + $headers = array(); + $postParams = array(); + $queryParams = array(); + $path = $this->createPath($container, $blob); + + if (is_null($options)) { + $options = new CreateBlobSnapshotOptions(); + } + + $queryParams[Resources::QP_COMP] = 'snapshot'; + + $headers = $this->addOptionalAccessConditionHeader( + $headers, + $options->getAccessConditions() + ); + $headers = $this->addMetadataHeaders($headers, $options->getMetadata()); + $this->addOptionalHeader( + $headers, + Resources::X_MS_LEASE_ID, + $options->getLeaseId() + ); + + $options->setLocationMode(LocationMode::PRIMARY_ONLY); + + return $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $path, + Resources::STATUS_CREATED, + Resources::EMPTY_STRING, + $options + )->then(function ($response) { + return CreateBlobSnapshotResult::create( + HttpFormatter::formatHeaders($response->getHeaders()) + ); + }, null); + } + + /** + * Copies a source blob to a destination blob within the same storage account. + * + * @param string $destinationContainer name of the destination + * container + * @param string $destinationBlob name of the destination + * blob + * @param string $sourceContainer name of the source + * container + * @param string $sourceBlob name of the source + * blob + * @param Models\CopyBlobOptions $options optional parameters + * + * @return Models\CopyBlobResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd894037.aspx + */ + public function copyBlob( + $destinationContainer, + $destinationBlob, + $sourceContainer, + $sourceBlob, + Models\CopyBlobOptions $options = null + ) { + return $this->copyBlobAsync( + $destinationContainer, + $destinationBlob, + $sourceContainer, + $sourceBlob, + $options + )->wait(); + } + + /** + * Creates promise to copy a source blob to a destination blob within the + * same storage account. + * + * @param string $destinationContainer name of the destination + * container + * @param string $destinationBlob name of the destination + * blob + * @param string $sourceContainer name of the source + * container + * @param string $sourceBlob name of the source + * blob + * @param Models\CopyBlobOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd894037.aspx + */ + public function copyBlobAsync( + $destinationContainer, + $destinationBlob, + $sourceContainer, + $sourceBlob, + Models\CopyBlobOptions $options = null + ) { + if (is_null($options)) { + $options = new CopyBlobOptions(); + } + + $sourceBlobPath = $this->getCopyBlobSourceName( + $sourceContainer, + $sourceBlob, + $options + ); + + return $this->copyBlobFromURLAsync( + $destinationContainer, + $destinationBlob, + $sourceBlobPath, + $options + ); + } + + /** + * Copies from a source URL to a destination blob. + * + * @param string $destinationContainer name of the + * destination + * container + * @param string $destinationBlob name of the + * destination + * blob + * @param string $sourceURL URL of the + * source + * resource + * @param Models\CopyBlobFromURLOptions $options optional + * parameters + * + * @return Models\CopyBlobResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd894037.aspx + */ + public function copyBlobFromURL( + $destinationContainer, + $destinationBlob, + $sourceURL, + Models\CopyBlobFromURLOptions $options = null + ) { + return $this->copyBlobFromURLAsync( + $destinationContainer, + $destinationBlob, + $sourceURL, + $options + )->wait(); + } + + /** + * Creates promise to copy from source URL to a destination blob. + * + * @param string $destinationContainer name of the + * destination + * container + * @param string $destinationBlob name of the + * destination + * blob + * @param string $sourceURL URL of the + * source + * resource + * @param Models\CopyBlobFromURLOptions $options optional + * parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd894037.aspx + */ + public function copyBlobFromURLAsync( + $destinationContainer, + $destinationBlob, + $sourceURL, + Models\CopyBlobFromURLOptions $options = null + ) { + $method = Resources::HTTP_PUT; + $headers = array(); + $postParams = array(); + $queryParams = array(); + $destinationBlobPath = $this->createPath( + $destinationContainer, + $destinationBlob + ); + + if (is_null($options)) { + $options = new CopyBlobFromURLOptions(); + } + + if ($options->getIsIncrementalCopy()) { + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_COMP, + 'incrementalcopy' + ); + } + + $headers = $this->addOptionalAccessConditionHeader( + $headers, + $options->getAccessConditions() + ); + + $headers = $this->addOptionalSourceAccessConditionHeader( + $headers, + $options->getSourceAccessConditions() + ); + + $this->addOptionalHeader( + $headers, + Resources::X_MS_COPY_SOURCE, + $sourceURL + ); + + $headers = $this->addMetadataHeaders($headers, $options->getMetadata()); + + $this->addOptionalHeader( + $headers, + Resources::X_MS_LEASE_ID, + $options->getLeaseId() + ); + + $this->addOptionalHeader( + $headers, + Resources::X_MS_SOURCE_LEASE_ID, + $options->getSourceLeaseId() + ); + + $options->setLocationMode(LocationMode::PRIMARY_ONLY); + + return $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $destinationBlobPath, + Resources::STATUS_ACCEPTED, + Resources::EMPTY_STRING, + $options + )->then(function ($response) { + return CopyBlobResult::create( + HttpFormatter::formatHeaders($response->getHeaders()) + ); + }, null); + } + + /** + * Abort a blob copy operation + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $copyId copy operation identifier. + * @param Models\BlobServiceOptions $options optional parameters + * + * @return void + * + * @see https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/abort-copy-blob + */ + public function abortCopy( + $container, + $blob, + $copyId, + Models\BlobServiceOptions $options = null + ) { + return $this->abortCopyAsync( + $container, + $blob, + $copyId, + $options + )->wait(); + } + + /** + * Creates promise to abort a blob copy operation + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $copyId copy operation identifier. + * @param Models\BlobServiceOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/abort-copy-blob + */ + public function abortCopyAsync( + $container, + $blob, + $copyId, + Models\BlobServiceOptions $options = null + ) { + Validate::canCastAsString($container, 'container'); + Validate::canCastAsString($blob, 'blob'); + Validate::canCastAsString($copyId, 'copyId'); + Validate::notNullOrEmpty($container, 'container'); + Validate::notNullOrEmpty($blob, 'blob'); + Validate::notNullOrEmpty($copyId, 'copyId'); + + $method = Resources::HTTP_PUT; + $headers = array(); + $postParams = array(); + $queryParams = array(); + $destinationBlobPath = $this->createPath( + $container, + $blob + ); + + if (is_null($options)) { + $options = new BlobServiceOptions(); + } + + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_TIMEOUT, + $options->getTimeout() + ); + + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_COMP, + 'copy' + ); + + $this->addOptionalQueryParam( + $queryParams, + Resources::QP_COPY_ID, + $copyId + ); + + $this->addOptionalHeader( + $headers, + Resources::X_MS_LEASE_ID, + $options->getLeaseId() + ); + + $this->addOptionalHeader( + $headers, + Resources::X_MS_COPY_ACTION, + 'abort' + ); + + return $this->sendAsync( + $method, + $headers, + $queryParams, + $postParams, + $destinationBlobPath, + Resources::STATUS_NO_CONTENT, + Resources::EMPTY_STRING, + $options + ); + } + + /** + * Establishes an exclusive write lock on a blob. To write to a locked + * blob, a client must provide a lease ID. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $proposedLeaseId lease id when acquiring + * @param int $leaseDuration the lease duration. + * A non-infinite + * lease can be between + * 15 and 60 seconds. + * Default is never + * to expire. + * @param Models\BlobServiceOptions $options optional parameters + * + * @return Models\LeaseResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691972.aspx + */ + public function acquireLease( + $container, + $blob, + $proposedLeaseId = null, + $leaseDuration = null, + Models\BlobServiceOptions $options = null + ) { + return $this->acquireLeaseAsync( + $container, + $blob, + $proposedLeaseId, + $leaseDuration, + $options + )->wait(); + } + + /** + * Creates promise to establish an exclusive one-minute write lock on a blob. + * To write to a locked blob, a client must provide a lease ID. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $proposedLeaseId lease id when acquiring + * @param int $leaseDuration the lease duration. + * A non-infinite + * lease can be between + * 15 and 60 seconds. + * Default is never to + * expire. + * @param Models\BlobServiceOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691972.aspx + */ + public function acquireLeaseAsync( + $container, + $blob, + $proposedLeaseId = null, + $leaseDuration = null, + Models\BlobServiceOptions $options = null + ) { + if ($options === null) { + $options = new BlobServiceOptions(); + } + + if ($leaseDuration === null) { + $leaseDuration = -1; + } + + return $this->putLeaseAsyncImpl( + LeaseMode::ACQUIRE_ACTION, + $container, + $blob, + $proposedLeaseId, + $leaseDuration, + null /* leaseId */, + null /* breakPeriod */, + self::getStatusCodeOfLeaseAction(LeaseMode::ACQUIRE_ACTION), + $options, + $options->getAccessConditions() + )->then(function ($response) { + return LeaseResult::create( + HttpFormatter::formatHeaders($response->getHeaders()) + ); + }, null); + } + + /** + * change an existing lease + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $leaseId lease id when acquiring + * @param string $proposedLeaseId lease id when acquiring + * @param Models\BlobServiceOptions $options optional parameters + * + * @return Models\LeaseResult + * + * @see https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/lease-blob + */ + public function changeLease( + $container, + $blob, + $leaseId, + $proposedLeaseId, + Models\BlobServiceOptions $options = null + ) { + return $this->changeLeaseAsync( + $container, + $blob, + $leaseId, + $proposedLeaseId, + $options + )->wait(); + } + + /** + * Creates promise to change an existing lease + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $leaseId lease id when acquiring + * @param string $proposedLeaseId the proposed lease id + * @param Models\BlobServiceOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/lease-blob + */ + public function changeLeaseAsync( + $container, + $blob, + $leaseId, + $proposedLeaseId, + Models\BlobServiceOptions $options = null + ) { + return $this->putLeaseAsyncImpl( + LeaseMode::CHANGE_ACTION, + $container, + $blob, + $proposedLeaseId, + null /* leaseDuration */, + $leaseId, + null /* breakPeriod */, + self::getStatusCodeOfLeaseAction(LeaseMode::RENEW_ACTION), + is_null($options) ? new BlobServiceOptions() : $options + )->then(function ($response) { + return LeaseResult::create( + HttpFormatter::formatHeaders($response->getHeaders()) + ); + }, null); + } + + /** + * Renews an existing lease + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $leaseId lease id when acquiring + * @param Models\BlobServiceOptions $options optional parameters + * + * @return Models\LeaseResult + * + * @see https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/lease-blob + */ + public function renewLease( + $container, + $blob, + $leaseId, + Models\BlobServiceOptions $options = null + ) { + return $this->renewLeaseAsync( + $container, + $blob, + $leaseId, + $options + )->wait(); + } + + /** + * Creates promise to renew an existing lease + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $leaseId lease id when acquiring + * @param Models\BlobServiceOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/lease-blob + */ + public function renewLeaseAsync( + $container, + $blob, + $leaseId, + Models\BlobServiceOptions $options = null + ) { + return $this->putLeaseAsyncImpl( + LeaseMode::RENEW_ACTION, + $container, + $blob, + null /* proposedLeaseId */, + null /* leaseDuration */, + $leaseId, + null /* breakPeriod */, + self::getStatusCodeOfLeaseAction(LeaseMode::RENEW_ACTION), + is_null($options) ? new BlobServiceOptions() : $options + )->then(function ($response) { + return LeaseResult::create( + HttpFormatter::formatHeaders($response->getHeaders()) + ); + }, null); + } + + /** + * Frees the lease if it is no longer needed so that another client may + * immediately acquire a lease against the blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $leaseId lease id when acquiring + * @param Models\BlobServiceOptions $options optional parameters + * + * @return void + * + * @see https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/lease-blob + */ + public function releaseLease( + $container, + $blob, + $leaseId, + Models\BlobServiceOptions $options = null + ) { + $this->releaseLeaseAsync($container, $blob, $leaseId, $options)->wait(); + } + + /** + * Creates promise to free the lease if it is no longer needed so that + * another client may immediately acquire a lease against the blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $leaseId lease id when acquiring + * @param Models\BlobServiceOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/lease-blob + */ + public function releaseLeaseAsync( + $container, + $blob, + $leaseId, + Models\BlobServiceOptions $options = null + ) { + return $this->putLeaseAsyncImpl( + LeaseMode::RELEASE_ACTION, + $container, + $blob, + null /* proposedLeaseId */, + null /* leaseDuration */, + $leaseId, + null /* breakPeriod */, + self::getStatusCodeOfLeaseAction(LeaseMode::RELEASE_ACTION), + is_null($options) ? new BlobServiceOptions() : $options + ); + } + + /** + * Ends the lease but ensure that another client cannot acquire a new lease until + * the current lease period has expired. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param int $breakPeriod the proposed duration of seconds that + * lease should continue before it it broken, + * between 0 and 60 seconds. + * @param Models\BlobServiceOptions $options optional parameters + * + * @return BreakLeaseResult + * + * @see https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/lease-blob + */ + public function breakLease( + $container, + $blob, + $breakPeriod = null, + Models\BlobServiceOptions $options = null + ) { + return $this->breakLeaseAsync( + $container, + $blob, + $breakPeriod, + $options + )->wait(); + } + + /** + * Creates promise to end the lease but ensure that another client cannot + * acquire a new lease until the current lease period has expired. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param int $breakPeriod break period, in seconds + * @param Models\BlobServiceOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/lease-blob + */ + public function breakLeaseAsync( + $container, + $blob, + $breakPeriod = null, + Models\BlobServiceOptions $options = null + ) { + return $this->putLeaseAsyncImpl( + LeaseMode::BREAK_ACTION, + $container, + $blob, + null /* proposedLeaseId */, + null /* leaseDuration */, + null /* leaseId */, + $breakPeriod, + self::getStatusCodeOfLeaseAction(LeaseMode::BREAK_ACTION), + is_null($options) ? new BlobServiceOptions() : $options + )->then(function ($response) { + return BreakLeaseResult::create( + HttpFormatter::formatHeaders($response->getHeaders()) + ); + }, null); + } + + /** + * Adds optional header to headers if set + * + * @param array $headers The array of request headers. + * @param Models\AccessCondition $accessCondition The access condition object. + * + * @return array + */ + public function addOptionalAccessConditionHeader( + array $headers, + array $accessConditions = null + ) { + if (!empty($accessConditions)) { + foreach ($accessConditions as $accessCondition) { + if (!is_null($accessCondition)) { + $header = $accessCondition->getHeader(); + + if ($header != Resources::EMPTY_STRING) { + $value = $accessCondition->getValue(); + if ($value instanceof \DateTime) { + $value = gmdate( + Resources::AZURE_DATE_FORMAT, + $value->getTimestamp() + ); + } + $headers[$header] = $value; + } + } + } + } + + return $headers; + } + + /** + * Adds optional header to headers if set + * + * @param array $headers The array of request headers. + * @param array $accessCondition The access condition object. + * + * @return array + */ + public function addOptionalSourceAccessConditionHeader( + array $headers, + array $accessConditions = null + ) { + if (!empty($accessConditions)) { + foreach ($accessConditions as $accessCondition) { + if (!is_null($accessCondition)) { + $header = $accessCondition->getHeader(); + $headerName = null; + if (!empty($header)) { + switch ($header) { + case Resources::IF_MATCH: + $headerName = Resources::X_MS_SOURCE_IF_MATCH; + break; + case Resources::IF_UNMODIFIED_SINCE: + $headerName = Resources::X_MS_SOURCE_IF_UNMODIFIED_SINCE; + break; + case Resources::IF_MODIFIED_SINCE: + $headerName = Resources::X_MS_SOURCE_IF_MODIFIED_SINCE; + break; + case Resources::IF_NONE_MATCH: + $headerName = Resources::X_MS_SOURCE_IF_NONE_MATCH; + break; + default: + throw new \Exception(Resources::INVALID_ACH_MSG); + break; + } + } + $value = $accessCondition->getValue(); + if ($value instanceof \DateTime) { + $value = gmdate( + Resources::AZURE_DATE_FORMAT, + $value->getTimestamp() + ); + } + + $this->addOptionalHeader($headers, $headerName, $value); + } + } + } + + return $headers; + } +} diff --git a/src/Blob/BlobSharedAccessSignatureHelper.php b/src/Blob/BlobSharedAccessSignatureHelper.php new file mode 100644 index 0000000..8e7f998 --- /dev/null +++ b/src/Blob/BlobSharedAccessSignatureHelper.php @@ -0,0 +1,213 @@ + + * @copyright Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob; + +use MicrosoftAzure\Storage\Blob\Internal\BlobResources as Resources; +use MicrosoftAzure\Storage\Common\Internal\Utilities; +use MicrosoftAzure\Storage\Common\Internal\Validate; +use MicrosoftAzure\Storage\Common\SharedAccessSignatureHelper; + +/** + * Provides methods to generate Azure Storage Shared Access Signature + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob + * @author Azure Storage PHP SDK + * @copyright 2017 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class BlobSharedAccessSignatureHelper extends SharedAccessSignatureHelper +{ + /** + * Constructor. + * + * @param string $accountName the name of the storage account. + * @param string $accountKey the shared key of the storage account + * + */ + public function __construct($accountName, $accountKey) + { + parent::__construct($accountName, $accountKey); + } + + /** + * Generates Blob service shared access signature. + * + * This only supports version 2015-04-05 and later. + * + * @param string $signedResource Resource name to generate the + * canonicalized resource. + * It can be Resources::RESOURCE_TYPE_BLOB + * or Resources::RESOURCE_TYPE_CONTAINER. + * @param string $resourceName The name of the resource, including + * the path of the resource. It should be + * - {container}/{blob}: for blobs, + * - {container}: for containers, e.g.: + * mymusic/music.mp3 or + * music.mp3 + * @param string $signedPermissions Signed permissions. + * @param \Datetime|string $signedExpiry Signed expiry date. + * @param \Datetime|string $signedStart Signed start date. + * @param string $signedIP Signed IP address. + * @param string $signedProtocol Signed protocol. + * @param string $signedIdentifier Signed identifier. + * @param string $cacheControl Cache-Control header (rscc). + * @param string $contentDisposition Content-Disposition header (rscd). + * @param string $contentEncoding Content-Encoding header (rsce). + * @param string $contentLanguage Content-Language header (rscl). + * @param string $contentType Content-Type header (rsct). + * + * @see Constructing an service SAS at + * https://docs.microsoft.com/en-us/rest/api/storageservices/constructing-a-service-sas + * @return string + */ + public function generateBlobServiceSharedAccessSignatureToken( + $signedResource, + $resourceName, + $signedPermissions, + $signedExpiry, + $signedStart = "", + $signedIP = "", + $signedProtocol = "", + $signedIdentifier = "", + $cacheControl = "", + $contentDisposition = "", + $contentEncoding = "", + $contentLanguage = "", + $contentType = "" + ) + { + // check that the resource name is valid. + Validate::canCastAsString($signedResource, 'signedResource'); + Validate::notNullOrEmpty($signedResource, 'signedResource'); + Validate::isTrue( + $signedResource == Resources::RESOURCE_TYPE_BLOB || + $signedResource == Resources::RESOURCE_TYPE_CONTAINER, + \sprintf( + Resources::INVALID_VALUE_MSG, + '$signedResource', + 'Can only be \'b\' or \'c\'.' + ) + ); + + // check that the resource name is valid. + Validate::notNullOrEmpty($resourceName, 'resourceName'); + Validate::canCastAsString($resourceName, 'resourceName'); + + // validate and sanitize signed permissions + $signedPermissions = $this->validateAndSanitizeStringWithArray( + strtolower($signedPermissions), + Resources::ACCESS_PERMISSIONS[$signedResource] + ); + + // check that expiry is valid + if ($signedExpiry instanceof \Datetime) { + $signedExpiry = Utilities::isoDate($signedExpiry); + } + Validate::notNullOrEmpty($signedExpiry, 'signedExpiry'); + Validate::canCastAsString($signedExpiry, 'signedExpiry'); + Validate::isDateString($signedExpiry, 'signedExpiry'); + + // check that signed start is valid + if ($signedStart instanceof \Datetime) { + $signedStart = Utilities::isoDate($signedStart); + } + Validate::canCastAsString($signedStart, 'signedStart'); + if (strlen($signedStart) > 0) { + Validate::isDateString($signedStart, 'signedStart'); + } + + // check that signed IP is valid + Validate::canCastAsString($signedIP, 'signedIP'); + + // validate and sanitize signed protocol + $signedProtocol = $this->validateAndSanitizeSignedProtocol($signedProtocol); + + // check that signed identifier is valid + Validate::canCastAsString($signedIdentifier, 'signedIdentifier'); + Validate::isTrue( + strlen($signedIdentifier) <= 64, + sprintf(Resources::INVALID_STRING_LENGTH, 'signedIdentifier', 'maximum 64') + ); + + Validate::canCastAsString($cacheControl, 'cacheControl'); + Validate::canCastAsString($contentDisposition, 'contentDisposition'); + Validate::canCastAsString($contentEncoding, 'contentEncoding'); + Validate::canCastAsString($contentLanguage, 'contentLanguage'); + Validate::canCastAsString($contentType, 'contentType'); + + // construct an array with the parameters to generate the shared access signature at the account level + $parameters = array(); + $parameters[] = $signedPermissions; + $parameters[] = $signedStart; + $parameters[] = $signedExpiry; + $parameters[] = static::generateCanonicalResource( + $this->accountName, + Resources::RESOURCE_TYPE_BLOB, + $resourceName + ); + $parameters[] = $signedIdentifier; + $parameters[] = $signedIP; + $parameters[] = $signedProtocol; + $parameters[] = Resources::STORAGE_API_LATEST_VERSION; + $parameters[] = $cacheControl; + $parameters[] = $contentDisposition; + $parameters[] = $contentEncoding; + $parameters[] = $contentLanguage; + $parameters[] = $contentType; + + // implode the parameters into a string + $stringToSign = utf8_encode(implode("\n", $parameters)); + // decode the account key from base64 + $decodedAccountKey = base64_decode($this->accountKey); + // create the signature with hmac sha256 + $signature = hash_hmac("sha256", $stringToSign, $decodedAccountKey, true); + // encode the signature as base64 + $sig = urlencode(base64_encode($signature)); + + $buildOptQueryStr = function ($string, $abrv) { + return $string === '' ? '' : $abrv . $string; + }; + //adding all the components for account SAS together. + $sas = 'sv=' . Resources::STORAGE_API_LATEST_VERSION; + $sas .= '&sr=' . $signedResource; + $sas .= $buildOptQueryStr($cacheControl, '&rscc='); + $sas .= $buildOptQueryStr($contentDisposition, '&rscd='); + $sas .= $buildOptQueryStr($contentEncoding, '&rsce='); + $sas .= $buildOptQueryStr($contentLanguage, '&rscl='); + $sas .= $buildOptQueryStr($contentType, '&rsct='); + + $sas .= $buildOptQueryStr($signedStart, '&st='); + $sas .= '&se=' . $signedExpiry; + $sas .= '&sp=' . $signedPermissions; + $sas .= $buildOptQueryStr($signedIP, '&sip='); + $sas .= $buildOptQueryStr($signedProtocol, '&spr='); + $sas .= $buildOptQueryStr($signedIdentifier, '&si='); + $sas .= '&sig=' . $sig; + + return $sas; + } +} diff --git a/src/Blob/Internal/BlobResources.php b/src/Blob/Internal/BlobResources.php new file mode 100644 index 0000000..e014708 --- /dev/null +++ b/src/Blob/Internal/BlobResources.php @@ -0,0 +1,106 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Internal; + +use MicrosoftAzure\Storage\Common\Internal\Resources; + +/** + * Project resources. + * + * @ignore + * @category Microsoft + * @package MicrosoftAzure\Storage\Common\Internal + * @author Azure Storage PHP SDK + * @copyright 2017 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class BlobResources extends Resources +{ + // @codingStandardsIgnoreStart + + const BLOB_SDK_VERSION = '1.0.0'; + const STORAGE_API_LATEST_VERSION = '2016-05-31'; + + // Error messages + const INVALID_BTE_MSG = "The blob block type must exist in %s"; + const INVALID_BLOB_PAT_MSG = 'The provided access type is invalid.'; + const INVALID_ACH_MSG = 'The provided access condition header is invalid'; + const ERROR_TOO_LARGE_FOR_BLOCK_BLOB = 'Error: Exceeds the upper limit of the blob.'; + const ERROR_RANGE_NOT_ALIGN_TO_512 = 'Error: Range of the page blob must be align to 512'; + const ERROR_CONTAINER_NOT_EXIST = 'The specified container does not exist'; + const ERROR_BLOB_NOT_EXIST = 'The specified blob does not exist'; + const CONTENT_SIZE_TOO_LARGE = 'The content is too large for the selected blob type.'; + + // Headers + const X_MS_BLOB_PUBLIC_ACCESS = 'x-ms-blob-public-access'; + const X_MS_BLOB_SEQUENCE_NUMBER = 'x-ms-blob-sequence-number'; + const X_MS_BLOB_SEQUENCE_NUMBER_ACTION = 'x-ms-sequence-number-action'; + const X_MS_BLOB_TYPE = 'x-ms-blob-type'; + const X_MS_BLOB_CONTENT_TYPE = 'x-ms-blob-content-type'; + const X_MS_BLOB_CONTENT_ENCODING = 'x-ms-blob-content-encoding'; + const X_MS_BLOB_CONTENT_LANGUAGE = 'x-ms-blob-content-language'; + const X_MS_BLOB_CONTENT_MD5 = 'x-ms-blob-content-md5'; + const X_MS_BLOB_CACHE_CONTROL = 'x-ms-blob-cache-control'; + const X_MS_BLOB_CONTENT_DISPOSITION = 'x-ms-blob-content-disposition'; + const X_MS_BLOB_CONTENT_LENGTH = 'x-ms-blob-content-length'; + const X_MS_BLOB_CONDITION_MAXSIZE = 'x-ms-blob-condition-maxsize'; + const X_MS_BLOB_CONDITION_APPENDPOS = 'x-ms-blob-condition-appendpos'; + const X_MS_BLOB_APPEND_OFFSET = 'x-ms-blob-append-offset'; + const X_MS_BLOB_COMMITTED_BLOCK_COUNT = 'x-ms-blob-committed-block-count'; + const X_MS_LEASE_DURATION = 'x-ms-lease-duration'; + const X_MS_LEASE_ID = 'x-ms-lease-id'; + const X_MS_LEASE_TIME = 'x-ms-lease-time'; + const X_MS_LEASE_STATUS = 'x-ms-lease-status'; + const X_MS_LEASE_STATE = 'x-ms-lease-state'; + const X_MS_LEASE_ACTION = 'x-ms-lease-action'; + const X_MS_PROPOSED_LEASE_ID = 'x-ms-proposed-lease-id'; + const X_MS_LEASE_BREAK_PERIOD = 'x-ms-lease-break-period'; + const X_MS_PAGE_WRITE = 'x-ms-page-write'; + const X_MS_REQUEST_SERVER_ENCRYPTED = 'x-ms-request-server-encrypted'; + const X_MS_SERVER_ENCRYPTED = 'x-ms-server-encrypted'; + const X_MS_INCREMENTAL_COPY = 'x-ms-incremental-copy'; + const X_MS_COPY_DESTINATION_SNAPSHOT = 'x-ms-copy-destination-snapshot'; + const MAX_BLOB_SIZE = 'x-ms-blob-condition-maxsize'; + const MAX_APPEND_POSITION = 'x-ms-blob-condition-appendpos'; + const SEQUENCE_NUMBER_LESS_THAN_OR_EQUAL = 'x-ms-if-sequence-number-le'; + const SEQUENCE_NUMBER_LESS_THAN = 'x-ms-if-sequence-number-lt'; + const SEQUENCE_NUMBER_EQUAL = 'x-ms-if-sequence-number-eq'; + const BLOB_CONTENT_MD5 = 'x-ms-blob-content-md5'; + + // Query parameters + const QP_DELIMITER = 'Delimiter'; + const QP_BLOCKID = 'blockid'; + const QP_BLOCK_LIST_TYPE = 'blocklisttype'; + const QP_PRE_SNAPSHOT = 'prevsnapshot'; + + // Resource permissions + const ACCESS_PERMISSIONS = [ + Resources::RESOURCE_TYPE_BLOB => ['r', 'a', 'c', 'w', 'd'], + Resources::RESOURCE_TYPE_CONTAINER => ['r', 'a', 'c', 'w', 'd', 'l'] + ]; + + // @codingStandardsIgnoreEnd +} diff --git a/src/Blob/Internal/IBlob.php b/src/Blob/Internal/IBlob.php new file mode 100644 index 0000000..c2b6028 --- /dev/null +++ b/src/Blob/Internal/IBlob.php @@ -0,0 +1,1555 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Internal; + +use MicrosoftAzure\Storage\Blob\Models as BlobModels; +use MicrosoftAzure\Storage\Common\Models\ServiceOptions; +use MicrosoftAzure\Storage\Common\Models\ServiceProperties; +use MicrosoftAzure\Storage\Common\Models\GetServiceStats; +use MicrosoftAzure\Storage\Common\Models\Range; + +/** + * This interface has all REST APIs provided by Windows Azure for Blob service. + * + * @ignore + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Internal + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd135733.aspx + */ +interface IBlob +{ + /** + * Gets the properties of the service. + * + * @param ServiceOptions $options optional service options. + * + * @return GetServicePropertiesResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/hh452239.aspx + */ + public function getServiceProperties(ServiceOptions $options = null); + + /** + * Creates promise to get the properties of the service. + * + * @param ServiceOptions $options The optional parameters. + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/hh452239.aspx + */ + public function getServicePropertiesAsync(ServiceOptions $options = null); + + /** + * Sets the properties of the service. + * + * @param ServiceProperties $serviceProperties new service properties + * @param ServiceOptions $options optional parameters + * + * @return void + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/hh452235.aspx + */ + public function setServiceProperties( + ServiceProperties $serviceProperties, + ServiceOptions $options = null + ); + + /** + * Retieves statistics related to replication for the service. The operation + * will only be sent to secondary location endpoint. + * + * @param ServiceOptions|null $options The options this operation sends with. + * + * @return GetServiceStatsResult + * + * @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-service-stats + */ + public function getServiceStats(ServiceOptions $options = null); + + /** + * Creates promise that retrieves statistics related to replication for the + * service. The operation will only be sent to secondary location endpoint. + * + * @param ServiceOptions|null $options The options this operation sends with. + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-service-stats + */ + public function getServiceStatsAsync(ServiceOptions $options = null); + + /** + * Creates the promise to set the properties of the service. + * + * It's recommended to use getServiceProperties, alter the returned object and + * then use setServiceProperties with this altered object. + * + * @param ServiceProperties $serviceProperties new service properties. + * @param ServiceOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/hh452235.aspx + */ + public function setServicePropertiesAsync( + ServiceProperties $serviceProperties, + ServiceOptions $options = null + ); + + /** + * Lists all of the containers in the given storage account. + * + * @param BlobModels\ListContainersOptions $options optional parameters + * + * @return BlobModels\ListContainersResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179352.aspx + */ + public function listContainers(BlobModels\ListContainersOptions $options = null); + + /** + * Create a promise for lists all of the containers in the given + * storage account. + * + * @param BlobModels\ListContainersOptions $options The optional parameters. + * + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function listContainersAsync( + BlobModels\ListContainersOptions $options = null + ); + + /** + * Creates a new container in the given storage account. + * + * @param string $container name + * @param BlobModels\CreateContainerOptions $options optional parameters + * + * @return void + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179468.aspx + */ + public function createContainer( + $container, + BlobModels\CreateContainerOptions $options = null + ); + + /** + * Creates a new container in the given storage account. + * + * @param string $container The container name. + * @param BlobModels\CreateContainerOptions $options The optional parameters. + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179468.aspx + */ + public function createContainerAsync( + $container, + BlobModels\CreateContainerOptions $options = null + ); + + /** + * Creates a new container in the given storage account. + * + * @param string $container name + * @param BlobModels\BlobServiceOptions $options optional parameters + * + * @return void + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179408.aspx + */ + public function deleteContainer( + $container, + BlobModels\BlobServiceOptions $options = null + ); + + /** + * Create a promise for deleting a container. + * + * @param string $container name of the container + * @param BlobModels\BlobServiceOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function deleteContainerAsync( + $container, + BlobModels\BlobServiceOptions $options = null + ); + + /** + * Returns all properties and metadata on the container. + * + * @param string $container name + * @param BlobModels\BlobServiceOptions $options optional parameters + * + * @return BlobModels\GetContainerPropertiesResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179370.aspx + */ + public function getContainerProperties( + $container, + BlobModels\BlobServiceOptions $options = null + ); + + /** + * Create promise to return all properties and metadata on the container. + * + * @param string $container name + * @param BlobModels\BlobServiceOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179370.aspx + */ + public function getContainerPropertiesAsync( + $container, + BlobModels\BlobServiceOptions $options = null + ); + + /** + * Returns only user-defined metadata for the specified container. + * + * @param string $container name + * @param BlobModels\BlobServiceOptions $options optional parameters + * + * @return BlobModels\GetContainerPropertiesResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691976.aspx + */ + public function getContainerMetadata( + $container, + BlobModels\BlobServiceOptions $options = null + ); + + /** + * Create promise to return only user-defined metadata for the specified + * container. + * + * @param string $container name + * @param BlobModels\BlobServiceOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691976.aspx + */ + public function getContainerMetadataAsync( + $container, + BlobModels\BlobServiceOptions $options = null + ); + + /** + * Gets the access control list (ACL) and any container-level access policies + * for the container. + * + * @param string $container name + * @param BlobModels\BlobServiceOptions $options optional parameters + * + * @return BlobModels\GetContainerACLResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179469.aspx + */ + public function getContainerAcl( + $container, + BlobModels\BlobServiceOptions $options = null + ); + + /** + * Creates the promise to get the access control list (ACL) and any + * container-level access policies for the container. + * + * @param string $container The container name. + * @param BlobModels\BlobServiceOptions $options The optional parameters. + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179469.aspx + */ + public function getContainerAclAsync( + $container, + BlobModels\BlobServiceOptions $options = null + ); + + /** + * Sets the ACL and any container-level access policies for the container. + * + * @param string $container name + * @param BlobModels\ContainerACL $acl access control list for container + * @param BlobModels\BlobServiceOptions $options optional parameters + * + * @return void + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179391.aspx + */ + public function setContainerAcl( + $container, + BlobModels\ContainerACL $acl, + BlobModels\BlobServiceOptions $options = null + ); + + /** + * Creates promise to set the ACL and any container-level access policies + * for the container. + * + * @param string $container name + * @param BlobModels\ContainerACL $acl access control list for container + * @param BlobModels\BlobServiceOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179391.aspx + */ + public function setContainerAclAsync( + $container, + BlobModels\ContainerACL $acl, + BlobModels\BlobServiceOptions $options = null + ); + + /** + * Sets metadata headers on the container. + * + * @param string $container name + * @param array $metadata metadata key/value pair. + * @param BlobModels\BlobServiceOptions $options optional parameters + * + * @return void + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179362.aspx + */ + public function setContainerMetadata( + $container, + array $metadata, + BlobModels\BlobServiceOptions $options = null + ); + + /** + * Sets metadata headers on the container. + * + * @param string $container name + * @param array $metadata metadata key/value pair. + * @param BlobModels\BlobServiceOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179362.aspx + */ + public function setContainerMetadataAsync( + $container, + array $metadata, + BlobModels\BlobServiceOptions $options = null + ); + + /** + * Lists all of the blobs in the given container. + * + * @param string $container name + * @param BlobModels\ListBlobsOptions $options optional parameters + * + * @return BlobModels\ListBlobsResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd135734.aspx + */ + public function listBlobs( + $container, + BlobModels\ListBlobsOptions $options = null + ); + + /** + * Creates promise to list all of the blobs in the given container. + * + * @param string $container The container name. + * @param BlobModels\ListBlobsOptions $options The optional parameters. + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd135734.aspx + */ + public function listBlobsAsync( + $container, + BlobModels\ListBlobsOptions $options = null + ); + + /** + * Creates a new page blob. Note that calling createPageBlob to create a page + * blob only initializes the blob. + * To add content to a page blob, call createBlobPages method. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param int $length specifies the maximum size + * for the page blob, up to 1 TB. The page blob size must be aligned to + * a 512-byte boundary. + * @param BlobModels\CreateBlobOptions $options optional parameters + * + * @return BlobModels\CopyBlobResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179451.aspx + */ + public function createPageBlob( + $container, + $blob, + $length, + BlobModels\CreateBlobOptions $options = null + ); + + /** + * Creates promise to create a new page blob. Note that calling + * createPageBlob to create a page blob only initializes the blob. + * To add content to a page blob, call createBlobPages method. + * + * @param string $container The container name. + * @param string $blob The blob name. + * @param integer $length Specifies the maximum size + * for the page blob, up to + * 1 TB. The page blob size + * must be aligned to a + * 512-byte boundary. + * @param BlobModels\CreateBlobOptions $options The optional parameters. + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179451.aspx + */ + public function createPageBlobAsync( + $container, + $blob, + $length, + BlobModels\CreateBlobOptions $options = null + ); + + /** + * Create a new append blob. + * If the blob already exists on the service, it will be overwritten. + * + * @param string $container The container name. + * @param string $blob The blob name. + * @param Models\CreateBlobOptions $options The optional parameters. + * + * @return Models\PutBlobResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179451.aspx + */ + public function createAppendBlob( + $container, + $blob, + BlobModels\CreateBlobOptions $options = null + ); + + + /** + * Creates promise to create a new append blob. + * If the blob already exists on the service, it will be overwritten. + * + * @param string $container The container name. + * @param string $blob The blob name. + * @param Models\CreateBlobOptions $options The optional parameters. + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179451.aspx + */ + public function createAppendBlobAsync( + $container, + $blob, + BlobModels\CreateBlobOptions $options = null + ); + + /** + * Creates a new block blob or updates the content of an existing block blob. + * Updating an existing block blob overwrites any existing metadata on the blob. + * Partial updates are not supported with createBlockBlob; the content of the + * existing blob is overwritten with the content of the new blob. To perform a + * partial update of the content of a block blob, use the createBlockList method. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $content content of the blob + * @param BlobModels\CreateBlockBlobOptions $options optional parameters + * + * @return BlobModels\CopyBlobResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179451.aspx + */ + public function createBlockBlob( + $container, + $blob, + $content, + BlobModels\CreateBlockBlobOptions $options = null + ); + + /** + * Creates a promise to create a new block blob or updates the content of + * an existing block blob. + * + * Updating an existing block blob overwrites any existing metadata on the blob. + * Partial updates are not supported with createBlockBlob the content of the + * existing blob is overwritten with the content of the new blob. To perform a + * partial update of the content of a block blob, use the createBlockList + * method. + * + * @param string $container The name of the container. + * @param string $blob The name of the blob. + * @param string|resource|StreamInterface $content The content of the blob. + * @param BlobModels\CreateBlockBlobOptions $options The optional parameters. + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179451.aspx + */ + public function createBlockBlobAsync( + $container, + $blob, + $content, + BlobModels\CreateBlockBlobOptions $options = null + ); + + /** + * Create a new page blob and upload the content to the page blob. + * + * @param string $container The name of the container. + * @param string $blob The name of the blob. + * @param int $length The length of the blob. + * @param string|resource|StreamInterface $content The content of the blob. + * @param BlobModels\CreatePageBlobFromContentOptions + * $options The optional parameters. + * + * @return BlobModels\GetBlobPropertiesResult + * + * @see https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/get-blob-properties + */ + public function createPageBlobFromContent( + $container, + $blob, + $length, + $content, + BlobModels\CreatePageBlobFromContentOptions $options = null + ); + + /** + * Creates a promise to create a new page blob and upload the content + * to the page blob. + * + * @param string $container The name of the container. + * @param string $blob The name of the blob. + * @param int $length The length of the blob. + * @param string|resource|StreamInterface $content The content of the blob. + * @param BlobModels\CreatePageBlobFromContentOptions + * $options The optional parameters. + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/get-blob-properties + */ + public function createPageBlobFromContentAsync( + $container, + $blob, + $length, + $content, + BlobModels\CreatePageBlobFromContentOptions $options = null + ); + + /** + * Clears a range of pages from the blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param Range $range Can be up to the value + * of the blob's full size. + * @param BlobModels\CreateBlobPagesOptions $options optional parameters + * + * @return BlobModels\CreateBlobPagesResult. + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691975.aspx + */ + public function clearBlobPages( + $container, + $blob, + Range $range, + BlobModels\CreateBlobPagesOptions $options = null + ); + + /** + * Creates promise to clear a range of pages from the blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param Range $range Can be up to the value + * of the blob's full size. + * Note that ranges must be + * aligned to 512 (0-511, + * 512-1023) + * @param BlobModels\CreateBlobPagesOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691975.aspx + */ + public function clearBlobPagesAsync( + $container, + $blob, + Range $range, + BlobModels\CreateBlobPagesOptions $options = null + ); + + /** + * Creates a range of pages to a page blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param Range $range Can be up to 4 MB in size + * @param string $content the blob contents + * @param BlobModels\CreateBlobPagesOptions $options optional parameters + * + * @return BlobModels\CreateBlobPagesResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691975.aspx + */ + public function createBlobPages( + $container, + $blob, + Range $range, + $content, + BlobModels\CreateBlobPagesOptions $options = null + ); + + /** + * Creates promise to create a range of pages to a page blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param Range $range Can be up to 4 MB in + * size. Note that ranges + * must be aligned to 512 + * (0-511, 512-1023) + * @param string|resource|StreamInterface $content the blob contents. + * @param BlobModels\CreateBlobPagesOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691975.aspx + */ + public function createBlobPagesAsync( + $container, + $blob, + Range $range, + $content, + BlobModels\CreateBlobPagesOptions $options = null + ); + + /** + * Creates a new block to be committed as part of a block blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $blockId must be less than or equal to + * 64 bytes in size. For a given blob, the length of the value specified for the + * blockid parameter must be the same size for each block. + * @param string $content the blob block contents + * @param BlobModels\CreateBlobBlockOptions $options optional parameters + * + * @return void + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd135726.aspx + */ + public function createBlobBlock( + $container, + $blob, + $blockId, + $content, + BlobModels\CreateBlobBlockOptions $options = null + ); + + /** + * Creates a new block to be committed as part of a block blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $blockId must be less than or + * equal to 64 bytes in + * size. For a given + * blob, the length of + * the value specified + * for the blockid + * parameter must + * be the same size for + * each block. + * @param resource|string|StreamInterface $content the blob block contents + * @param BlobModels\CreateBlobBlockOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd135726.aspx + */ + public function createBlobBlockAsync( + $container, + $blob, + $blockId, + $content, + BlobModels\CreateBlobBlockOptions $options = null + ); + + /** + * Commits a new block of data to the end of an existing append blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param resource|string|StreamInterface $content the blob block contents + * @param Models\AppendBlockOptions $options optional parameters + * + * @return Models\AppendBlockResult + * + * @see https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/append-block + */ + public function appendBlock( + $container, + $blob, + $content, + BlobModels\AppendBlockOptions $options = null + ); + + /** + * Creates promise to commit a new block of data to the end of an existing append blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param resource|string|StreamInterface $content the blob block contents + * @param Models\AppendBlockOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/append-block + */ + public function appendBlockAsync( + $container, + $blob, + $content, + BlobModels\AppendBlockOptions $options = null + ); + + /** + * This method writes a blob by specifying the list of block IDs that make up the + * blob. In order to be written as part of a blob, a block must have been + * successfully written to the server in a prior createBlobBlock method. + * + * You can call Put Block List to update a blob by uploading only those blocks + * that have changed, then committing the new and existing blocks together. + * You can do this by specifying whether to commit a block from the committed + * block list or from the uncommitted block list, or to commit the most recently + * uploaded version of the block, whichever list it may belong to. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param BlobModels\BlockList|BlobModels\Block[] $blockList the block list entries + * @param BlobModels\CommitBlobBlocksOptions $options optional parameters + * + * @return BlobModels\PutBlobResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179467.aspx + */ + public function commitBlobBlocks( + $container, + $blob, + $blockList, + BlobModels\CommitBlobBlocksOptions $options = null + ); + + /** + * This method writes a blob by specifying the list of block IDs that make up the + * blob. In order to be written as part of a blob, a block must have been + * successfully written to the server in a prior createBlobBlock method. + * + * You can call Put Block List to update a blob by uploading only those blocks + * that have changed, then committing the new and existing blocks together. + * You can do this by specifying whether to commit a block from the committed + * block list or from the uncommitted block list, or to commit the most recently + * uploaded version of the block, whichever list it may belong to. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param BlobModels\BlockList|BlobModels\Block[] $blockList the block list + * entries + * @param BlobModels\CommitBlobBlocksOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179467.aspx + */ + public function commitBlobBlocksAsync( + $container, + $blob, + $blockList, + BlobModels\CommitBlobBlocksOptions $options = null + ); + + /** + * Retrieves the list of blocks that have been uploaded as part of a block blob. + * + * There are two block lists maintained for a blob: + * 1) Committed Block List: The list of blocks that have been successfully + * committed to a given blob with commitBlobBlocks. + * 2) Uncommitted Block List: The list of blocks that have been uploaded for a + * blob using Put Block (REST API), but that have not yet been committed. + * These blocks are stored in Windows Azure in association with a blob, but do + * not yet form part of the blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param BlobModels\ListBlobBlocksOptions $options optional parameters + * + * @return BlobModels\ListBlobBlocksResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179400.aspx + */ + public function listBlobBlocks( + $container, + $blob, + BlobModels\ListBlobBlocksOptions $options = null + ); + + /** + * Creates promise to retrieve the list of blocks that have been uploaded as + * part of a block blob. + * + * There are two block lists maintained for a blob: + * 1) Committed Block List: The list of blocks that have been successfully + * committed to a given blob with commitBlobBlocks. + * 2) Uncommitted Block List: The list of blocks that have been uploaded for a + * blob using Put Block (REST API), but that have not yet been committed. + * These blocks are stored in Windows Azure in association with a blob, but do + * not yet form part of the blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param BlobModels\ListBlobBlocksOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179400.aspx + */ + public function listBlobBlocksAsync( + $container, + $blob, + BlobModels\ListBlobBlocksOptions $options = null + ); + + /** + * Returns all properties and metadata on the blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param BlobModels\GetBlobPropertiesOptions $options optional parameters + * + * @return BlobModels\GetBlobPropertiesResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179394.aspx + */ + public function getBlobProperties( + $container, + $blob, + BlobModels\GetBlobPropertiesOptions $options = null + ); + + /** + * Creates promise to return all properties and metadata on the blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param BlobModels\GetBlobPropertiesOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179394.aspx + */ + public function getBlobPropertiesAsync( + $container, + $blob, + BlobModels\GetBlobPropertiesOptions $options = null + ); + + /** + * Returns all properties and metadata on the blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param BlobModels\GetBlobMetadataOptions $options optional parameters + * + * @return BlobModels\GetBlobMetadataResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179350.aspx + */ + public function getBlobMetadata( + $container, + $blob, + BlobModels\GetBlobMetadataOptions $options = null + ); + + /** + * Creates promise to return all properties and metadata on the blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param BlobModels\GetBlobMetadataOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179350.aspx + */ + public function getBlobMetadataAsync( + $container, + $blob, + BlobModels\GetBlobMetadataOptions $options = null + ); + + /** + * Returns a list of active page ranges for a page blob. Active page ranges are + * those that have been populated with data. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param BlobModels\ListPageBlobRangesOptions $options optional parameters + * + * @return BlobModels\ListPageBlobRangesResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691973.aspx + */ + public function listPageBlobRanges( + $container, + $blob, + BlobModels\ListPageBlobRangesOptions $options = null + ); + + /** + * Creates promise to return a list of active page ranges for a page blob. + * Active page ranges are those that have been populated with data. + * + * @param string $container name of the + * container + * @param string $blob name of the blob + * @param BlobModels\ListPageBlobRangesOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691973.aspx + */ + public function listPageBlobRangesAsync( + $container, + $blob, + BlobModels\ListPageBlobRangesOptions $options = null + ); + + /** + * Returns a list of page ranges that have been updated or cleared. + * + * Returns a list of page ranges that have been updated or cleared since + * the snapshot specified by `previousSnapshotTime`. Gets all of the page + * ranges by default, or only the page ranges over a specific range of + * bytes if `rangeStart` and `rangeEnd` in the `options` are specified. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $previousSnapshotTime previous snapshot time + * for comparison which + * should be prior to the + * snapshot time defined + * in `options` + * @param BlobModels\ListPageBlobRangesOptions $options optional parameters + * + * @return BlobModels\ListPageBlobRangesDiffResult + * + * @see https://docs.microsoft.com/en-us/rest/api/storageservices/version-2015-07-08 + */ + public function listPageBlobRangesDiff( + $container, + $blob, + $previousSnapshotTime, + BlobModels\ListPageBlobRangesOptions $options = null + ); + + /** + * Creates promise to return a list of page ranges that have been updated + * or cleared. + * + * Creates promise to return a list of page ranges that have been updated + * or cleared since the snapshot specified by `previousSnapshotTime`. Gets + * all of the page ranges by default, or only the page ranges over a specific + * range of bytes if `rangeStart` and `rangeEnd` in the `options` are specified. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $previousSnapshotTime previous snapshot time + * for comparison which + * should be prior to the + * snapshot time defined + * in `options` + * @param BlobModels\ListPageBlobRangesOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691973.aspx + */ + public function listPageBlobRangesDiffAsync( + $container, + $blob, + $previousSnapshotTime, + BlobModels\ListPageBlobRangesOptions $options = null + ); + + /** + * Sets system properties defined for a blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param BlobModels\SetBlobPropertiesOptions $options optional parameters + * + * @return BlobModels\SetBlobPropertiesResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691966.aspx + */ + public function setBlobProperties( + $container, + $blob, + BlobModels\SetBlobPropertiesOptions $options = null + ); + + /** + * Creates promise to set system properties defined for a blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param BlobModels\SetBlobPropertiesOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691966.aspx + */ + public function setBlobPropertiesAsync( + $container, + $blob, + BlobModels\SetBlobPropertiesOptions $options = null + ); + + /** + * Sets metadata headers on the blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param array $metadata key/value pair representation + * @param BlobModels\BlobServiceOptions $options optional parameters + * + * @return BlobModels\SetBlobMetadataResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179414.aspx + */ + public function setBlobMetadata( + $container, + $blob, + array $metadata, + BlobModels\BlobServiceOptions $options = null + ); + + /** + * Creates promise to set metadata headers on the blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param array $metadata key/value pair representation + * @param BlobModels\BlobServiceOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179414.aspx + */ + public function setBlobMetadataAsync( + $container, + $blob, + array $metadata, + BlobModels\BlobServiceOptions $options = null + ); + + /** + * Reads or downloads a blob from the system, including its metadata and + * properties. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param BlobModels\GetBlobOptions $options optional parameters + * + * @return BlobModels\GetBlobResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179440.aspx + */ + public function getBlob( + $container, + $blob, + BlobModels\GetBlobOptions $options = null + ); + + /** + * Creates promise to read or download a blob from the system, including its + * metadata and properties. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param BlobModels\GetBlobOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179440.aspx + */ + public function getBlobAsync( + $container, + $blob, + BlobModels\GetBlobOptions $options = null + ); + + /** + * Deletes a blob or blob snapshot. + * + * Note that if the snapshot entry is specified in the $options then only this + * blob snapshot is deleted. To delete all blob snapshots, do not set Snapshot + * and just set getDeleteSnaphotsOnly to true. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param BlobModels\DeleteBlobOptions $options optional parameters + * + * @return void + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179413.aspx + */ + public function deleteBlob( + $container, + $blob, + BlobModels\DeleteBlobOptions $options = null + ); + + /** + * Creates promise to delete a blob or blob snapshot. + * + * Note that if the snapshot entry is specified in the $options then only this + * blob snapshot is deleted. To delete all blob snapshots, do not set Snapshot + * and just set getDeleteSnaphotsOnly to true. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param BlobModels\DeleteBlobOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179413.aspx + */ + public function deleteBlobAsync( + $container, + $blob, + BlobModels\DeleteBlobOptions $options = null + ); + + /** + * Creates a snapshot of a blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param BlobModels\CreateBlobSnapshotOptions $options optional parameters + * + * @return BlobModels\CreateBlobSnapshotResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691971.aspx + */ + public function createBlobSnapshot( + $container, + $blob, + BlobModels\CreateBlobSnapshotOptions $options = null + ); + + /** + * Creates promise to create a snapshot of a blob. + * + * @param string $container The name of the + * container. + * @param string $blob The name of the + * blob. + * @param BlobModels\CreateBlobSnapshotOptions $options The optional + * parameters. + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691971.aspx + */ + public function createBlobSnapshotAsync( + $container, + $blob, + BlobModels\CreateBlobSnapshotOptions $options = null + ); + + /** + * Copies a source blob to a destination blob within the same storage account. + * + * @param string $destinationContainer name of container + * @param string $destinationBlob name of blob + * @param string $sourceContainer name of container + * @param string $sourceBlob name of blob + * @param BlobModels\CopyBlobOptions $options optional parameters + * + * @return BlobModels\CopyBlobResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd894037.aspx + */ + public function copyBlob( + $destinationContainer, + $destinationBlob, + $sourceContainer, + $sourceBlob, + BlobModels\CopyBlobOptions $options = null + ); + + /** + * Creates promise to copy a source blob to a destination blob within the + * same storage account. + * + * @param string $destinationContainer name of the + * destination + * container + * @param string $destinationBlob name of the + * destination blob + * @param string $sourceContainer name of the source + * container + * @param string $sourceBlob name of the source + * blob + * @param BlobModels\CopyBlobOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd894037.aspx + */ + public function copyBlobAsync( + $destinationContainer, + $destinationBlob, + $sourceContainer, + $sourceBlob, + BlobModels\CopyBlobOptions $options = null + ); + + /** + * Copies from a source URL to a destination blob. + * + * @param string $destinationContainer name of the + * destination + * container + * @param string $destinationBlob name of the + * destination + * blob + * @param string $sourceURL URL of the + * source + * resource + * @param BlobModels\CopyBlobFromURLOptions $options optional + * parameters + * + * @return BlobModels\CopyBlobResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd894037.aspx + */ + public function copyBlobFromURL( + $destinationContainer, + $destinationBlob, + $sourceURL, + BlobModels\CopyBlobFromURLOptions $options = null + ); + + /** + * Creates promise to copy from source URL to a destination blob. + * + * @param string $destinationContainer name of the + * destination + * container + * @param string $destinationBlob name of the + * destination + * blob + * @param string $sourceURL URL of the + * source + * resource + * @param BlobModels\CopyBlobFromURLOptions $options optional + * parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd894037.aspx + */ + public function copyBlobFromURLAsync( + $destinationContainer, + $destinationBlob, + $sourceURL, + BlobModels\CopyBlobFromURLOptions $options = null + ); + + /** + * Abort a blob copy operation + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $copyId copy operation identifier. + * @param BlobModels\BlobServiceOptions $options optional parameters + * + * @return void + * + * @see https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/abort-copy-blob + */ + public function abortCopy( + $container, + $blob, + $copyId, + BlobModels\BlobServiceOptions $options = null + ); + + /** + * Creates promise to abort a blob copy operation + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $copyId copy operation identifier. + * @param BlobModels\BlobServiceOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/abort-copy-blob + */ + public function abortCopyAsync( + $container, + $blob, + $copyId, + BlobModels\BlobServiceOptions $options = null + ); + + /** + * Establishes an exclusive write lock on a blob. To write to a locked + * blob, a client must provide a lease ID. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $proposedLeaseId lease id when acquiring + * @param int $leaseDuration the lease duration. A non-infinite + * lease can be between 15 and 60 seconds. + * Default is never to expire. + * @param Models\BlobServiceOptions $options optional parameters + * + * @return Models\LeaseResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691972.aspx + */ + public function acquireLease( + $container, + $blob, + $proposedLeaseId = null, + $leaseDuration = null, + BlobModels\BlobServiceOptions $options = null + ); + + /** + * Creates promise to establish an exclusive one-minute write lock on a blob. + * To write to a locked blob, a client must provide a lease ID. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $proposedLeaseId lease id when acquiring + * @param int $leaseDuration the lease duration. A non-infinite + * lease can be between 15 and 60 seconds. + * Default is never to expire. + * @param Models\BlobServiceOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691972.aspx + */ + public function acquireLeaseAsync( + $container, + $blob, + $proposedLeaseId = null, + $leaseDuration = null, + BlobModels\BlobServiceOptions $options = null + ); + + /** + * change an existing lease + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $leaseId lease id when acquiring + * @param string $proposedLeaseId lease id when acquiring + * @param BlobModels\BlobServiceOptions $options optional parameters + * + * @return BlobModels\LeaseResult + * + * @see https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/lease-blob + */ + public function changeLease( + $container, + $blob, + $leaseId, + $proposedLeaseId, + BlobModels\BlobServiceOptions $options = null + ); + + /** + * Creates promise to change an existing lease + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $leaseId lease id when acquiring + * @param string $proposedLeaseId the proposed lease id + * @param BlobModels\BlobServiceOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/lease-blob + */ + public function changeLeaseAsync( + $container, + $blob, + $leaseId, + $proposedLeaseId, + BlobModels\BlobServiceOptions $options = null + ); + + /** + * Renews an existing lease + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $leaseId lease id when acquiring + * @param BlobModels\BlobServiceOptions $options optional parameters + * + * @return BlobModels\AcquireLeaseResult + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691972.aspx + */ + public function renewLease( + $container, + $blob, + $leaseId, + BlobModels\BlobServiceOptions $options = null + ); + + /** + * Creates promise to renew an existing lease + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $leaseId lease id when acquiring + * @param BlobModels\BlobServiceOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691972.aspx + */ + public function renewLeaseAsync( + $container, + $blob, + $leaseId, + BlobModels\BlobServiceOptions $options = null + ); + + + /** + * Frees the lease if it is no longer needed so that another client may + * immediately acquire a lease against the blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $leaseId lease id when acquiring + * @param BlobModels\BlobServiceOptions $options optional parameters + * + * @return void + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691972.aspx + */ + public function releaseLease( + $container, + $blob, + $leaseId, + BlobModels\BlobServiceOptions $options = null + ); + + /** + * Creates promise to free the lease if it is no longer needed so that + * another client may immediately acquire a lease against the blob. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param string $leaseId lease id when acquiring + * @param BlobModels\BlobServiceOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691972.aspx + */ + public function releaseLeaseAsync( + $container, + $blob, + $leaseId, + BlobModels\BlobServiceOptions $options = null + ); + + /** + * Ends the lease but ensure that another client cannot acquire a new lease until + * the current lease period has expired. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param BlobModels\BlobServiceOptions $options optional parameters + * + * @return void + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691972.aspx + */ + public function breakLease( + $container, + $blob, + $breakPeriod = null, + BlobModels\BlobServiceOptions $options = null + ); + + /** + * Creates promise to end the lease but ensure that another client cannot + * acquire a new lease until the current lease period has expired. + * + * @param string $container name of the container + * @param string $blob name of the blob + * @param BlobModels\BlobServiceOptions $options optional parameters + * + * @return \GuzzleHttp\Promise\PromiseInterface + * + * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691972.aspx + */ + public function breakLeaseAsync( + $container, + $blob, + $breakPeriod = null, + BlobModels\BlobServiceOptions $options = null + ); +} diff --git a/src/Blob/Models/AccessCondition.php b/src/Blob/Models/AccessCondition.php new file mode 100644 index 0000000..c2d0ea2 --- /dev/null +++ b/src/Blob/Models/AccessCondition.php @@ -0,0 +1,355 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Blob\Internal\BlobResources as Resources; +use MicrosoftAzure\Storage\Common\Internal\Validate; +use MicrosoftAzure\Storage\Common\Internal\WindowsAzureUtilities; + +/** + * Represents a set of access conditions to be used for operations against the + * storage services. + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class AccessCondition +{ + private $_header = Resources::EMPTY_STRING; + private $_value; + + /** + * Constructor + * + * @param string $headerType header name + * @param string $value header value + * + * @internal + */ + protected function __construct($headerType, $value) + { + $this->setHeader($headerType); + $this->setValue($value); + } + + /** + * Specifies that no access condition is set. + * + * @return \MicrosoftAzure\Storage\Blob\Models\AccessCondition + */ + public static function none() + { + return new AccessCondition(Resources::EMPTY_STRING, null); + } + + /** + * Returns an access condition such that an operation will be performed only if + * the resource's ETag value matches the specified ETag value. + *

+ * Setting this access condition modifies the request to include the HTTP + * If-Match conditional header. If this access condition is set, the + * operation is performed only if the ETag of the resource matches the specified + * ETag. + *

+ * For more information, see + * + * Specifying Conditional Headers for Blob Service Operations. + * + * @param string $etag a string that represents the ETag value to check. + * + * @return \MicrosoftAzure\Storage\Blob\Models\AccessCondition + */ + public static function ifMatch($etag) + { + return new AccessCondition(Resources::IF_MATCH, $etag); + } + + /** + * Returns an access condition such that an operation will be performed only if + * the resource has been modified since the specified time. + *

+ * Setting this access condition modifies the request to include the HTTP + * If-Modified-Since conditional header. If this access condition is set, + * the operation is performed only if the resource has been modified since the + * specified time. + *

+ * For more information, see + * + * Specifying Conditional Headers for Blob Service Operations. + * + * @param \DateTime $lastModified date that represents the last-modified + * time to check for the resource. + * + * @return \MicrosoftAzure\Storage\Blob\Models\AccessCondition + */ + public static function ifModifiedSince(\DateTime $lastModified) + { + Validate::isDate($lastModified); + return new AccessCondition( + Resources::IF_MODIFIED_SINCE, + $lastModified + ); + } + + /** + * Returns an access condition such that an operation will be performed only if + * the resource's ETag value does not match the specified ETag value. + *

+ * Setting this access condition modifies the request to include the HTTP + * If-None-Match conditional header. If this access condition is set, the + * operation is performed only if the ETag of the resource does not match the + * specified ETag. + *

+ * For more information, + * see + * Specifying Conditional Headers for Blob Service Operations. + * + * @param string $etag string that represents the ETag value to check. + * + * @return \MicrosoftAzure\Storage\Blob\Models\AccessCondition + */ + public static function ifNoneMatch($etag) + { + return new AccessCondition(Resources::IF_NONE_MATCH, $etag); + } + + /** + * Returns an access condition such that an operation will be performed only if + * the resource has not been modified since the specified time. + *

+ * Setting this access condition modifies the request to include the HTTP + * If-Unmodified-Since conditional header. If this access condition is + * set, the operation is performed only if the resource has not been modified + * since the specified time. + *

+ * For more information, see + * + * Specifying Conditional Headers for Blob Service Operations. + * + * @param \DateTime $lastModified date that represents the last-modified + * time to check for the resource. + * + * @return \MicrosoftAzure\Storage\Blob\Models\AccessCondition + */ + public static function ifNotModifiedSince(\DateTime $lastModified) + { + Validate::isDate($lastModified); + return new AccessCondition( + Resources::IF_UNMODIFIED_SINCE, + $lastModified + ); + } + + /** + * Returns an access condition such that an operation will be performed only if + * the operation would cause the blob to exceed that limit or if the append + * position is equal to this number. + *

+ * Setting this access condition modifies the request to include the HTTP + * x-ms-blob-condition-appendpos conditional header. If this access condition + * is set, the operation is performed only if the append position is equal to this number + *

+ * For more information, + * see + * Specifying Conditional Headers for Blob Service Operations. + * + * @param int $appendPosition int that represents the append position + * + * @return \MicrosoftAzure\Storage\Blob\Models\AccessCondition + */ + public static function appendPosition($appendPosition) + { + return new AccessCondition(Resources::MAX_APPEND_POSITION, $appendPosition); + } + + /** + * Returns an access condition such that an operation will be performed only if + * the operation would cause the blob to exceed that limit or if the blob size + * is already greater than the value specified in this header. + *

+ * Setting this access condition modifies the request to include the HTTP + * x-ms-blob-condition-maxsize conditional header. If this access condition + * is set, the operation is performed only if the operation would cause the blob + * to exceed that limit or if the blob size is already greater than the value + * specified in this header. + *

+ * For more information, + * see + * Specifying Conditional Headers for Blob Service Operations. + * + * @param int $maxBlobSize int that represents the max blob size + * + * @return \MicrosoftAzure\Storage\Blob\Models\AccessCondition + */ + public static function maxBlobSize($maxBlobSize) + { + return new AccessCondition(Resources::MAX_BLOB_SIZE, $maxBlobSize); + } + + /** + * Returns an access condition such that an operation will be performed only if + * the blob’s sequence number is less than the specified value. + *

+ * Setting this access condition modifies the request to include the HTTP + * x-ms-if-sequence-number-lt conditional header. If this access condition + * is set, the operation is performed only if the blob’s sequence number is less + * than the specified value. + *

+ * For more information, + * see + * Specifying Conditional Headers for Blob Service Operations. + * + * @param int $sequenceNumber int that represents the sequence number value to check. + * + * @return \MicrosoftAzure\Storage\Blob\Models\AccessCondition + */ + public static function ifSequenceNumberLessThan($sequenceNumber) + { + return new AccessCondition(Resources::SEQUENCE_NUMBER_LESS_THAN, $sequenceNumber); + } + + /** + * Returns an access condition such that an operation will be performed only if + * the blob’s sequence number is equal to the specified value. + *

+ * Setting this access condition modifies the request to include the HTTP + * x-ms-if-sequence-number-eq conditional header. If this access condition + * is set, the operation is performed only if the blob’s sequence number is equal to + * the specified value. + *

+ * For more information, + * see + * Specifying Conditional Headers for Blob Service Operations. + * + * @param int $sequenceNumber int that represents the sequence number value to check. + * + * @return \MicrosoftAzure\Storage\Blob\Models\AccessCondition + */ + public static function ifSequenceNumberEqual($sequenceNumber) + { + return new AccessCondition(Resources::SEQUENCE_NUMBER_EQUAL, $sequenceNumber); + } + + /** + * Returns an access condition such that an operation will be performed only if + * the blob’s sequence number is less than or equal to the specified value. + *

+ * Setting this access condition modifies the request to include the HTTP + * x-ms-if-sequence-number-le conditional header. If this access condition + * is set, the operation is performed only if the blob’s sequence number is less + * than or equal to the specified value. + *

+ * For more information, + * see + * Specifying Conditional Headers for Blob Service Operations. + * + * @param int $sequenceNumber int that represents the sequence number value to check. + * + * @return \MicrosoftAzure\Storage\Blob\Models\AccessCondition + */ + public static function ifSequenceNumberLessThanOrEqual($sequenceNumber) + { + return new AccessCondition(Resources::SEQUENCE_NUMBER_LESS_THAN_OR_EQUAL, $sequenceNumber); + } + + /** + * Sets header type + * + * @param string $headerType can be one of Resources + * + * @return void + */ + public function setHeader($headerType) + { + $valid = AccessCondition::isValid($headerType); + Validate::isTrue($valid, Resources::INVALID_HT_MSG); + + $this->_header = $headerType; + } + + /** + * Gets header type + * + * @return string + */ + public function getHeader() + { + return $this->_header; + } + + /** + * Sets the header value + * + * @param string $value the value to use + * + * @return void + */ + public function setValue($value) + { + $this->_value = $value; + } + + /** + * Gets the header value + * + * @return string + */ + public function getValue() + { + return $this->_value; + } + + /** + * Check if the $headerType belongs to valid header types + * + * @param string $headerType candidate header type + * + * @internal + * + * @return boolean + */ + public static function isValid($headerType) + { + if ($headerType == Resources::EMPTY_STRING + || $headerType == Resources::IF_UNMODIFIED_SINCE + || $headerType == Resources::IF_MATCH + || $headerType == Resources::IF_MODIFIED_SINCE + || $headerType == Resources::IF_NONE_MATCH + || $headerType == Resources::MAX_BLOB_SIZE + || $headerType == Resources::MAX_APPEND_POSITION + || $headerType == Resources::SEQUENCE_NUMBER_LESS_THAN_OR_EQUAL + || $headerType == Resources::SEQUENCE_NUMBER_LESS_THAN + || $headerType == Resources::SEQUENCE_NUMBER_EQUAL + ) { + return true; + } else { + return false; + } + } +} diff --git a/src/Blob/Models/AppendBlockOptions.php b/src/Blob/Models/AppendBlockOptions.php new file mode 100644 index 0000000..087b751 --- /dev/null +++ b/src/Blob/Models/AppendBlockOptions.php @@ -0,0 +1,108 @@ + + * @copyright 2017 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +/** + * Optional parameters for appendBlock wrapper + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class AppendBlockOptions extends BlobServiceOptions +{ + private $contentMD5; + private $maxBlobSize; + private $appendPosition; + + /** + * Gets block contentMD5. + * + * @return string + */ + public function getContentMD5() + { + return $this->contentMD5; + } + + /** + * Sets block contentMD5. + * + * @param string $contentMD5 value. + * + * @return void + */ + public function setContentMD5($contentMD5) + { + $this->contentMD5 = $contentMD5; + } + + /** + * Gets the max length in bytes allowed for the append blob to grow to. + * + * @return int + */ + public function getMaxBlobSize() + { + return $this->maxBlobSize; + } + + /** + * Sets the max length in bytes allowed for the append blob to grow to. + * + * @param int $maxBlobSize value. + * + * @return void + */ + public function setMaxBlobSize($maxBlobSize) + { + $this->maxBlobSize = $maxBlobSize; + } + + /** + * Gets append blob appendPosition. + * + * @return int + */ + public function getAppendPosition() + { + return $this->appendPosition; + } + + /** + * Sets append blob appendPosition. + * + * @param int $appendPosition value. + * + * @return void + */ + public function setAppendPosition($appendPosition) + { + $this->appendPosition = $appendPosition; + } +} diff --git a/src/Blob/Models/AppendBlockResult.php b/src/Blob/Models/AppendBlockResult.php new file mode 100644 index 0000000..39ca5ad --- /dev/null +++ b/src/Blob/Models/AppendBlockResult.php @@ -0,0 +1,244 @@ + + * @copyright 2017 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Blob\Internal\BlobResources as Resources; +use MicrosoftAzure\Storage\Common\Internal\Utilities; + +/** + * The result of calling appendBlock API. + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class AppendBlockResult +{ + private $appendOffset; + private $committedBlockCount; + private $contentMD5; + private $etag; + private $lastModified; + private $requestServerEncrypted; + + /** + * Creates AppendBlockResult object from the response of the put block request. + * + * @param array $headers The HTTP response headers in array representation. + * + * @internal + * + * @return AppendBlockResult + */ + public static function create(array $headers) + { + $result = new AppendBlockResult(); + + $result->setAppendOffset( + intval( + Utilities::tryGetValueInsensitive( + Resources::X_MS_BLOB_APPEND_OFFSET, $headers + ) + ) + ); + + $result->setCommittedBlockCount( + intval( + Utilities::tryGetValueInsensitive( + Resources::X_MS_BLOB_COMMITTED_BLOCK_COUNT, $headers + ) + ) + ); + + $result->setContentMD5( + Utilities::tryGetValueInsensitive(Resources::CONTENT_MD5, $headers) + ); + + $result->setEtag( + Utilities::tryGetValueInsensitive(Resources::ETAG, $headers) + ); + + if (Utilities::arrayKeyExistsInsensitive( + Resources::LAST_MODIFIED, + $headers + )) { + $lastModified = Utilities::tryGetValueInsensitive( + Resources::LAST_MODIFIED, + $headers + ); + $lastModified = Utilities::rfc1123ToDateTime($lastModified); + + $result->setLastModified($lastModified); + } + + $result->setRequestServerEncrypted( + Utilities::toBoolean( + Utilities::tryGetValueInsensitive( + Resources::X_MS_REQUEST_SERVER_ENCRYPTED, + $headers + ), + true + ) + ); + + return $result; + } + + /** + * Gets Etag of the blob that the client can use to perform conditional + * PUT operations by using the If-Match request header. + * + * @return string + */ + public function getEtag() + { + return $this->etag; + } + + /** + * Sets the etag value. + * + * @param string $etag etag as a string. + * + * @return void + */ + protected function setEtag($etag) + { + $this->etag = $etag; + } + + /** + * Gets $lastModified value. + * + * @return \DateTime + */ + public function getLastModified() + { + return $this->lastModified; + } + + /** + * Sets the $lastModified value. + * + * @param \DateTime $lastModified $lastModified value. + * + * @return void + */ + protected function setLastModified($lastModified) + { + $this->lastModified = $lastModified; + } + + /** + * Gets block content MD5. + * + * @return string + */ + public function getContentMD5() + { + return $this->contentMD5; + } + + /** + * Sets the content MD5 value. + * + * @param string $contentMD5 conent MD5 as a string. + * + * @return void + */ + protected function setContentMD5($contentMD5) + { + $this->contentMD5 = $contentMD5; + } + + /** + * Gets the offset at which the block was committed, in bytes. + * + * @return int + */ + public function getAppendOffset() + { + return $this->appendOffset; + } + + /** + * Sets the offset at which the block was committed, in bytes. + * + * @param int $appendOffset append offset, in bytes. + * + * @return void + */ + protected function setAppendOffset($appendOffset) + { + $this->appendOffset = $appendOffset; + } + + /** + * Gets the number of committed blocks present in the blob. + * + * @return int + */ + public function getCommittedBlockCount() + { + return $this->committedBlockCount; + } + + /** + * Sets the number of committed blocks present in the blob. + * + * @param int $committedBlockCount the number of committed blocks present in the blob. + * + * @return void + */ + protected function setCommittedBlockCount($committedBlockCount) + { + $this->committedBlockCount = $committedBlockCount; + } + + /** + * Gets the whether the contents of the request are successfully encrypted. + * + * @return boolean + */ + public function getRequestServerEncrypted() + { + return $this->requestServerEncrypted; + } + + /** + * Sets the request server encryption value. + * + * @param boolean $requestServerEncrypted + * + * @return void + */ + public function setRequestServerEncrypted($requestServerEncrypted) + { + $this->requestServerEncrypted = $requestServerEncrypted; + } +} diff --git a/src/Blob/Models/Blob.php b/src/Blob/Models/Blob.php new file mode 100644 index 0000000..56a6d35 --- /dev/null +++ b/src/Blob/Models/Blob.php @@ -0,0 +1,153 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +/** + * Represents windows azure blob object + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class Blob +{ + private $_name; + private $_url; + private $_snapshot; + private $_metadata; + private $_properties; + /** + * Gets blob name. + * + * @return string + */ + public function getName() + { + return $this->_name; + } + + /** + * Sets blob name. + * + * @param string $name value. + * + * @return void + */ + public function setName($name) + { + $this->_name = $name; + } + + /** + * Gets blob snapshot. + * + * @return string + */ + public function getSnapshot() + { + return $this->_snapshot; + } + + /** + * Sets blob snapshot. + * + * @param string $snapshot value. + * + * @return void + */ + public function setSnapshot($snapshot) + { + $this->_snapshot = $snapshot; + } + + /** + * Gets blob url. + * + * @return string + */ + public function getUrl() + { + return $this->_url; + } + + /** + * Sets blob url. + * + * @param string $url value. + * + * @return void + */ + public function setUrl($url) + { + $this->_url = $url; + } + + /** + * Gets blob metadata. + * + * @return array + */ + public function getMetadata() + { + return $this->_metadata; + } + + /** + * Sets blob metadata. + * + * @param array $metadata value. + * + * @return void + */ + public function setMetadata(array $metadata = null) + { + $this->_metadata = $metadata; + } + + /** + * Gets blob properties. + * + * @return BlobProperties + */ + public function getProperties() + { + return $this->_properties; + } + + /** + * Sets blob properties. + * + * @param BlobProperties $properties value. + * + * @return void + */ + public function setProperties($properties) + { + $this->_properties = $properties; + } +} diff --git a/src/Blob/Models/BlobAccessPolicy.php b/src/Blob/Models/BlobAccessPolicy.php new file mode 100644 index 0000000..26bb4ba --- /dev/null +++ b/src/Blob/Models/BlobAccessPolicy.php @@ -0,0 +1,61 @@ + + * @copyright 2017 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Blob\Internal\BlobResources; +use MicrosoftAzure\Storage\Common\Models\AccessPolicy; + +/** + * Holds access policy elements + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2017 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class BlobAccessPolicy extends AccessPolicy +{ + /** + * Get the valid permissions for the given resource. + * + * @return array + */ + public static function getResourceValidPermissions() + { + return BlobResources::ACCESS_PERMISSIONS[ + BlobResources::RESOURCE_TYPE_BLOB + ]; + } + + /** + * Constructor + */ + public function __construct() + { + parent::__construct(BlobResources::RESOURCE_TYPE_BLOB); + } +} diff --git a/src/Blob/Models/BlobBlockType.php b/src/Blob/Models/BlobBlockType.php new file mode 100644 index 0000000..92f91b4 --- /dev/null +++ b/src/Blob/Models/BlobBlockType.php @@ -0,0 +1,64 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +/** + * Holds available blob block types + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class BlobBlockType +{ + const COMMITTED_TYPE = 'Committed'; + const UNCOMMITTED_TYPE = 'Uncommitted'; + const LATEST_TYPE = 'Latest'; + + /** + * Validates the provided type. + * + * @param string $type The entry type. + * + * @internal + * + * @return boolean + */ + public static function isValid($type) + { + switch ($type) { + case self::COMMITTED_TYPE: + case self::LATEST_TYPE: + case self::UNCOMMITTED_TYPE: + return true; + + default: + return false; + } + } +} diff --git a/src/Blob/Models/BlobPrefix.php b/src/Blob/Models/BlobPrefix.php new file mode 100644 index 0000000..10a9ea2 --- /dev/null +++ b/src/Blob/Models/BlobPrefix.php @@ -0,0 +1,62 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +/** + * Represents BlobPrefix object + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class BlobPrefix +{ + private $_name; + + /** + * Gets blob name. + * + * @return string + */ + public function getName() + { + return $this->_name; + } + + /** + * Sets blob name. + * + * @param string $name value. + * + * @return void + */ + public function setName($name) + { + $this->_name = $name; + } +} diff --git a/src/Blob/Models/BlobProperties.php b/src/Blob/Models/BlobProperties.php new file mode 100644 index 0000000..bcc6fda --- /dev/null +++ b/src/Blob/Models/BlobProperties.php @@ -0,0 +1,663 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Blob\Internal\BlobResources as Resources; +use MicrosoftAzure\Storage\Common\Internal\Validate; +use MicrosoftAzure\Storage\Common\Internal\Utilities; + +/** + * Represents blob properties + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class BlobProperties +{ + private $lastModified; + private $etag; + private $contentType; + private $contentLength; + private $contentEncoding; + private $contentLanguage; + private $contentMD5; + private $contentRange; + private $cacheControl; + private $contentDisposition; + private $blobType; + private $leaseStatus; + private $leaseState; + private $leaseDuration; + private $sequenceNumber; + private $serverEncrypted; + private $committedBlockCount; + private $copyState; + private $copyDestinationSnapshot; + private $incrementalCopy; + private $rangeContentMD5; + + /** + * Creates BlobProperties object from $parsed response in array representation of XML elements + * + * @param array $parsed parsed response in array format. + * + * @internal + * + * @return BlobProperties + */ + public static function createFromXml(array $parsed) + { + $result = new BlobProperties(); + $clean = array_change_key_case($parsed); + + $result->setCommonBlobProperties($clean); + $result->setLeaseStatus(Utilities::tryGetValue($clean, 'leasestatus')); + $result->setLeaseState(Utilities::tryGetValue($clean, 'leasestate')); + $result->setLeaseDuration(Utilities::tryGetValue($clean, 'leaseduration')); + $result->setCopyState(CopyState::createFromXml($clean)); + + $result->setIncrementalCopy( + Utilities::toBoolean( + Utilities::tryGetValue($clean, 'incrementalcopy'), + true + ) + ); + + return $result; + } + + /** + * Creates BlobProperties object from $parsed response in array representation of http headers + * + * @param array $parsed parsed response in array format. + * + * @internal + * + * @return BlobProperties + */ + public static function createFromHttpHeaders(array $parsed) + { + $result = new BlobProperties(); + $clean = array_change_key_case($parsed); + + $result->setCommonBlobProperties($clean); + + $result->setBlobType(Utilities::tryGetValue($clean, Resources::X_MS_BLOB_TYPE)); + $result->setLeaseStatus(Utilities::tryGetValue($clean, Resources::X_MS_LEASE_STATUS)); + $result->setLeaseState(Utilities::tryGetValue($clean, Resources::X_MS_LEASE_STATE)); + $result->setLeaseDuration(Utilities::tryGetValue($clean, Resources::X_MS_LEASE_DURATION)); + $result->setCopyState(CopyState::createFromHttpHeaders($clean)); + + $result->setServerEncrypted( + Utilities::toBoolean( + Utilities::tryGetValue( + $clean, + Resources::X_MS_SERVER_ENCRYPTED + ), + true + ) + ); + $result->setIncrementalCopy( + Utilities::toBoolean( + Utilities::tryGetValue( + $clean, + Resources::X_MS_INCREMENTAL_COPY + ), + true + ) + ); + $result->setCommittedBlockCount( + intval(Utilities::tryGetValue( + $clean, + Resources::X_MS_BLOB_COMMITTED_BLOCK_COUNT + )) + ); + $result->setCopyDestinationSnapshot( + Utilities::tryGetValue( + $clean, + Resources::X_MS_COPY_DESTINATION_SNAPSHOT + ) + ); + + return $result; + } + + /** + * Gets blob lastModified. + * + * @return \DateTime + */ + public function getLastModified() + { + return $this->lastModified; + } + + /** + * Sets blob lastModified. + * + * @param \DateTime $lastModified value. + * + * @return void + */ + public function setLastModified(\DateTime $lastModified) + { + Validate::isDate($lastModified); + $this->lastModified = $lastModified; + } + + /** + * Gets blob etag. + * + * @return string + */ + public function getETag() + { + return $this->etag; + } + + /** + * Sets blob etag. + * + * @param string $etag value. + * + * @return void + */ + public function setETag($etag) + { + $this->etag = $etag; + } + + /** + * Gets blob contentType. + * + * @return string + */ + public function getContentType() + { + return $this->contentType; + } + + /** + * Sets blob contentType. + * + * @param string $contentType value. + * + * @return void + */ + public function setContentType($contentType) + { + $this->contentType = $contentType; + } + + /** + * Gets blob contentRange. + * + * @return string + */ + public function getContentRange() + { + return $this->contentRange; + } + + /** + * Sets blob contentRange. + * + * @param string $contentRange value. + * + * @return void + */ + public function setContentRange($contentRange) + { + $this->contentRange = $contentRange; + } + + /** + * Gets blob contentLength. + * + * @return integer + */ + public function getContentLength() + { + return $this->contentLength; + } + + /** + * Sets blob contentLength. + * + * @param integer $contentLength value. + * + * @return void + */ + public function setContentLength($contentLength) + { + Validate::isInteger($contentLength, 'contentLength'); + $this->contentLength = $contentLength; + } + + /** + * Gets blob contentEncoding. + * + * @return string + */ + public function getContentEncoding() + { + return $this->contentEncoding; + } + + /** + * Sets blob contentEncoding. + * + * @param string $contentEncoding value. + * + * @return void + */ + public function setContentEncoding($contentEncoding) + { + $this->contentEncoding = $contentEncoding; + } + + /** + * Gets blob contentLanguage. + * + * @return string + */ + public function getContentLanguage() + { + return $this->contentLanguage; + } + + /** + * Sets blob contentLanguage. + * + * @param string $contentLanguage value. + * + * @return void + */ + public function setContentLanguage($contentLanguage) + { + $this->contentLanguage = $contentLanguage; + } + + /** + * Gets blob contentMD5. + * + * @return string + */ + public function getContentMD5() + { + return $this->contentMD5; + } + + /** + * Sets blob contentMD5. + * + * @param string $contentMD5 value. + * + * @return void + */ + public function setContentMD5($contentMD5) + { + $this->contentMD5 = $contentMD5; + } + + /** + * Gets blob range contentMD5. + * + * @return string + */ + public function getRangeContentMD5() + { + return $this->rangeContentMD5; + } + + /** + * Sets blob range contentMD5. + * + * @param string rangeContentMD5 value. + * + * @return void + */ + public function setRangeContentMD5($rangeContentMD5) + { + $this->rangeContentMD5 = $rangeContentMD5; + } + + /** + * Gets blob cacheControl. + * + * @return string + */ + public function getCacheControl() + { + return $this->cacheControl; + } + + /** + * Sets blob cacheControl. + * + * @param string $cacheControl value. + * + * @return void + */ + public function setCacheControl($cacheControl) + { + $this->cacheControl = $cacheControl; + } + + /** + * Gets blob contentDisposition. + * + * @return string + */ + public function getContentDisposition() + { + return $this->contentDisposition; + } + + /** + * Sets blob contentDisposition. + * + * @param string $contentDisposition value. + * + * @return void + */ + public function setContentDisposition($contentDisposition) + { + $this->contentDisposition = $contentDisposition; + } + + /** + * Gets blob blobType. + * + * @return string + */ + public function getBlobType() + { + return $this->blobType; + } + + /** + * Sets blob blobType. + * + * @param string $blobType value. + * + * @return void + */ + public function setBlobType($blobType) + { + $this->blobType = $blobType; + } + + /** + * Gets blob leaseStatus. + * + * @return string + */ + public function getLeaseStatus() + { + return $this->leaseStatus; + } + + /** + * Sets blob leaseStatus. + * + * @param string $leaseStatus value. + * + * @return void + */ + public function setLeaseStatus($leaseStatus) + { + $this->leaseStatus = $leaseStatus; + } + + /** + * Gets blob lease state. + * + * @return string + */ + public function getLeaseState() + { + return $this->leaseState; + } + + /** + * Sets blob lease state. + * + * @param string $leaseState value. + * + * @return void + */ + public function setLeaseState($leaseState) + { + $this->leaseState = $leaseState; + } + + /** + * Gets blob lease duration. + * + * @return string + */ + public function getLeaseDuration() + { + return $this->leaseDuration; + } + + /** + * Sets blob leaseStatus. + * + * @param string $leaseDuration value. + * + * @return void + */ + public function setLeaseDuration($leaseDuration) + { + $this->leaseDuration = $leaseDuration; + } + + /** + * Gets blob sequenceNumber. + * + * @return int + */ + public function getSequenceNumber() + { + return $this->sequenceNumber; + } + + /** + * Sets blob sequenceNumber. + * + * @param int $sequenceNumber value. + * + * @return void + */ + public function setSequenceNumber($sequenceNumber) + { + Validate::isInteger($sequenceNumber, 'sequenceNumber'); + $this->sequenceNumber = $sequenceNumber; + } + + /** + * Gets the server encryption status of the blob. + * + * @return boolean + */ + public function getServerEncrypted() + { + return $this->serverEncrypted; + } + + /** + * Sets the server encryption status of the blob. + * + * @param boolean $serverEncrypted + * + * @return void + */ + public function setServerEncrypted($serverEncrypted) + { + $this->serverEncrypted = $serverEncrypted; + } + + /** + * Gets the number of committed blocks present in the blob. + * + * @return int + */ + public function getCommittedBlockCount() + { + return $this->committedBlockCount; + } + + /** + * Sets the number of committed blocks present in the blob. + * + * @param int $committedBlockCount the number of committed blocks present in the blob. + * + * @return void + */ + public function setCommittedBlockCount($committedBlockCount) + { + $this->committedBlockCount = $committedBlockCount; + } + + /** + * Gets copy state of the blob. + * + * @return CopyState + */ + public function getCopyState() + { + return $this->copyState; + } + + /** + * Sets the copy state of the blob. + * + * @param CopyState $copyState the copy state of the blob. + * + * @return void + */ + public function setCopyState($copyState) + { + $this->copyState = $copyState; + } + + /** + * Gets snapshot time of the last successful incremental copy snapshot for this blob. + * + * @return string + */ + public function getCopyDestinationSnapshot() + { + return $this->copyDestinationSnapshot; + } + + /** + * Sets snapshot time of the last successful incremental copy snapshot for this blob. + * + * @param string $copyDestinationSnapshot last successful incremental copy snapshot. + */ + public function setCopyDestinationSnapshot($copyDestinationSnapshot) + { + $this->copyDestinationSnapshot = $copyDestinationSnapshot; + } + + /** + * Gets whether the blob is an incremental copy blob. + * + * @return boolean + */ + public function getIncrementalCopy() + { + return $this->incrementalCopy; + } + + /** + * Sets whether the blob is an incremental copy blob. + * + * @param boolean $incrementalCopy whether blob is an incremental copy blob. + */ + public function setIncrementalCopy($incrementalCopy) + { + $this->incrementalCopy = $incrementalCopy; + } + + private function setCommonBlobProperties(array $clean) + { + $date = Utilities::tryGetValue($clean, Resources::LAST_MODIFIED); + if (!is_null($date)) { + $date = Utilities::rfc1123ToDateTime($date); + $this->setLastModified($date); + } + + $this->setBlobType(Utilities::tryGetValue($clean, 'blobtype')); + + $this->setContentLength(intval($clean[Resources::CONTENT_LENGTH])); + $this->setETag(Utilities::tryGetValue($clean, Resources::ETAG)); + $this->setSequenceNumber( + intval( + Utilities::tryGetValue($clean, Resources::X_MS_BLOB_SEQUENCE_NUMBER) + ) + ); + $this->setContentRange( + Utilities::tryGetValue($clean, Resources::CONTENT_RANGE) + ); + $this->setCacheControl( + Utilities::tryGetValue($clean, Resources::CACHE_CONTROL) + ); + $this->setContentDisposition( + Utilities::tryGetValue($clean, Resources::CONTENT_DISPOSITION) + ); + $this->setContentEncoding( + Utilities::tryGetValue($clean, Resources::CONTENT_ENCODING) + ); + $this->setContentLanguage( + Utilities::tryGetValue($clean, Resources::CONTENT_LANGUAGE) + ); + $this->setContentType( + Utilities::tryGetValue($clean, Resources::CONTENT_TYPE) + ); + + if (Utilities::tryGetValue($clean, Resources::CONTENT_MD5) && + !Utilities::tryGetValue($clean, Resources::CONTENT_RANGE) + ) { + $this->setContentMD5( + Utilities::tryGetValue($clean, Resources::CONTENT_MD5) + ); + } else { + $this->setContentMD5( + Utilities::tryGetValue($clean, Resources::BLOB_CONTENT_MD5) + ); + $this->setRangeContentMD5( + Utilities::tryGetValue($clean, Resources::CONTENT_MD5) + ); + } + } +} diff --git a/src/Blob/Models/BlobServiceOptions.php b/src/Blob/Models/BlobServiceOptions.php new file mode 100644 index 0000000..b3b080c --- /dev/null +++ b/src/Blob/Models/BlobServiceOptions.php @@ -0,0 +1,92 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Common\Models\ServiceOptions; + +/** + * Blob service options. + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class BlobServiceOptions extends ServiceOptions +{ + private $_leaseId; + private $_accessConditions; + + /** + * Gets lease Id for the blob + * + * @return string + */ + public function getLeaseId() + { + return $this->_leaseId; + } + + /** + * Sets lease Id for the blob + * + * @param string $leaseId the blob lease id. + * + * @return void + */ + public function setLeaseId($leaseId) + { + $this->_leaseId = $leaseId; + } + + /** + * Gets access condition + * + * @return \MicrosoftAzure\Storage\Blob\Models\AccessCondition[] + */ + public function getAccessConditions() + { + return $this->_accessConditions; + } + + /** + * Sets access condition + * + * @param mixed $accessConditions value to use. + * + * @return void + */ + public function setAccessConditions($accessConditions) + { + if (!is_null($accessConditions) && + is_array($accessConditions)) { + $this->_accessConditions = $accessConditions; + } else { + $this->_accessConditions = [$accessConditions]; + } + } +} diff --git a/src/Blob/Models/BlobType.php b/src/Blob/Models/BlobType.php new file mode 100644 index 0000000..ec318a1 --- /dev/null +++ b/src/Blob/Models/BlobType.php @@ -0,0 +1,42 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +/** + * Encapsulates blob types + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class BlobType +{ + const BLOCK_BLOB = 'BlockBlob'; + const PAGE_BLOB = 'PageBlob'; + const APPEND_BLOB = 'AppendBlob'; +} diff --git a/src/Blob/Models/Block.php b/src/Blob/Models/Block.php new file mode 100644 index 0000000..ff8e7a8 --- /dev/null +++ b/src/Blob/Models/Block.php @@ -0,0 +1,97 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +/** + * Holds information about blob block. + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class Block +{ + private $_blockId; + private $_type; + + /** + * Constructor. + * + * @param string $blockId The ID of this block. + * @param string $type The type of the block. + */ + public function __construct($blockId = '', $type = '') + { + $this->_blockId = $blockId; + $this->_type = $type; + } + + /** + * Sets the blockId. + * + * @param string $blockId The id of the block. + * + * @return void + */ + public function setBlockId($blockId) + { + $this->_blockId = $blockId; + } + + /** + * Gets the blockId. + * + * @return string + */ + public function getBlockId() + { + return $this->_blockId; + } + + /** + * Sets the type. + * + * @param string $type The type of the block. + * + * @return void + */ + public function setType($type) + { + $this->_type = $type; + } + + /** + * Gets the type. + * + * @return string + */ + public function getType() + { + return $this->_type; + } +} diff --git a/src/Blob/Models/BlockList.php b/src/Blob/Models/BlockList.php new file mode 100644 index 0000000..2a03a46 --- /dev/null +++ b/src/Blob/Models/BlockList.php @@ -0,0 +1,172 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Blob\Internal\BlobResources as Resources; +use MicrosoftAzure\Storage\Common\Internal\Validate; +use MicrosoftAzure\Storage\Common\Internal\Serialization\XmlSerializer; + +/** + * Holds block list used for commitBlobBlocks + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class BlockList +{ + private $entries; + private static $xmlRootName = 'BlockList'; + + /** + * Creates block list from array of blocks. + * + * @param Block[] The blocks array. + * + * @return BlockList + */ + public static function create(array $array) + { + $blockList = new BlockList(); + + foreach ($array as $value) { + $blockList->addEntry($value->getBlockId(), $value->getType()); + } + + return $blockList; + } + + /** + * Adds new entry to the block list entries. + * + * @param string $blockId The block id. + * @param string $type The entry type, you can use BlobBlockType. + * + * @return void + */ + public function addEntry($blockId, $type) + { + Validate::canCastAsString($blockId, 'blockId'); + Validate::isTrue( + BlobBlockType::isValid($type), + sprintf(Resources::INVALID_BTE_MSG, get_class(new BlobBlockType())) + ); + $block = new Block(); + $block->setBlockId($blockId); + $block->setType($type); + + $this->entries[] = $block; + } + + /** + * Addds committed block entry. + * + * @param string $blockId The block id. + * + * @return void + */ + public function addCommittedEntry($blockId) + { + $this->addEntry($blockId, BlobBlockType::COMMITTED_TYPE); + } + + /** + * Addds uncommitted block entry. + * + * @param string $blockId The block id. + * + * @return void + */ + public function addUncommittedEntry($blockId) + { + $this->addEntry($blockId, BlobBlockType::UNCOMMITTED_TYPE); + } + + /** + * Addds latest block entry. + * + * @param string $blockId The block id. + * + * @return void + */ + public function addLatestEntry($blockId) + { + $this->addEntry($blockId, BlobBlockType::LATEST_TYPE); + } + + /** + * Gets blob block entry. + * + * @param string $blockId The id of the block. + * + * @return Block + */ + public function getEntry($blockId) + { + foreach ($this->entries as $value) { + if ($blockId == $value->getBlockId()) { + return $value; + } + } + + return null; + } + + /** + * Gets all blob block entries. + * + * @return Block[] + */ + public function getEntries() + { + return $this->entries; + } + + /** + * Converts the BlockList object to XML representation + * + * @param XmlSerializer $xmlSerializer The XML serializer. + * + * @internal + * + * @return string + */ + public function toXml(XmlSerializer $xmlSerializer) + { + $properties = array(XmlSerializer::ROOT_NAME => self::$xmlRootName); + $array = array(); + + foreach ($this->entries as $value) { + $array[] = array( + $value->getType() => $value->getBlockId() + ); + } + + return $xmlSerializer->serialize($array, $properties); + } +} diff --git a/src/Blob/Models/BreakLeaseResult.php b/src/Blob/Models/BreakLeaseResult.php new file mode 100644 index 0000000..3b30464 --- /dev/null +++ b/src/Blob/Models/BreakLeaseResult.php @@ -0,0 +1,83 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Blob\Internal\BlobResources as Resources; +use MicrosoftAzure\Storage\Common\Internal\Utilities; + +/** + * The result of calling breakLease API. + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class BreakLeaseResult +{ + private $_leaseTime; + + /** + * Creates BreakLeaseResult from response headers + * + * @param array $headers response headers + * + * @return BreakLeaseResult + */ + public static function create($headers) + { + $result = new BreakLeaseResult(); + + $result->setLeaseTime( + Utilities::tryGetValue($headers, Resources::X_MS_LEASE_TIME) + ); + + return $result; + } + + /** + * Gets lease time. + * + * @return string + */ + public function getLeaseTime() + { + return $this->_leaseTime; + } + + /** + * Sets lease time. + * + * @param string $leaseTime the blob lease time. + * + * @return void + */ + protected function setLeaseTime($leaseTime) + { + $this->_leaseTime = $leaseTime; + } +} diff --git a/src/Blob/Models/CommitBlobBlocksOptions.php b/src/Blob/Models/CommitBlobBlocksOptions.php new file mode 100644 index 0000000..c2d22f5 --- /dev/null +++ b/src/Blob/Models/CommitBlobBlocksOptions.php @@ -0,0 +1,223 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +/** + * Optional parameters for commitBlobBlocks + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class CommitBlobBlocksOptions extends BlobServiceOptions +{ + private $_contentType; + private $_contentEncoding; + private $_contentLanguage; + private $_contentMD5; + private $_cacheControl; + private $_contentDisposition; + private $_metadata; + + /** + * Gets ContentType. + * + * @return string + */ + public function getContentType() + { + return $this->_contentType; + } + + /** + * Sets ContentType. + * + * @param string $contentType value. + * + * @return void + */ + public function setContentType($contentType) + { + $this->_contentType = $contentType; + } + + /** + * Gets ContentEncoding. + * + * @return string + */ + public function getContentEncoding() + { + return $this->_contentEncoding; + } + + /** + * Sets ContentEncoding. + * + * @param string $contentEncoding value. + * + * @return void + */ + public function setContentEncoding($contentEncoding) + { + $this->_contentEncoding = $contentEncoding; + } + + /** + * Gets ContentLanguage. + * + * @return string + */ + public function getContentLanguage() + { + return $this->_contentLanguage; + } + + /** + * Sets ContentLanguage. + * + * @param string $contentLanguage value. + * + * @return void + */ + public function setContentLanguage($contentLanguage) + { + $this->_contentLanguage = $contentLanguage; + } + + /** + * Gets ContentMD5. + * + * @return string + */ + public function getContentMD5() + { + return $this->_contentMD5; + } + + /** + * Sets ContentMD5. + * + * @param string $contentMD5 value. + * + * @return void + */ + public function setContentMD5($contentMD5) + { + $this->_contentMD5 = $contentMD5; + } + + /** + * Gets cache control. + * + * @return string + */ + public function getCacheControl() + { + return $this->_cacheControl; + } + + /** + * Sets cacheControl. + * + * @param string $cacheControl value to use. + * + * @return void + */ + public function setCacheControl($cacheControl) + { + $this->_cacheControl = $cacheControl; + } + + /** + * Gets content disposition. + * + * @return string + */ + public function getContentDisposition() + { + return $this->_contentDisposition; + } + + /** + * Sets contentDisposition. + * + * @param string $contentDisposition value to use. + * + * @return void + */ + public function setContentDisposition($contentDisposition) + { + $this->_contentDisposition = $contentDisposition; + } + + /** + * Gets blob metadata. + * + * @return array + */ + public function getMetadata() + { + return $this->_metadata; + } + + /** + * Sets blob metadata. + * + * @param array $metadata value. + * + * @return void + */ + public function setMetadata(array $metadata = null) + { + $this->_metadata = $metadata; + } + + /** + * Create a instance using the given options + * @param mixed $options Input options + * + * @internal + * + * @return self + */ + public static function create($options) + { + $result = new CommitBlobBlocksOptions(); + $result->setContentType($options->getContentType()); + $result->setContentEncoding($options->getContentEncoding()); + $result->setContentLanguage($options->getContentLanguage()); + $result->setContentMD5($options->getContentMD5()); + $result->setCacheControl($options->getCacheControl()); + $result->setContentDisposition($options->getContentDisposition()); + $result->setMetadata($options->getMetadata()); + $result->setLeaseId($options->getLeaseId()); + + return $result; + } +} diff --git a/src/Blob/Models/Container.php b/src/Blob/Models/Container.php new file mode 100644 index 0000000..5ae31bf --- /dev/null +++ b/src/Blob/Models/Container.php @@ -0,0 +1,131 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +/** + * WindowsAzure container object. + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class Container +{ + private $_name; + private $_url; + private $_metadata; + private $_properties; + + /** + * Gets container name. + * + * @return string + */ + public function getName() + { + return $this->_name; + } + + /** + * Sets container name. + * + * @param string $name value. + * + * @return void + */ + public function setName($name) + { + $this->_name = $name; + } + + /** + * Gets container url. + * + * @return string + */ + public function getUrl() + { + return $this->_url; + } + + /** + * Sets container url. + * + * @param string $url value. + * + * @return void + */ + public function setUrl($url) + { + $this->_url = $url; + } + + /** + * Gets container metadata. + * + * @return array + */ + public function getMetadata() + { + return $this->_metadata; + } + + /** + * Sets container metadata. + * + * @param array $metadata value. + * + * @return void + */ + public function setMetadata(array $metadata = null) + { + $this->_metadata = $metadata; + } + + /** + * Gets container properties + * + * @return ContainerProperties + */ + public function getProperties() + { + return $this->_properties; + } + + /** + * Sets container properties + * + * @param ContainerProperties $properties container properties + * + * @return void + */ + public function setProperties(ContainerProperties $properties) + { + $this->_properties = $properties; + } +} diff --git a/src/Blob/Models/ContainerACL.php b/src/Blob/Models/ContainerACL.php new file mode 100644 index 0000000..339d01c --- /dev/null +++ b/src/Blob/Models/ContainerACL.php @@ -0,0 +1,164 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Common\Internal\ACLBase; +use MicrosoftAzure\Storage\Blob\Internal\BlobResources as Resources; +use MicrosoftAzure\Storage\Common\Internal\Validate; + +/** + * Holds container ACL members. + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class ContainerACL extends ACLBase +{ + private $publicAccess; + + /** + * Constructor. + */ + public function __construct() + { + //setting the resource type to a default value. + $this->setResourceType(Resources::RESOURCE_TYPE_CONTAINER); + } + + /** + * Parses the given array into signed identifiers and create an instance of + * ContainerACL + * + * @param string $publicAccess The container public access. + * @param array $parsed The parsed response into array representation. + * + * @internal + * + * @return ContainerACL + */ + public static function create($publicAccess, array $parsed = null) + { + Validate::isTrue( + PublicAccessType::isValid($publicAccess), + Resources::INVALID_BLOB_PAT_MSG + ); + $result = new ContainerACL(); + $result->fromXmlArray($parsed); + $result->setPublicAccess($publicAccess); + + return $result; + } + + /** + * Gets container publicAccess. + * + * @return string + */ + public function getPublicAccess() + { + return $this->publicAccess; + } + + /** + * Sets container publicAccess. + * + * @param string $publicAccess value. + * + * @return void + */ + public function setPublicAccess($publicAccess) + { + Validate::isTrue( + PublicAccessType::isValid($publicAccess), + Resources::INVALID_BLOB_PAT_MSG + ); + $this->publicAccess = $publicAccess; + $this->setResourceType( + self::getResourceTypeByPublicAccess($publicAccess) + ); + } + + /** + * Gets the resource type according to the given public access. Default + * value is Resources::RESOURCE_TYPE_CONTAINER. + * + * @param string $publicAccess The public access that determines the + * resource type. + * + * @return string + */ + private static function getResourceTypeByPublicAccess($publicAccess) + { + $result = ''; + + switch ($publicAccess) { + case PublicAccessType::BLOBS_ONLY: + $result = Resources::RESOURCE_TYPE_BLOB; + break; + case PublicAccessType::CONTAINER_AND_BLOBS: + $result = Resources::RESOURCE_TYPE_CONTAINER; + break; + default: + $result = Resources::RESOURCE_TYPE_CONTAINER; + break; + } + + return $result; + } + + /** + * Validate if the resource type is for the class. + * + * @param string $resourceType the resource type to be validated. + * + * @throws \InvalidArgumentException + * + * @internal + * + * @return void + */ + protected static function validateResourceType($resourceType) + { + Validate::isTrue( + $resourceType == Resources::RESOURCE_TYPE_BLOB || + $resourceType == Resources::RESOURCE_TYPE_CONTAINER, + Resources::INVALID_RESOURCE_TYPE + ); + } + + /** + * Create a ContainerAccessPolicy object. + * + * @return ContainerAccessPolicy + */ + protected static function createAccessPolicy() + { + return new ContainerAccessPolicy(); + } +} diff --git a/src/Blob/Models/ContainerAccessPolicy.php b/src/Blob/Models/ContainerAccessPolicy.php new file mode 100644 index 0000000..fcf24ed --- /dev/null +++ b/src/Blob/Models/ContainerAccessPolicy.php @@ -0,0 +1,61 @@ + + * @copyright 2017 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Blob\Internal\BlobResources; +use MicrosoftAzure\Storage\Common\Models\AccessPolicy; + +/** + * Holds access policy elements + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2017 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class ContainerAccessPolicy extends AccessPolicy +{ + /** + * Get the valid permissions for the given resource. + * + * @return array + */ + public static function getResourceValidPermissions() + { + return BlobResources::ACCESS_PERMISSIONS[ + BlobResources::RESOURCE_TYPE_CONTAINER + ]; + } + + /** + * Constructor + */ + public function __construct() + { + parent::__construct(BlobResources::RESOURCE_TYPE_CONTAINER); + } +} diff --git a/src/Blob/Models/ContainerProperties.php b/src/Blob/Models/ContainerProperties.php new file mode 100644 index 0000000..40a9703 --- /dev/null +++ b/src/Blob/Models/ContainerProperties.php @@ -0,0 +1,184 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Blob\Internal\BlobResources as Resources; +use MicrosoftAzure\Storage\Common\Internal\Validate; + +/** + * Holds container properties fields + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class ContainerProperties +{ + private $etag; + private $lastModified; + private $leaseDuration; + private $leaseStatus; + private $leaseState; + private $publicAccess; + + /** + * Gets container lastModified. + * + * @return \DateTime + */ + public function getLastModified() + { + return $this->lastModified; + } + + /** + * Sets container lastModified. + * + * @param \DateTime $lastModified value. + * + * @return void + */ + public function setLastModified(\DateTime $lastModified) + { + $this->lastModified = $lastModified; + } + + /** + * Gets container etag. + * + * @return string + */ + public function getETag() + { + return $this->etag; + } + + /** + * Sets container etag. + * + * @param string $etag value. + * + * @return void + */ + public function setETag($etag) + { + $this->etag = $etag; + } + + /** + * Gets blob leaseStatus. + * + * @return string + */ + public function getLeaseStatus() + { + return $this->leaseStatus; + } + + /** + * Sets blob leaseStatus. + * + * @param string $leaseStatus value. + * + * @return void + */ + public function setLeaseStatus($leaseStatus) + { + $this->leaseStatus = $leaseStatus; + } + + /** + * Gets blob lease state. + * + * @return string + */ + public function getLeaseState() + { + return $this->leaseState; + } + + /** + * Sets blob lease state. + * + * @param string $leaseState value. + * + * @return void + */ + public function setLeaseState($leaseState) + { + $this->leaseState = $leaseState; + } + + /** + * Gets blob lease duration. + * + * @return string + */ + public function getLeaseDuration() + { + return $this->leaseDuration; + } + + /** + * Sets blob leaseStatus. + * + * @param string $leaseDuration value. + * + * @return void + */ + public function setLeaseDuration($leaseDuration) + { + $this->leaseDuration = $leaseDuration; + } + + /** + * Gets container publicAccess. + * + * @return string + */ + public function getPublicAccess() + { + return $this->publicAccess; + } + + /** + * Sets container publicAccess. + * + * @param string $publicAccess value. + * + * @return void + */ + public function setPublicAccess($publicAccess) + { + Validate::isTrue( + PublicAccessType::isValid($publicAccess), + Resources::INVALID_BLOB_PAT_MSG + ); + $this->publicAccess = $publicAccess; + } +} diff --git a/src/Blob/Models/CopyBlobFromURLOptions.php b/src/Blob/Models/CopyBlobFromURLOptions.php new file mode 100644 index 0000000..cf0af8a --- /dev/null +++ b/src/Blob/Models/CopyBlobFromURLOptions.php @@ -0,0 +1,136 @@ + + * @copyright 2017 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +/** + * optional parameters for CopyBlobOptions wrapper + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2017 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class CopyBlobFromURLOptions extends BlobServiceOptions +{ + private $sourceLeaseId; + private $sourceAccessConditions; + private $metadata; + private $isIncrementalCopy; + + /** + * Gets source access condition + * + * @return AccessCondition[] + */ + public function getSourceAccessConditions() + { + return $this->sourceAccessConditions; + } + + /** + * Sets source access condition + * + * @param array $sourceAccessConditions value to use. + * + * @return void + */ + public function setSourceAccessConditions($sourceAccessConditions) + { + if (!is_null($sourceAccessConditions) && + is_array($sourceAccessConditions)) { + $this->sourceAccessConditions = $sourceAccessConditions; + } else { + $this->sourceAccessConditions = [$sourceAccessConditions]; + } + } + + /** + * Gets metadata. + * + * @return array + */ + public function getMetadata() + { + return $this->metadata; + } + + /** + * Sets metadata. + * + * @param array $metadata value. + * + * @return void + */ + public function setMetadata(array $metadata) + { + $this->metadata = $metadata; + } + + /** + * Gets source lease ID. + * + * @return string + */ + public function getSourceLeaseId() + { + return $this->sourceLeaseId; + } + + /** + * Sets source lease ID. + * + * @param string $sourceLeaseId value. + * + * @return void + */ + public function setSourceLeaseId($sourceLeaseId) + { + $this->sourceLeaseId = $sourceLeaseId; + } + + /** + * Gets isIncrementalCopy. + * + * @return boolean + */ + public function getIsIncrementalCopy() + { + return $this->isIncrementalCopy; + } + + /** + * Sets isIncrementalCopy. + * + * @param boolean $isIncrementalCopy + * + * @return void + */ + public function setIsIncrementalCopy($isIncrementalCopy) + { + $this->isIncrementalCopy = $isIncrementalCopy; + } +} diff --git a/src/Blob/Models/CopyBlobOptions.php b/src/Blob/Models/CopyBlobOptions.php new file mode 100644 index 0000000..b46d70e --- /dev/null +++ b/src/Blob/Models/CopyBlobOptions.php @@ -0,0 +1,62 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +/** + * optional parameters for CopyBlobOptions wrapper + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class CopyBlobOptions extends CopyBlobFromURLOptions +{ + private $sourceSnapshot; + + /** + * Gets source snapshot. + * + * @return string + */ + public function getSourceSnapshot() + { + return $this->sourceSnapshot; + } + + /** + * Sets source snapshot. + * + * @param string $sourceSnapshot value. + * + * @return void + */ + public function setSourceSnapshot($sourceSnapshot) + { + $this->sourceSnapshot = $sourceSnapshot; + } +} diff --git a/src/Blob/Models/CopyBlobResult.php b/src/Blob/Models/CopyBlobResult.php new file mode 100644 index 0000000..848cd16 --- /dev/null +++ b/src/Blob/Models/CopyBlobResult.php @@ -0,0 +1,179 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Blob\Internal\BlobResources as Resources; +use MicrosoftAzure\Storage\Common\Internal\Utilities; + +/** + * The result of calling copyBlob API. + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class CopyBlobResult +{ + private $_etag; + private $_lastModified; + private $_copyId; + private $_copyStatus; + + /** + * Creates CopyBlobResult object from the response of the copy blob request. + * + * @param array $headers The HTTP response headers in array representation. + * + * @internal + * + * @return CopyBlobResult + */ + public static function create(array $headers) + { + $result = new CopyBlobResult(); + $result->setETag( + Utilities::tryGetValueInsensitive( + Resources::ETAG, + $headers + ) + ); + $result->setCopyId( + Utilities::tryGetValueInsensitive( + Resources::X_MS_COPY_ID, + $headers + ) + ); + $result->setCopyStatus( + Utilities::tryGetValueInsensitive( + Resources::X_MS_COPY_STATUS, + $headers + ) + ); + if (Utilities::arrayKeyExistsInsensitive(Resources::LAST_MODIFIED, $headers)) { + $lastModified = Utilities::tryGetValueInsensitive( + Resources::LAST_MODIFIED, + $headers + ); + $result->setLastModified(Utilities::rfc1123ToDateTime($lastModified)); + } + + return $result; + } + + /** + * Gets copy Id + * + * @return string + */ + public function getCopyId() + { + return $this->_copyId; + } + + /** + * Sets copy Id + * + * @param string $copyId the blob copy id. + * + * @internal + * + * @return void + */ + protected function setCopyId($copyId) + { + $this->_copyId = $copyId; + } + + /** + * Gets copy status + * + * @return string + */ + public function getCopyStatus() + { + return $this->_copyStatus; + } + + /** + * Sets copy status + * + * @param string $status the copy status. + * + * @internal + * + * @return void + */ + protected function setCopyStatus($copystatus) + { + $this->_copyStatus = $copystatus; + } + + /** + * Gets ETag. + * + * @return string + */ + public function getETag() + { + return $this->_etag; + } + + /** + * Sets ETag. + * + * @param string $etag value. + * + * @return void + */ + protected function setETag($etag) + { + $this->_etag = $etag; + } + + /** + * Gets blob lastModified. + * + * @return \DateTime + */ + public function getLastModified() + { + return $this->_lastModified; + } + + /** + * Sets blob lastModified. + * + * @param \DateTime $lastModified value. + * + * @return void + */ + protected function setLastModified(\DateTime $lastModified) + { + $this->_lastModified = $lastModified; + } +} diff --git a/src/Blob/Models/CopyState.php b/src/Blob/Models/CopyState.php new file mode 100644 index 0000000..52ace6a --- /dev/null +++ b/src/Blob/Models/CopyState.php @@ -0,0 +1,294 @@ + + * @copyright 2017 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Blob\Internal\BlobResources as Resources; +use MicrosoftAzure\Storage\Common\Internal\Utilities; + +/** + * Represents blob copy state + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class CopyState +{ + private $_copyId; + private $_completionTime; + private $_status; + private $_statusDescription; + private $_source; + private $_bytesCopied; + private $_totalBytes; + + /** + * Creates CopyState object from $parsed response in array representation of XML elements + * + * @param array $parsed parsed response in array format. + * + * @internal + * + * @return \MicrosoftAzure\Storage\Blob\Models\CopyState + */ + public static function createFromXml(array $parsed) + { + $result = new CopyState(); + $clean = array_change_key_case($parsed); + + $copyCompletionTime = Utilities::tryGetValue($clean, 'copycompletiontime'); + if (!is_null($copyCompletionTime)) { + $copyCompletionTime = Utilities::rfc1123ToDateTime($copyCompletionTime); + $result->setCompletionTime($copyCompletionTime); + } + + $result->setCopyId(Utilities::tryGetValue($clean, 'copyid')); + $result->setStatus(Utilities::tryGetValue($clean, 'copystatus')); + $result->setStatusDescription(Utilities::tryGetValue($clean, 'copystatusdescription')); + $result->setSource(Utilities::tryGetValue($clean, 'copysource')); + + $copyProgress = Utilities::tryGetValue($clean, 'copyprogress'); + + if (strpos($copyProgress, '/') !== false) { + $parts = explode('/', $copyProgress); + $bytesCopied = intval($parts[0]); + $totalBytes = intval($parts[1]); + + $result->setBytesCopied($bytesCopied); + $result->setTotalBytes($totalBytes); + } + + return $result; + } + + /** + * Creates CopyState object from $parsed response in array representation of http headers + * + * @param array $parsed parsed response in array format. + * + * @internal + * + * @return \MicrosoftAzure\Storage\Blob\Models\CopyState + */ + public static function createFromHttpHeaders(array $parsed) + { + $result = new CopyState(); + $clean = array_change_key_case($parsed); + + $copyCompletionTime = Utilities::tryGetValue($clean, Resources::X_MS_COPY_COMPLETION_TIME); + if (!is_null($copyCompletionTime)) { + $copyCompletionTime = Utilities::rfc1123ToDateTime($copyCompletionTime); + $result->setCompletionTime($copyCompletionTime); + } + + $result->setCopyId(Utilities::tryGetValue($clean, Resources::X_MS_COPY_ID)); + $result->setStatus(Utilities::tryGetValue($clean, Resources::X_MS_COPY_STATUS)); + $result->setStatusDescription(Utilities::tryGetValue($clean, Resources::X_MS_COPY_STATUS_DESCRIPTION)); + $result->setSource(Utilities::tryGetValue($clean, Resources::X_MS_COPY_SOURCE)); + + $copyProgress = Utilities::tryGetValue($clean, Resources::X_MS_COPY_PROGRESS); + if (strpos($copyProgress, '/') !== false) { + $parts = explode('/', $copyProgress); + $bytesCopied = intval($parts[0]); + $totalBytes = intval($parts[1]); + + $result->setBytesCopied($bytesCopied); + $result->setTotalBytes($totalBytes); + } + + return $result; + } + + /** + * Gets copy Id + * + * @return string + */ + public function getCopyId() + { + return $this->_copyId; + } + + /** + * Sets copy Id + * + * @param string $copyId the blob copy id. + * + * @internal + * + * @return void + */ + protected function setCopyId($copyId) + { + $this->_copyId = $copyId; + } + + /** + * Gets copy completion time + * + * @return \DateTime + */ + public function getCompletionTime() + { + return $this->_completionTime; + } + + /** + * Sets copy completion time + * + * @param \DateTime $completionTime the copy completion time. + * + * @internal + * + * @return void + */ + protected function setCompletionTime($completionTime) + { + $this->_completionTime = $completionTime; + } + + /** + * Gets copy status + * + * @return string + */ + public function getStatus() + { + return $this->_status; + } + + /** + * Sets copy status + * + * @param string $status the copy status. + * + * @internal + * + * @return void + */ + protected function setStatus($status) + { + $this->_status = $status; + } + + /** + * Gets copy status description + * + * @return string + */ + public function getStatusDescription() + { + return $this->_statusDescription; + } + + /** + * Sets copy status description + * + * @param string $statusDescription the copy status description. + * + * @internal + * + * @return void + */ + protected function setStatusDescription($statusDescription) + { + $this->_statusDescription = $statusDescription; + } + + /** + * Gets copy source + * + * @return string + */ + public function getSource() + { + return $this->_source; + } + + /** + * Sets copy source + * + * @param string $source the copy source. + * + * @internal + * + * @return void + */ + protected function setSource($source) + { + $this->_source = $source; + } + + /** + * Gets bytes copied + * + * @return int + */ + public function getBytesCopied() + { + return $this->_bytesCopied; + } + + /** + * Sets bytes copied + * + * @param int $bytesCopied the bytes copied. + * + * @internal + * + * @return void + */ + protected function setBytesCopied($bytesCopied) + { + $this->_bytesCopied = $bytesCopied; + } + + /** + * Gets total bytes to be copied + * + * @return int + */ + public function getTotalBytes() + { + return $this->_bytesCopied; + } + + /** + * Sets total bytes to be copied + * + * @param int $totalBytes the bytes copied. + * + * @internal + * + * @return void + */ + protected function setTotalBytes($totalBytes) + { + $this->_totalBytes = $totalBytes; + } +} diff --git a/src/Blob/Models/CreateBlobBlockOptions.php b/src/Blob/Models/CreateBlobBlockOptions.php new file mode 100644 index 0000000..d4bbe85 --- /dev/null +++ b/src/Blob/Models/CreateBlobBlockOptions.php @@ -0,0 +1,101 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +/** + * Optional parameters for createBlobBlock wrapper + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class CreateBlobBlockOptions extends BlobServiceOptions +{ + private $_contentMD5; + private $_numberOfConcurrency; + + /** + * Gets blob contentMD5. + * + * @return string + */ + public function getContentMD5() + { + return $this->_contentMD5; + } + + /** + * Sets blob contentMD5. + * + * @param string $contentMD5 value. + * + * @return void + */ + public function setContentMD5($contentMD5) + { + $this->_contentMD5 = $contentMD5; + } + + /** + * Gets number of concurrency for sending a blob. + * + * @return int + */ + public function getNumberOfConcurrency() + { + return $this->_numberOfConcurrency; + } + + /** + * Sets number of concurrency for sending a blob. + * + * @param int $numberOfConcurrency the number of concurrent requests. + */ + public function setNumberOfConcurrency($numberOfConcurrency) + { + $this->_numberOfConcurrency = $numberOfConcurrency; + } + + /** + * Construct a CreateBlobBlockOptions object from a createBlobOptions. + * + * @param CreateBlobOptions $createBlobOptions + * + * @return CreateBlobBlockOptions + */ + public static function create(CreateBlobOptions $createBlobOptions) + { + $result = new CreateBlobBlockOptions(); + $result->setTimeout($createBlobOptions->getTimeout()); + $result->setLeaseId($createBlobOptions->getLeaseId()); + $result->setNumberOfConcurrency( + $createBlobOptions->getNumberOfConcurrency() + ); + return $result; + } +} diff --git a/src/Blob/Models/CreateBlobOptions.php b/src/Blob/Models/CreateBlobOptions.php new file mode 100644 index 0000000..6089b3c --- /dev/null +++ b/src/Blob/Models/CreateBlobOptions.php @@ -0,0 +1,247 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Common\Internal\Validate; + +/** + * optional parameters for createXXXBlob wrapper + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class CreateBlobOptions extends BlobServiceOptions +{ + private $_contentType; + private $_contentEncoding; + private $_contentLanguage; + private $_contentMD5; + private $_cacheControl; + private $_contentDisposition; + private $_metadata; + private $_sequenceNumber; + private $_numberOfConcurrency; + + /** + * Gets blob contentType. + * + * @return string + */ + public function getContentType() + { + return $this->_contentType; + } + + /** + * Sets blob contentType. + * + * @param string $contentType value. + * + * @return void + */ + public function setContentType($contentType) + { + $this->_contentType = $contentType; + } + + /** + * Gets contentEncoding. + * + * @return string + */ + public function getContentEncoding() + { + return $this->_contentEncoding; + } + + /** + * Sets contentEncoding. + * + * @param string $contentEncoding value. + * + * @return void + */ + public function setContentEncoding($contentEncoding) + { + $this->_contentEncoding = $contentEncoding; + } + + /** + * Gets contentLanguage. + * + * @return string + */ + public function getContentLanguage() + { + return $this->_contentLanguage; + } + + /** + * Sets contentLanguage. + * + * @param string $contentLanguage value. + * + * @return void + */ + public function setContentLanguage($contentLanguage) + { + $this->_contentLanguage = $contentLanguage; + } + + /** + * Gets contentMD5. + * + * @return string + */ + public function getContentMD5() + { + return $this->_contentMD5; + } + + /** + * Sets contentMD5. + * + * @param string $contentMD5 value. + * + * @return void + */ + public function setContentMD5($contentMD5) + { + $this->_contentMD5 = $contentMD5; + } + + /** + * Gets cacheControl. + * + * @return string + */ + public function getCacheControl() + { + return $this->_cacheControl; + } + + /** + * Sets cacheControl. + * + * @param string $cacheControl value to use. + * + * @return void + */ + public function setCacheControl($cacheControl) + { + $this->_cacheControl = $cacheControl; + } + + /** + * Gets content disposition. + * + * @return string + */ + public function getContentDisposition() + { + return $this->_contentDisposition; + } + + /** + * Sets content disposition. + * + * @param string $contentDisposition value to use. + * + * @return void + */ + public function setContentDisposition($contentDisposition) + { + $this->_contentDisposition = $contentDisposition; + } + + /** + * Gets blob metadata. + * + * @return array + */ + public function getMetadata() + { + return $this->_metadata; + } + + /** + * Sets blob metadata. + * + * @param array $metadata value. + * + * @return void + */ + public function setMetadata(array $metadata) + { + $this->_metadata = $metadata; + } + + /** + * Gets blob sequenceNumber. + * + * @return int + */ + public function getSequenceNumber() + { + return $this->_sequenceNumber; + } + + /** + * Sets blob sequenceNumber. + * + * @param int $sequenceNumber value. + * + * @return void + */ + public function setSequenceNumber($sequenceNumber) + { + Validate::isInteger($sequenceNumber, 'sequenceNumber'); + $this->_sequenceNumber = $sequenceNumber; + } + + /** + * Gets number of concurrency for sending a blob. + * + * @return int + */ + public function getNumberOfConcurrency() + { + return $this->_numberOfConcurrency; + } + + /** + * Sets number of concurrency for sending a blob. + * + * @param int $numberOfConcurrency the number of concurrent requests. + */ + public function setNumberOfConcurrency($numberOfConcurrency) + { + $this->_numberOfConcurrency = $numberOfConcurrency; + } +} diff --git a/src/Blob/Models/CreateBlobPagesOptions.php b/src/Blob/Models/CreateBlobPagesOptions.php new file mode 100644 index 0000000..6ee39f3 --- /dev/null +++ b/src/Blob/Models/CreateBlobPagesOptions.php @@ -0,0 +1,62 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +/** + * Optional parameters for create and clear blob pages + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class CreateBlobPagesOptions extends BlobServiceOptions +{ + private $_contentMD5; + + /** + * Gets blob contentMD5. + * + * @return string + */ + public function getContentMD5() + { + return $this->_contentMD5; + } + + /** + * Sets blob contentMD5. + * + * @param string $contentMD5 value. + * + * @return void + */ + public function setContentMD5($contentMD5) + { + $this->_contentMD5 = $contentMD5; + } +} diff --git a/src/Blob/Models/CreateBlobPagesResult.php b/src/Blob/Models/CreateBlobPagesResult.php new file mode 100644 index 0000000..61c7c40 --- /dev/null +++ b/src/Blob/Models/CreateBlobPagesResult.php @@ -0,0 +1,207 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Blob\Internal\BlobResources as Resources; +use MicrosoftAzure\Storage\Common\Internal\Validate; +use MicrosoftAzure\Storage\Common\Internal\Utilities; + +/** + * Holds result of calling create or clear blob pages + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class CreateBlobPagesResult +{ + private $contentMD5; + private $etag; + private $lastModified; + private $requestServerEncrypted; + private $sequenceNumber; + + /** + * Creates CreateBlobPagesResult object from $parsed response in array + * representation + * + * @param array $headers HTTP response headers + * + * @internal + * + * @return CreateBlobPagesResult + */ + public static function create(array $headers) + { + $result = new CreateBlobPagesResult(); + $clean = array_change_key_case($headers); + + $date = $clean[Resources::LAST_MODIFIED]; + $date = Utilities::rfc1123ToDateTime($date); + $result->setETag($clean[Resources::ETAG]); + $result->setLastModified($date); + + $result->setContentMD5( + Utilities::tryGetValue($clean, Resources::CONTENT_MD5) + ); + + $result->setRequestServerEncrypted( + Utilities::toBoolean( + Utilities::tryGetValueInsensitive( + Resources::X_MS_REQUEST_SERVER_ENCRYPTED, + $headers + ), + true + ) + ); + + $result->setSequenceNumber( + intval( + Utilities::tryGetValue( + $clean, + Resources::X_MS_BLOB_SEQUENCE_NUMBER + ) + ) + ); + + return $result; + } + + /** + * Gets blob lastModified. + * + * @return \DateTime. + */ + public function getLastModified() + { + return $this->lastModified; + } + + /** + * Sets blob lastModified. + * + * @param \DateTime $lastModified value. + * + * @return void + */ + protected function setLastModified($lastModified) + { + Validate::isDate($lastModified); + $this->lastModified = $lastModified; + } + + /** + * Gets blob etag. + * + * @return string + */ + public function getETag() + { + return $this->etag; + } + + /** + * Sets blob etag. + * + * @param string $etag value. + * + * @return void + */ + protected function setETag($etag) + { + Validate::canCastAsString($etag, 'etag'); + $this->etag = $etag; + } + + /** + * Gets blob contentMD5. + * + * @return string + */ + public function getContentMD5() + { + return $this->contentMD5; + } + + /** + * Sets blob contentMD5. + * + * @param string $contentMD5 value. + * + * @return void + */ + protected function setContentMD5($contentMD5) + { + $this->contentMD5 = $contentMD5; + } + + /** + * Gets the whether the contents of the request are successfully encrypted. + * + * @return boolean + */ + public function getRequestServerEncrypted() + { + return $this->requestServerEncrypted; + } + + /** + * Sets the request server encryption value. + * + * @param boolean $requestServerEncrypted + * + * @return void + */ + public function setRequestServerEncrypted($requestServerEncrypted) + { + $this->requestServerEncrypted = $requestServerEncrypted; + } + + /** + * Gets blob sequenceNumber. + * + * @return int + */ + public function getSequenceNumber() + { + return $this->sequenceNumber; + } + + /** + * Sets blob sequenceNumber. + * + * @param int $sequenceNumber value. + * + * @return void + */ + protected function setSequenceNumber($sequenceNumber) + { + Validate::isInteger($sequenceNumber, 'sequenceNumber'); + $this->sequenceNumber = $sequenceNumber; + } +} diff --git a/src/Blob/Models/CreateBlobSnapshotOptions.php b/src/Blob/Models/CreateBlobSnapshotOptions.php new file mode 100644 index 0000000..e5f4230 --- /dev/null +++ b/src/Blob/Models/CreateBlobSnapshotOptions.php @@ -0,0 +1,62 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +/** + * The optional parameters for createBlobSnapshot wrapper. + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class CreateBlobSnapshotOptions extends BlobServiceOptions +{ + private $_metadata; + + /** + * Gets metadata. + * + * @return array + */ + public function getMetadata() + { + return $this->_metadata; + } + + /** + * Sets metadata. + * + * @param array $metadata The metadata array. + * + * @return void + */ + public function setMetadata(array $metadata) + { + $this->_metadata = $metadata; + } +} diff --git a/src/Blob/Models/CreateBlobSnapshotResult.php b/src/Blob/Models/CreateBlobSnapshotResult.php new file mode 100644 index 0000000..89c611b --- /dev/null +++ b/src/Blob/Models/CreateBlobSnapshotResult.php @@ -0,0 +1,139 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Blob\Internal\BlobResources as Resources; +use MicrosoftAzure\Storage\Common\Internal\Utilities; + +/** + * The result of creating Blob snapshot. + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class CreateBlobSnapshotResult +{ + private $_snapshot; + private $_etag; + private $_lastModified; + + /** + * Creates CreateBlobSnapshotResult object from the response of the + * create Blob snapshot request. + * + * @param array $headers The HTTP response headers in array representation. + * + * @internal + * + * @return CreateBlobSnapshotResult + */ + public static function create(array $headers) + { + $result = new CreateBlobSnapshotResult(); + $headerWithLowerCaseKey = array_change_key_case($headers); + + $result->setETag($headerWithLowerCaseKey[Resources::ETAG]); + + $result->setLastModified( + Utilities::rfc1123ToDateTime( + $headerWithLowerCaseKey[Resources::LAST_MODIFIED] + ) + ); + + $result->setSnapshot($headerWithLowerCaseKey[Resources::X_MS_SNAPSHOT]); + + return $result; + } + + /** + * Gets snapshot. + * + * @return string + */ + public function getSnapshot() + { + return $this->_snapshot; + } + + /** + * Sets snapshot. + * + * @param string $snapshot value. + * + * @return void + */ + protected function setSnapshot($snapshot) + { + $this->_snapshot = $snapshot; + } + + /** + * Gets ETag. + * + * @return string + */ + public function getETag() + { + return $this->_etag; + } + + /** + * Sets ETag. + * + * @param string $etag value. + * + * @return void + */ + protected function setETag($etag) + { + $this->_etag = $etag; + } + + /** + * Gets blob lastModified. + * + * @return \DateTime + */ + public function getLastModified() + { + return $this->_lastModified; + } + + /** + * Sets blob lastModified. + * + * @param \DateTime $lastModified value. + * + * @return void + */ + protected function setLastModified($lastModified) + { + $this->_lastModified = $lastModified; + } +} diff --git a/src/Blob/Models/CreateBlockBlobOptions.php b/src/Blob/Models/CreateBlockBlobOptions.php new file mode 100644 index 0000000..3b3946f --- /dev/null +++ b/src/Blob/Models/CreateBlockBlobOptions.php @@ -0,0 +1,42 @@ + + * @copyright 2018 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Common\Models\TransactionalMD5Trait; + +/** + * Optional parameters for CreateBlockBlob. + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2018 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class CreateBlockBlobOptions extends CreateBlobOptions +{ + use TransactionalMD5Trait; +} diff --git a/src/Blob/Models/CreateContainerOptions.php b/src/Blob/Models/CreateContainerOptions.php new file mode 100644 index 0000000..a825338 --- /dev/null +++ b/src/Blob/Models/CreateContainerOptions.php @@ -0,0 +1,113 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Common\Internal\Validate; + +/** + * Optional parameters for createContainer API + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class CreateContainerOptions extends BlobServiceOptions +{ + private $_publicAccess; + private $_metadata; + + /** + * Gets container public access. + * + * @return string + */ + public function getPublicAccess() + { + return $this->_publicAccess; + } + + /** + * Specifies whether data in the container may be accessed publicly and the level + * of access. Possible values include: + * 1) container: Specifies full public read access for container and blob data. + * Clients can enumerate blobs within the container via anonymous request, but + * cannot enumerate containers within the storage account. + * 2) blob: Specifies public read access for blobs. Blob data within this + * container can be read via anonymous request, but container data is not + * available. Clients cannot enumerate blobs within the container via + * anonymous request. + * If this value is not specified in the request, container data is private to + * the account owner. + * + * @param string $publicAccess access modifier for the container + * + * @return void + */ + public function setPublicAccess($publicAccess) + { + Validate::canCastAsString($publicAccess, 'publicAccess'); + $this->_publicAccess = $publicAccess; + } + + /** + * Gets user defined metadata. + * + * @return array + */ + public function getMetadata() + { + return $this->_metadata; + } + + /** + * Sets user defined metadata. This metadata should be added without the header + * prefix (x-ms-meta-*). + * + * @param array $metadata user defined metadata object in array form. + * + * @return void + */ + public function setMetadata(array $metadata) + { + $this->_metadata = $metadata; + } + + /** + * Adds new metadata element. This element should be added without the header + * prefix (x-ms-meta-*). + * + * @param string $key metadata key element. + * @param string $value metadata value element. + * + * @return void + */ + public function addMetadata($key, $value) + { + $this->_metadata[$key] = $value; + } +} diff --git a/src/Blob/Models/CreatePageBlobFromContentOptions.php b/src/Blob/Models/CreatePageBlobFromContentOptions.php new file mode 100644 index 0000000..2f12987 --- /dev/null +++ b/src/Blob/Models/CreatePageBlobFromContentOptions.php @@ -0,0 +1,42 @@ + + * @copyright 2018 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Common\Models\TransactionalMD5Trait; + +/** + * Optional parameters for createPageBlobFromContent. + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2018 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class CreatePageBlobFromContentOptions extends CreateBlobOptions +{ + use TransactionalMD5Trait; +} diff --git a/src/Blob/Models/DeleteBlobOptions.php b/src/Blob/Models/DeleteBlobOptions.php new file mode 100644 index 0000000..2bbed7f --- /dev/null +++ b/src/Blob/Models/DeleteBlobOptions.php @@ -0,0 +1,88 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Common\Internal\Validate; + +/** + * Optional parameters for deleteBlob wrapper + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class DeleteBlobOptions extends BlobServiceOptions +{ + private $_snapshot; + private $_deleteSnaphotsOnly; + + /** + * Gets blob snapshot. + * + * @return string + */ + public function getSnapshot() + { + return $this->_snapshot; + } + + /** + * Sets blob snapshot. + * + * @param string $snapshot value. + * + * @return void + */ + public function setSnapshot($snapshot) + { + $this->_snapshot = $snapshot; + } + + /** + * Gets blob deleteSnaphotsOnly. + * + * @return boolean + */ + public function getDeleteSnaphotsOnly() + { + return $this->_deleteSnaphotsOnly; + } + + /** + * Sets blob deleteSnaphotsOnly. + * + * @param string $deleteSnaphotsOnly value. + * + * @return boolean + */ + public function setDeleteSnaphotsOnly($deleteSnaphotsOnly) + { + Validate::isBoolean($deleteSnaphotsOnly); + $this->_deleteSnaphotsOnly = $deleteSnaphotsOnly; + } +} diff --git a/src/Blob/Models/GetBlobMetadataOptions.php b/src/Blob/Models/GetBlobMetadataOptions.php new file mode 100644 index 0000000..2b7695a --- /dev/null +++ b/src/Blob/Models/GetBlobMetadataOptions.php @@ -0,0 +1,62 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +/** + * Optional parameters for getBlobMetadata wrapper + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class GetBlobMetadataOptions extends BlobServiceOptions +{ + private $_snapshot; + + /** + * Gets blob snapshot. + * + * @return string + */ + public function getSnapshot() + { + return $this->_snapshot; + } + + /** + * Sets blob snapshot. + * + * @param string $snapshot value. + * + * @return void + */ + public function setSnapshot($snapshot) + { + $this->_snapshot = $snapshot; + } +} diff --git a/src/Blob/Models/GetBlobMetadataResult.php b/src/Blob/Models/GetBlobMetadataResult.php new file mode 100644 index 0000000..f9c1bcd --- /dev/null +++ b/src/Blob/Models/GetBlobMetadataResult.php @@ -0,0 +1,54 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Common\Internal\MetadataTrait; + +/** + * Holds results of calling getBlobMetadata wrapper + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class GetBlobMetadataResult +{ + use MetadataTrait; + + /** + * Creates the instance from the parsed headers. + * + * @param array $parsed Parsed headers + * + * @return GetBlobMetadataResult + */ + public static function create(array $parsed) + { + return static::createMetadataResult($parsed); + } +} diff --git a/src/Blob/Models/GetBlobOptions.php b/src/Blob/Models/GetBlobOptions.php new file mode 100644 index 0000000..20ee494 --- /dev/null +++ b/src/Blob/Models/GetBlobOptions.php @@ -0,0 +1,112 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Common\Internal\Validate; +use MicrosoftAzure\Storage\Common\Models\Range; + +/** + * Optional parameters for getBlob wrapper + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class GetBlobOptions extends BlobServiceOptions +{ + private $snapshot; + private $range; + private $rangeGetContentMD5; + + /** + * Gets blob snapshot. + * + * @return string + */ + public function getSnapshot() + { + return $this->snapshot; + } + + /** + * Sets blob snapshot. + * + * @param string $snapshot value. + * + * @return void + */ + public function setSnapshot($snapshot) + { + $this->snapshot = $snapshot; + } + + /** + * Gets Blob range. + * + * @return Range + */ + public function getRange() + { + return $this->range; + } + + /** + * Sets Blob range. + * + * @param Range $range value. + * + * @return void + */ + public function setRange(Range $range) + { + $this->range = $range; + } + + /** + * Gets rangeGetContentMD5 + * + * @return boolean + */ + public function getRangeGetContentMD5() + { + return $this->rangeGetContentMD5; + } + + /** + * Sets rangeGetContentMD5 + * + * @param boolean $rangeGetContentMD5 value + * + * @return void + */ + public function setRangeGetContentMD5($rangeGetContentMD5) + { + Validate::isBoolean($rangeGetContentMD5); + $this->rangeGetContentMD5 = $rangeGetContentMD5; + } +} diff --git a/src/Blob/Models/GetBlobPropertiesOptions.php b/src/Blob/Models/GetBlobPropertiesOptions.php new file mode 100644 index 0000000..833939a --- /dev/null +++ b/src/Blob/Models/GetBlobPropertiesOptions.php @@ -0,0 +1,62 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +/** + * Optional parameters for getBlobProperties wrapper + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class GetBlobPropertiesOptions extends BlobServiceOptions +{ + private $_snapshot; + + /** + * Gets blob snapshot. + * + * @return string + */ + public function getSnapshot() + { + return $this->_snapshot; + } + + /** + * Sets blob snapshot. + * + * @param string $snapshot value. + * + * @return void + */ + public function setSnapshot($snapshot) + { + $this->_snapshot = $snapshot; + } +} diff --git a/src/Blob/Models/GetBlobPropertiesResult.php b/src/Blob/Models/GetBlobPropertiesResult.php new file mode 100644 index 0000000..c5e4c04 --- /dev/null +++ b/src/Blob/Models/GetBlobPropertiesResult.php @@ -0,0 +1,84 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Common\Internal\MetadataTrait; + +/** + * Holds result of calling getBlobProperties + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class GetBlobPropertiesResult +{ + use MetadataTrait; + + private $_properties; + + /** + * Gets blob properties. + * + * @return BlobProperties + */ + public function getProperties() + { + return $this->_properties; + } + + /** + * Sets blob properties. + * + * @param BlobProperties $properties value. + * + * @return void + */ + protected function setProperties($properties) + { + $this->_properties = $properties; + } + + /** + * Create a instance using the given headers. + * + * @param array $headers response headers parsed in an array + * + * @internal + * + * @return GetBlobPropertiesResult + */ + public static function create(array $headers) + { + $result = static::createMetadataResult($headers); + + $result->setProperties(BlobProperties::createFromHttpHeaders($headers)); + + return $result; + } +} diff --git a/src/Blob/Models/GetBlobResult.php b/src/Blob/Models/GetBlobResult.php new file mode 100644 index 0000000..b12cb63 --- /dev/null +++ b/src/Blob/Models/GetBlobResult.php @@ -0,0 +1,134 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use Psr\Http\Message\StreamInterface; + +/** + * Holds result of GetBlob API. + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class GetBlobResult +{ + private $properties; + private $metadata; + private $contentStream; + + /** + * Creates GetBlobResult from getBlob call. + * + * @param array $headers The HTTP response headers. + * @param StreamInterface $body The response body. + * @param array $metadata The blob metadata. + * + * @internal + * + * @return GetBlobResult + */ + public static function create( + array $headers, + StreamInterface $body, + array $metadata + ) { + $result = new GetBlobResult(); + $result->setContentStream($body->detach()); + $result->setProperties(BlobProperties::createFromHttpHeaders($headers)); + $result->setMetadata(is_null($metadata) ? array() : $metadata); + + return $result; + } + + /** + * Gets blob metadata. + * + * @return array + */ + public function getMetadata() + { + return $this->metadata; + } + + /** + * Sets blob metadata. + * + * @param array $metadata value. + * + * @return void + */ + protected function setMetadata(array $metadata) + { + $this->metadata = $metadata; + } + + /** + * Gets blob properties. + * + * @return BlobProperties + */ + public function getProperties() + { + return $this->properties; + } + + /** + * Sets blob properties. + * + * @param BlobProperties $properties value. + * + * @return void + */ + protected function setProperties(BlobProperties $properties) + { + $this->properties = $properties; + } + + /** + * Gets blob contentStream. + * + * @return \resource + */ + public function getContentStream() + { + return $this->contentStream; + } + + /** + * Sets blob contentStream. + * + * @param \resource $contentStream The stream handle. + * + * @return void + */ + protected function setContentStream($contentStream) + { + $this->contentStream = $contentStream; + } +} diff --git a/src/Blob/Models/GetContainerACLResult.php b/src/Blob/Models/GetContainerACLResult.php new file mode 100644 index 0000000..1876b6d --- /dev/null +++ b/src/Blob/Models/GetContainerACLResult.php @@ -0,0 +1,137 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +/** + * Holds container ACL + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class GetContainerACLResult +{ + private $containerACL; + private $lastModified; + + private $etag; + + /** + * Parses the given array into signed identifiers + * + * @param string $publicAccess container public access + * @param string $etag container etag + * @param \DateTime $lastModified last modification date + * @param array $parsed parsed response into array + * representation + * + * @internal + * + * @return self + */ + public static function create( + $publicAccess, + $etag, + \DateTime $lastModified, + array $parsed = null + ) { + $result = new GetContainerAclResult(); + $result->setETag($etag); + $result->setLastModified($lastModified); + $acl = ContainerACL::create($publicAccess, $parsed); + $result->setContainerAcl($acl); + + return $result; + } + + /** + * Gets container ACL + * + * @return ContainerACL + */ + public function getContainerAcl() + { + return $this->containerACL; + } + + /** + * Sets container ACL + * + * @param ContainerACL $containerACL value. + * + * @return void + */ + protected function setContainerAcl(ContainerACL $containerACL) + { + $this->containerACL = $containerACL; + } + + /** + * Gets container lastModified. + * + * @return \DateTime. + */ + public function getLastModified() + { + return $this->lastModified; + } + + /** + * Sets container lastModified. + * + * @param \DateTime $lastModified value. + * + * @return void + */ + protected function setLastModified(\DateTime $lastModified) + { + $this->lastModified = $lastModified; + } + + /** + * Gets container etag. + * + * @return string + */ + public function getETag() + { + return $this->etag; + } + + /** + * Sets container etag. + * + * @param string $etag value. + * + * @return void + */ + protected function setETag($etag) + { + $this->etag = $etag; + } +} diff --git a/src/Blob/Models/GetContainerPropertiesResult.php b/src/Blob/Models/GetContainerPropertiesResult.php new file mode 100644 index 0000000..dea7855 --- /dev/null +++ b/src/Blob/Models/GetContainerPropertiesResult.php @@ -0,0 +1,175 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Common\Internal\MetadataTrait; +use MicrosoftAzure\Storage\Blob\Internal\BlobResources as Resources; +use MicrosoftAzure\Storage\Common\Internal\Utilities; +use MicrosoftAzure\Storage\Common\Internal\Validate; + +/** + * Holds result of getContainerProperties and getContainerMetadata + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class GetContainerPropertiesResult +{ + use MetadataTrait; + + private $leaseStatus; + private $leaseState; + private $leaseDuration; + private $publicAccess; + + /** + * Gets blob leaseStatus. + * + * @return string + */ + public function getLeaseStatus() + { + return $this->leaseStatus; + } + + /** + * Sets blob leaseStatus. + * + * @param string $leaseStatus value. + * + * @return void + */ + public function setLeaseStatus($leaseStatus) + { + $this->leaseStatus = $leaseStatus; + } + + /** + * Gets blob lease state. + * + * @return string + */ + public function getLeaseState() + { + return $this->leaseState; + } + + /** + * Sets blob lease state. + * + * @param string $leaseState value. + * + * @return void + */ + public function setLeaseState($leaseState) + { + $this->leaseState = $leaseState; + } + + /** + * Gets blob lease duration. + * + * @return string + */ + public function getLeaseDuration() + { + return $this->leaseDuration; + } + + /** + * Sets blob leaseStatus. + * + * @param string $leaseDuration value. + * + * @return void + */ + public function setLeaseDuration($leaseDuration) + { + $this->leaseDuration = $leaseDuration; + } + + /** + * Gets container publicAccess. + * + * @return string + */ + public function getPublicAccess() + { + return $this->publicAccess; + } + + /** + * Sets container publicAccess. + * + * @param string $publicAccess value. + * + * @return void + */ + public function setPublicAccess($publicAccess) + { + Validate::isTrue( + PublicAccessType::isValid($publicAccess), + Resources::INVALID_BLOB_PAT_MSG + ); + $this->publicAccess = $publicAccess; + } + + /** + * Create an instance using the response headers from the API call. + * + * @param array $responseHeaders The array contains all the response headers + * + * @internal + * + * @return GetContainerPropertiesResult + */ + public static function create(array $responseHeaders) + { + $result = static::createMetadataResult($responseHeaders); + + $result->setLeaseStatus(Utilities::tryGetValueInsensitive( + Resources::X_MS_LEASE_STATUS, + $responseHeaders + )); + $result->setLeaseState(Utilities::tryGetValueInsensitive( + Resources::X_MS_LEASE_STATE, + $responseHeaders + )); + $result->setLeaseDuration(Utilities::tryGetValueInsensitive( + Resources::X_MS_LEASE_DURATION, + $responseHeaders + )); + $result->setPublicAccess(Utilities::tryGetValueInsensitive( + Resources::X_MS_BLOB_PUBLIC_ACCESS, + $responseHeaders + )); + + return $result; + } +} diff --git a/src/Blob/Models/LeaseMode.php b/src/Blob/Models/LeaseMode.php new file mode 100644 index 0000000..9f3f631 --- /dev/null +++ b/src/Blob/Models/LeaseMode.php @@ -0,0 +1,44 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +/** + * Modes for leasing a blob + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class LeaseMode +{ + const ACQUIRE_ACTION = 'acquire'; + const RENEW_ACTION = 'renew'; + const RELEASE_ACTION = 'release'; + const BREAK_ACTION = 'break'; + const CHANGE_ACTION = 'change'; +} diff --git a/src/Blob/Models/LeaseResult.php b/src/Blob/Models/LeaseResult.php new file mode 100644 index 0000000..271909f --- /dev/null +++ b/src/Blob/Models/LeaseResult.php @@ -0,0 +1,85 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Blob\Internal\BlobResources as Resources; +use MicrosoftAzure\Storage\Common\Internal\Utilities; + +/** + * The result of calling acquireLease API. + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class LeaseResult +{ + private $leaseId; + + /** + * Creates LeaseResult from response headers + * + * @param array $headers response headers + * + * @internal + * + * @return \MicrosoftAzure\Storage\Blob\Models\LeaseResult + */ + public static function create(array $headers) + { + $result = new LeaseResult(); + + $result->setLeaseId( + Utilities::tryGetValue($headers, Resources::X_MS_LEASE_ID) + ); + + return $result; + } + + /** + * Gets lease Id for the blob + * + * @return string + */ + public function getLeaseId() + { + return $this->leaseId; + } + + /** + * Sets lease Id for the blob + * + * @param string $leaseId the blob lease id. + * + * @return void + */ + protected function setLeaseId($leaseId) + { + $this->leaseId = $leaseId; + } +} diff --git a/src/Blob/Models/ListBlobBlocksOptions.php b/src/Blob/Models/ListBlobBlocksOptions.php new file mode 100644 index 0000000..0b2ca77 --- /dev/null +++ b/src/Blob/Models/ListBlobBlocksOptions.php @@ -0,0 +1,141 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Common\Internal\Validate; + +/** + * Optional parameters for listBlobBlock wrapper + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class ListBlobBlocksOptions extends BlobServiceOptions +{ + private $_snapshot; + private $_includeUncommittedBlobs; + private $_includeCommittedBlobs; + private static $_listType; + + /** + * Constructs the static variable $listType. + */ + public function __construct() + { + parent::__construct(); + self::$_listType[true][true] = 'all'; + self::$_listType[true][false] = 'uncommitted'; + self::$_listType[false][true] = 'committed'; + self::$_listType[false][false] = 'all'; + + $this->_includeUncommittedBlobs = false; + $this->_includeCommittedBlobs = false; + } + + /** + * Gets blob snapshot. + * + * @return string + */ + public function getSnapshot() + { + return $this->_snapshot; + } + + /** + * Sets blob snapshot. + * + * @param string $snapshot value. + * + * @return void + */ + public function setSnapshot($snapshot) + { + $this->_snapshot = $snapshot; + } + + /** + * Sets the include uncommittedBlobs flag. + * + * @param bool $includeUncommittedBlobs value. + * + * @return void + */ + public function setIncludeUncommittedBlobs($includeUncommittedBlobs) + { + Validate::isBoolean($includeUncommittedBlobs); + $this->_includeUncommittedBlobs = $includeUncommittedBlobs; + } + + /** + * Indicates if uncommittedBlobs is included or not. + * + * @return boolean + */ + public function getIncludeUncommittedBlobs() + { + return $this->_includeUncommittedBlobs; + } + + /** + * Sets the include committedBlobs flag. + * + * @param bool $includeCommittedBlobs value. + * + * @return void + */ + public function setIncludeCommittedBlobs($includeCommittedBlobs) + { + Validate::isBoolean($includeCommittedBlobs); + $this->_includeCommittedBlobs = $includeCommittedBlobs; + } + + /** + * Indicates if committedBlobs is included or not. + * + * @return boolean + */ + public function getIncludeCommittedBlobs() + { + return $this->_includeCommittedBlobs; + } + + /** + * Gets block list type. + * + * @return string + */ + public function getBlockListType() + { + $includeUncommitted = $this->_includeUncommittedBlobs; + $includeCommitted = $this->_includeCommittedBlobs; + + return self::$_listType[$includeUncommitted][$includeCommitted]; + } +} diff --git a/src/Blob/Models/ListBlobBlocksResult.php b/src/Blob/Models/ListBlobBlocksResult.php new file mode 100644 index 0000000..c8f4bf2 --- /dev/null +++ b/src/Blob/Models/ListBlobBlocksResult.php @@ -0,0 +1,252 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Common\Internal\Validate; +use MicrosoftAzure\Storage\Blob\Internal\BlobResources as Resources; +use MicrosoftAzure\Storage\Common\Internal\Utilities; + +/** + * Holds result of listBlobBlocks + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class ListBlobBlocksResult +{ + private $lastModified; + private $etag; + private $contentType; + private $contentLength; + private $committedBlocks; + private $uncommittedBlocks; + + /** + * Gets block entries from parsed response + * + * @param array $parsed HTTP response + * @param string $type Block type + * + * @return array + */ + private static function getEntries(array $parsed, $type) + { + $entries = array(); + + if (is_array($parsed)) { + $rawEntries = array(); + + if (array_key_exists($type, $parsed) + && is_array($parsed[$type]) + && !empty($parsed[$type]) + ) { + $rawEntries = Utilities::getArray($parsed[$type]['Block']); + } + + foreach ($rawEntries as $value) { + $entries[$value['Name']] = $value['Size']; + } + } + + return $entries; + } + + /** + * Creates ListBlobBlocksResult from given response headers and parsed body + * + * @param array $headers HTTP response headers + * @param array $parsed HTTP response body in array representation + * + * @internal + * + * @return ListBlobBlocksResult + */ + public static function create(array $headers, array $parsed) + { + $result = new ListBlobBlocksResult(); + $clean = array_change_key_case($headers); + + $result->setETag(Utilities::tryGetValue($clean, Resources::ETAG)); + $date = Utilities::tryGetValue($clean, Resources::LAST_MODIFIED); + if (!is_null($date)) { + $date = Utilities::rfc1123ToDateTime($date); + $result->setLastModified($date); + } + $result->setContentLength( + intval( + Utilities::tryGetValue($clean, Resources::X_MS_BLOB_CONTENT_LENGTH) + ) + ); + $result->setContentType( + Utilities::tryGetValue($clean, Resources::CONTENT_TYPE) + ); + + $result->uncommittedBlocks = self::getEntries( + $parsed, + 'UncommittedBlocks' + ); + $result->committedBlocks = self::getEntries($parsed, 'CommittedBlocks'); + + return $result; + } + + /** + * Gets blob lastModified. + * + * @return \DateTime + */ + public function getLastModified() + { + return $this->lastModified; + } + + /** + * Sets blob lastModified. + * + * @param \DateTime $lastModified value. + * + * @return void + */ + protected function setLastModified(\DateTime $lastModified) + { + Validate::isDate($lastModified); + $this->lastModified = $lastModified; + } + + /** + * Gets blob etag. + * + * @return string + */ + public function getETag() + { + return $this->etag; + } + + /** + * Sets blob etag. + * + * @param string $etag value. + * + * @return void + */ + protected function setETag($etag) + { + $this->etag = $etag; + } + + /** + * Gets blob contentType. + * + * @return string + */ + public function getContentType() + { + return $this->contentType; + } + + /** + * Sets blob contentType. + * + * @param string $contentType value. + * + * @return void + */ + protected function setContentType($contentType) + { + $this->contentType = $contentType; + } + + /** + * Gets blob contentLength. + * + * @return integer + */ + public function getContentLength() + { + return $this->contentLength; + } + + /** + * Sets blob contentLength. + * + * @param integer $contentLength value. + * + * @return void + */ + protected function setContentLength($contentLength) + { + Validate::isInteger($contentLength, 'contentLength'); + $this->contentLength = $contentLength; + } + + /** + * Gets uncommitted blocks + * + * @return array + */ + public function getUncommittedBlocks() + { + return $this->uncommittedBlocks; + } + + /** + * Sets uncommitted blocks + * + * @param array $uncommittedBlocks The uncommitted blocks entries + * + * @return void + */ + protected function setUncommittedBlocks(array $uncommittedBlocks) + { + $this->uncommittedBlocks = $uncommittedBlocks; + } + + /** + * Gets committed blocks + * + * @return array + */ + public function getCommittedBlocks() + { + return $this->committedBlocks; + } + + /** + * Sets committed blocks + * + * @param array $committedBlocks The committed blocks entries + * + * @return void + */ + protected function setCommittedBlocks(array $committedBlocks) + { + $this->committedBlocks = $committedBlocks; + } +} diff --git a/src/Blob/Models/ListBlobsOptions.php b/src/Blob/Models/ListBlobsOptions.php new file mode 100644 index 0000000..8a54cfd --- /dev/null +++ b/src/Blob/Models/ListBlobsOptions.php @@ -0,0 +1,212 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Common\Internal\Validate; +use MicrosoftAzure\Storage\Common\MarkerContinuationTokenTrait; + +/** + * Optional parameters for listBlobs API. + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class ListBlobsOptions extends BlobServiceOptions +{ + use MarkerContinuationTokenTrait; + + private $_prefix; + private $_delimiter; + private $_maxResults; + private $_includeMetadata; + private $_includeSnapshots; + private $_includeUncommittedBlobs; + private $_includeCopy; + + /** + * Gets prefix. + * + * @return string + */ + public function getPrefix() + { + return $this->_prefix; + } + + /** + * Sets prefix. + * + * @param string $prefix value. + * + * @return void + */ + public function setPrefix($prefix) + { + Validate::canCastAsString($prefix, 'prefix'); + $this->_prefix = $prefix; + } + + /** + * Gets delimiter. + * + * @return string + */ + public function getDelimiter() + { + return $this->_delimiter; + } + + /** + * Sets prefix. + * + * @param string $delimiter value. + * + * @return void + */ + public function setDelimiter($delimiter) + { + Validate::canCastAsString($delimiter, 'delimiter'); + $this->_delimiter = $delimiter; + } + + /** + * Gets max results. + * + * @return integer + */ + public function getMaxResults() + { + return $this->_maxResults; + } + + /** + * Sets max results. + * + * @param integer $maxResults value. + * + * @return void + */ + public function setMaxResults($maxResults) + { + Validate::isInteger($maxResults, 'maxResults'); + $this->_maxResults = $maxResults; + } + + /** + * Indicates if metadata is included or not. + * + * @return boolean + */ + public function getIncludeMetadata() + { + return $this->_includeMetadata; + } + + /** + * Sets the include metadata flag. + * + * @param bool $includeMetadata value. + * + * @return void + */ + public function setIncludeMetadata($includeMetadata) + { + Validate::isBoolean($includeMetadata); + $this->_includeMetadata = $includeMetadata; + } + + /** + * Indicates if snapshots is included or not. + * + * @return boolean + */ + public function getIncludeSnapshots() + { + return $this->_includeSnapshots; + } + + /** + * Sets the include snapshots flag. + * + * @param bool $includeSnapshots value. + * + * @return void + */ + public function setIncludeSnapshots($includeSnapshots) + { + Validate::isBoolean($includeSnapshots); + $this->_includeSnapshots = $includeSnapshots; + } + + /** + * Indicates if uncommittedBlobs is included or not. + * + * @return boolean + */ + public function getIncludeUncommittedBlobs() + { + return $this->_includeUncommittedBlobs; + } + + /** + * Sets the include uncommittedBlobs flag. + * + * @param bool $includeUncommittedBlobs value. + * + * @return void + */ + public function setIncludeUncommittedBlobs($includeUncommittedBlobs) + { + Validate::isBoolean($includeUncommittedBlobs); + $this->_includeUncommittedBlobs = $includeUncommittedBlobs; + } + + /** + * Indicates if copy is included or not. + * + * @return boolean + */ + public function getIncludeCopy() + { + return $this->_includeCopy; + } + + /** + * Sets the include copy flag. + * + * @param bool $includeCopy value. + * + * @return void + */ + public function setIncludeCopy($includeCopy) + { + Validate::isBoolean($includeCopy); + $this->_includeCopy = $includeCopy; + } +} diff --git a/src/Blob/Models/ListBlobsResult.php b/src/Blob/Models/ListBlobsResult.php new file mode 100644 index 0000000..d809d6e --- /dev/null +++ b/src/Blob/Models/ListBlobsResult.php @@ -0,0 +1,313 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Blob\Internal\BlobResources as Resources; +use MicrosoftAzure\Storage\Common\Internal\Utilities; +use MicrosoftAzure\Storage\Common\MarkerContinuationTokenTrait; +use MicrosoftAzure\Storage\Common\Models\MarkerContinuationToken; + +/** + * Hold result of calliing listBlobs wrapper. + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class ListBlobsResult +{ + use MarkerContinuationTokenTrait; + + private $blobPrefixes; + private $blobs; + private $delimiter; + private $prefix; + private $marker; + private $maxResults; + private $containerName; + + /** + * Creates ListBlobsResult object from parsed XML response. + * + * @param array $parsed XML response parsed into array. + * @param string $location Contains the location for the previous + * request. + * + * @internal + * + * @return ListBlobsResult + */ + public static function create(array $parsed, $location = '') + { + $result = new ListBlobsResult(); + $serviceEndpoint = Utilities::tryGetKeysChainValue( + $parsed, + Resources::XTAG_ATTRIBUTES, + Resources::XTAG_SERVICE_ENDPOINT + ); + $containerName = Utilities::tryGetKeysChainValue( + $parsed, + Resources::XTAG_ATTRIBUTES, + Resources::XTAG_CONTAINER_NAME + ); + $result->setContainerName($containerName); + $result->setPrefix(Utilities::tryGetValue( + $parsed, + Resources::QP_PREFIX + )); + $result->setMarker(Utilities::tryGetValue( + $parsed, + Resources::QP_MARKER + )); + + $nextMarker = + Utilities::tryGetValue($parsed, Resources::QP_NEXT_MARKER); + + if ($nextMarker != null) { + $result->setContinuationToken( + new MarkerContinuationToken( + $nextMarker, + $location + ) + ); + } + + $result->setMaxResults(intval( + Utilities::tryGetValue($parsed, Resources::QP_MAX_RESULTS, 0) + )); + $result->setDelimiter(Utilities::tryGetValue( + $parsed, + Resources::QP_DELIMITER + )); + $blobs = array(); + $blobPrefixes = array(); + $rawBlobs = array(); + $rawBlobPrefixes = array(); + + if (is_array($parsed['Blobs']) + && array_key_exists('Blob', $parsed['Blobs']) + ) { + $rawBlobs = Utilities::getArray($parsed['Blobs']['Blob']); + } + + foreach ($rawBlobs as $value) { + $blob = new Blob(); + $blob->setName($value['Name']); + $blob->setUrl($serviceEndpoint . $containerName . '/' . $value['Name']); + $blob->setSnapshot(Utilities::tryGetValue($value, 'Snapshot')); + $blob->setProperties( + BlobProperties::createFromXml( + Utilities::tryGetValue($value, 'Properties') + ) + ); + $blob->setMetadata( + Utilities::tryGetValue($value, Resources::QP_METADATA, array()) + ); + + $blobs[] = $blob; + } + + if (is_array($parsed['Blobs']) + && array_key_exists('BlobPrefix', $parsed['Blobs']) + ) { + $rawBlobPrefixes = Utilities::getArray($parsed['Blobs']['BlobPrefix']); + } + + foreach ($rawBlobPrefixes as $value) { + $blobPrefix = new BlobPrefix(); + $blobPrefix->setName($value['Name']); + + $blobPrefixes[] = $blobPrefix; + } + + $result->setBlobs($blobs); + $result->setBlobPrefixes($blobPrefixes); + + return $result; + } + + /** + * Gets blobs. + * + * @return Blob[] + */ + public function getBlobs() + { + return $this->blobs; + } + + /** + * Sets blobs. + * + * @param Blob[] $blobs list of blobs + * + * @return void + */ + protected function setBlobs(array $blobs) + { + $this->blobs = array(); + foreach ($blobs as $blob) { + $this->blobs[] = clone $blob; + } + } + + /** + * Gets blobPrefixes. + * + * @return array + */ + public function getBlobPrefixes() + { + return $this->blobPrefixes; + } + + /** + * Sets blobPrefixes. + * + * @param array $blobPrefixes list of blobPrefixes + * + * @return void + */ + protected function setBlobPrefixes(array $blobPrefixes) + { + $this->blobPrefixes = array(); + foreach ($blobPrefixes as $blob) { + $this->blobPrefixes[] = clone $blob; + } + } + + /** + * Gets prefix. + * + * @return string + */ + public function getPrefix() + { + return $this->prefix; + } + + /** + * Sets prefix. + * + * @param string $prefix value. + * + * @return void + */ + protected function setPrefix($prefix) + { + $this->prefix = $prefix; + } + + /** + * Gets prefix. + * + * @return string + */ + public function getDelimiter() + { + return $this->delimiter; + } + + /** + * Sets prefix. + * + * @param string $delimiter value. + * + * @return void + */ + protected function setDelimiter($delimiter) + { + $this->delimiter = $delimiter; + } + + /** + * Gets marker. + * + * @return string + */ + public function getMarker() + { + return $this->marker; + } + + /** + * Sets marker. + * + * @param string $marker value. + * + * @return void + */ + protected function setMarker($marker) + { + $this->marker = $marker; + } + + /** + * Gets max results. + * + * @return integer + */ + public function getMaxResults() + { + return $this->maxResults; + } + + /** + * Sets max results. + * + * @param integer $maxResults value. + * + * @return void + */ + protected function setMaxResults($maxResults) + { + $this->maxResults = $maxResults; + } + + /** + * Gets container name. + * + * @return string + */ + public function getContainerName() + { + return $this->containerName; + } + + /** + * Sets container name. + * + * @param string $containerName value. + * + * @return void + */ + protected function setContainerName($containerName) + { + $this->containerName = $containerName; + } +} diff --git a/src/Blob/Models/ListContainersOptions.php b/src/Blob/Models/ListContainersOptions.php new file mode 100644 index 0000000..5ef7c94 --- /dev/null +++ b/src/Blob/Models/ListContainersOptions.php @@ -0,0 +1,126 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Common\MarkerContinuationTokenTrait; +use MicrosoftAzure\Storage\Common\Internal\Validate; + +/** + * Options for listBlobs API. + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class ListContainersOptions extends BlobServiceOptions +{ + use MarkerContinuationTokenTrait; + + private $_prefix; + private $_maxResults; + private $_includeMetadata; + + /** + * Gets prefix - filters the results to return only containers whose name + * begins with the specified prefix. + * + * @return string + */ + public function getPrefix() + { + return $this->_prefix; + } + + /** + * Sets prefix - filters the results to return only containers whose name + * begins with the specified prefix. + * + * @param string $prefix value. + * + * @return void + */ + public function setPrefix($prefix) + { + Validate::canCastAsString($prefix, 'prefix'); + $this->_prefix = $prefix; + } + + /** + * Gets max results which specifies the maximum number of containers to return. + * If the request does not specify maxresults, or specifies a value + * greater than 5,000, the server will return up to 5,000 items. + * If the parameter is set to a value less than or equal to zero, + * the server will return status code 400 (Bad Request). + * + * @return string + */ + public function getMaxResults() + { + return $this->_maxResults; + } + + /** + * Sets max results which specifies the maximum number of containers to return. + * If the request does not specify maxresults, or specifies a value + * greater than 5,000, the server will return up to 5,000 items. + * If the parameter is set to a value less than or equal to zero, + * the server will return status code 400 (Bad Request). + * + * @param string $maxResults value. + * + * @return void + */ + public function setMaxResults($maxResults) + { + Validate::canCastAsString($maxResults, 'maxResults'); + $this->_maxResults = $maxResults; + } + + /** + * Indicates if metadata is included or not. + * + * @return string + */ + public function getIncludeMetadata() + { + return $this->_includeMetadata; + } + + /** + * Sets the include metadata flag. + * + * @param bool $includeMetadata value. + * + * @return void + */ + public function setIncludeMetadata($includeMetadata) + { + Validate::isBoolean($includeMetadata); + $this->_includeMetadata = $includeMetadata; + } +} diff --git a/src/Blob/Models/ListContainersResult.php b/src/Blob/Models/ListContainersResult.php new file mode 100644 index 0000000..abd5877 --- /dev/null +++ b/src/Blob/Models/ListContainersResult.php @@ -0,0 +1,251 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Blob\Internal\BlobResources as Resources; +use MicrosoftAzure\Storage\Common\Internal\Utilities; +use MicrosoftAzure\Storage\Common\Models\MarkerContinuationToken; +use MicrosoftAzure\Storage\Common\MarkerContinuationTokenTrait; + +/** + * Container to hold list container response object. + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class ListContainersResult +{ + use MarkerContinuationTokenTrait; + + private $containers; + private $prefix; + private $marker; + private $maxResults; + private $accountName; + + /** + * Creates ListBlobResult object from parsed XML response. + * + * @param array $parsedResponse XML response parsed into array. + * @param string $location Contains the location for the previous + * request. + * + * @internal + * + * @return ListContainersResult + */ + public static function create(array $parsedResponse, $location = '') + { + $result = new ListContainersResult(); + $serviceEndpoint = Utilities::tryGetKeysChainValue( + $parsedResponse, + Resources::XTAG_ATTRIBUTES, + Resources::XTAG_SERVICE_ENDPOINT + ); + $result->setAccountName(Utilities::tryParseAccountNameFromUrl( + $serviceEndpoint + )); + $result->setPrefix(Utilities::tryGetValue( + $parsedResponse, + Resources::QP_PREFIX + )); + $result->setMarker(Utilities::tryGetValue( + $parsedResponse, + Resources::QP_MARKER + )); + + $nextMarker = + Utilities::tryGetValue($parsedResponse, Resources::QP_NEXT_MARKER); + + if ($nextMarker != null) { + $result->setContinuationToken( + new MarkerContinuationToken( + $nextMarker, + $location + ) + ); + } + + $result->setMaxResults(Utilities::tryGetValue( + $parsedResponse, + Resources::QP_MAX_RESULTS + )); + $containers = array(); + $rawContainer = array(); + + if (!empty($parsedResponse['Containers'])) { + $containersArray = $parsedResponse['Containers']['Container']; + $rawContainer = Utilities::getArray($containersArray); + } + + foreach ($rawContainer as $value) { + $container = new Container(); + $container->setName($value['Name']); + $container->setUrl($serviceEndpoint . $value['Name']); + $container->setMetadata( + Utilities::tryGetValue($value, Resources::QP_METADATA, array()) + ); + $properties = new ContainerProperties(); + $date = $value['Properties']['Last-Modified']; + $date = Utilities::rfc1123ToDateTime($date); + $properties->setLastModified($date); + $properties->setETag($value['Properties']['Etag']); + + if (array_key_exists('LeaseStatus', $value['Properties'])) { + $properties->setLeaseStatus($value['Properties']['LeaseStatus']); + } + if (array_key_exists('LeaseState', $value['Properties'])) { + $properties->setLeaseStatus($value['Properties']['LeaseState']); + } + if (array_key_exists('LeaseDuration', $value['Properties'])) { + $properties->setLeaseStatus($value['Properties']['LeaseDuration']); + } + if (array_key_exists('PublicAccess', $value['Properties'])) { + $properties->setPublicAccess($value['Properties']['PublicAccess']); + } + $container->setProperties($properties); + $containers[] = $container; + } + $result->setContainers($containers); + return $result; + } + + /** + * Sets containers. + * + * @param array $containers list of containers. + * + * @return void + */ + protected function setContainers(array $containers) + { + $this->containers = array(); + foreach ($containers as $container) { + $this->containers[] = clone $container; + } + } + + /** + * Gets containers. + * + * @return Container[] + */ + public function getContainers() + { + return $this->containers; + } + + /** + * Gets prefix. + * + * @return string + */ + public function getPrefix() + { + return $this->prefix; + } + + /** + * Sets prefix. + * + * @param string $prefix value. + * + * @return void + */ + protected function setPrefix($prefix) + { + $this->prefix = $prefix; + } + + /** + * Gets marker. + * + * @return string + */ + public function getMarker() + { + return $this->marker; + } + + /** + * Sets marker. + * + * @param string $marker value. + * + * @return void + */ + protected function setMarker($marker) + { + $this->marker = $marker; + } + + /** + * Gets max results. + * + * @return string + */ + public function getMaxResults() + { + return $this->maxResults; + } + + /** + * Sets max results. + * + * @param string $maxResults value. + * + * @return void + */ + protected function setMaxResults($maxResults) + { + $this->maxResults = $maxResults; + } + + /** + * Gets account name. + * + * @return string + */ + public function getAccountName() + { + return $this->accountName; + } + + /** + * Sets account name. + * + * @param string $accountName value. + * + * @return void + */ + protected function setAccountName($accountName) + { + $this->accountName = $accountName; + } +} diff --git a/src/Blob/Models/ListPageBlobRangesDiffResult.php b/src/Blob/Models/ListPageBlobRangesDiffResult.php new file mode 100644 index 0000000..1575a5e --- /dev/null +++ b/src/Blob/Models/ListPageBlobRangesDiffResult.php @@ -0,0 +1,101 @@ + + * @copyright 2017 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Common\Internal\Utilities; +use MicrosoftAzure\Storage\Blob\Internal\BlobResources as Resources; +use MicrosoftAzure\Storage\Common\Models\RangeDiff; + +/** + * Holds result of calling listPageBlobRangesDiff wrapper + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2017 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class ListPageBlobRangesDiffResult extends ListPageBlobRangesResult +{ + /** + * Creates ListPageBlobRangesDiffResult object from $parsed response in array representation + * + * @param array $headers HTTP response headers + * @param array $parsed parsed response in array format. + * + * @internal + * + * @return ListPageBlobRangesDiffResult + */ + public static function create(array $headers, array $parsed = null) + { + $result = new ListPageBlobRangesDiffResult(); + $headers = array_change_key_case($headers); + + $date = $headers[Resources::LAST_MODIFIED]; + $date = Utilities::rfc1123ToDateTime($date); + $blobLength = intval($headers[Resources::X_MS_BLOB_CONTENT_LENGTH]); + + $result->setContentLength($blobLength); + $result->setLastModified($date); + $result->setETag($headers[Resources::ETAG]); + + if (is_null($parsed)) { + return $result; + } + + $parsed = array_change_key_case($parsed); + + $rawRanges = array(); + if (!empty($parsed[strtolower(Resources::XTAG_PAGE_RANGE)])) { + $rawRanges = Utilities::getArray($parsed[strtolower(Resources::XTAG_PAGE_RANGE)]); + } + + $pageRanges = array(); + foreach ($rawRanges as $value) { + $pageRanges[] = new RangeDiff( + intval($value[Resources::XTAG_RANGE_START]), + intval($value[Resources::XTAG_RANGE_END]) + ); + } + + $rawRanges = array(); + if (!empty($parsed[strtolower(Resources::XTAG_CLEAR_RANGE)])) { + $rawRanges = Utilities::getArray($parsed[strtolower(Resources::XTAG_CLEAR_RANGE)]); + } + + foreach ($rawRanges as $value) { + $pageRanges[] = new RangeDiff( + intval($value[Resources::XTAG_RANGE_START]), + intval($value[Resources::XTAG_RANGE_END]), + true + ); + } + + $result->setRanges($pageRanges); + return $result; + } +} diff --git a/src/Blob/Models/ListPageBlobRangesOptions.php b/src/Blob/Models/ListPageBlobRangesOptions.php new file mode 100644 index 0000000..155cbe4 --- /dev/null +++ b/src/Blob/Models/ListPageBlobRangesOptions.php @@ -0,0 +1,90 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Common\Internal\Validate; +use MicrosoftAzure\Storage\Common\Models\Range; + +/** + * Optional parameters for listPageBlobRanges wrapper + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class ListPageBlobRangesOptions extends BlobServiceOptions +{ + private $snapshot; + private $range; + private $_rangeStart; + private $_rangeEnd; + + /** + * Gets blob snapshot. + * + * @return string + */ + public function getSnapshot() + { + return $this->snapshot; + } + + /** + * Sets blob snapshot. + * + * @param string $snapshot value. + * + * @return void + */ + public function setSnapshot($snapshot) + { + $this->snapshot = $snapshot; + } + + /** + * Gets Blob range. + * + * @return Range + */ + public function getRange() + { + return $this->range; + } + + /** + * Sets Blob range. + * + * @param Range $range value. + * + * @return void + */ + public function setRange(Range $range) + { + $this->range = $range; + } +} diff --git a/src/Blob/Models/ListPageBlobRangesResult.php b/src/Blob/Models/ListPageBlobRangesResult.php new file mode 100644 index 0000000..262b4c7 --- /dev/null +++ b/src/Blob/Models/ListPageBlobRangesResult.php @@ -0,0 +1,182 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Common\Internal\Validate; +use MicrosoftAzure\Storage\Common\Internal\Utilities; +use MicrosoftAzure\Storage\Blob\Internal\BlobResources as Resources; +use MicrosoftAzure\Storage\Common\Models\Range; + +/** + * Holds result of calling listPageBlobRanges wrapper + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class ListPageBlobRangesResult +{ + private $_lastModified; + private $_etag; + private $_contentLength; + private $_pageRanges; + + /** + * Creates BlobProperties object from $parsed response in array representation + * + * @param array $headers HTTP response headers + * @param array $parsed parsed response in array format. + * + * @internal + * + * @return ListPageBlobRangesResult + */ + public static function create(array $headers, array $parsed = null) + { + $result = new ListPageBlobRangesResult(); + $headers = array_change_key_case($headers); + + $date = $headers[Resources::LAST_MODIFIED]; + $date = Utilities::rfc1123ToDateTime($date); + $blobLength = intval($headers[Resources::X_MS_BLOB_CONTENT_LENGTH]); + $rawRanges = array(); + + if (!empty($parsed[Resources::XTAG_PAGE_RANGE])) { + $parsed = array_change_key_case($parsed); + $rawRanges = Utilities::getArray($parsed[strtolower(RESOURCES::XTAG_PAGE_RANGE)]); + } + + $pageRanges = array(); + foreach ($rawRanges as $value) { + $pageRanges[] = new Range( + intval($value[Resources::XTAG_RANGE_START]), + intval($value[Resources::XTAG_RANGE_END]) + ); + } + $result->setRanges($pageRanges); + $result->setContentLength($blobLength); + $result->setETag($headers[Resources::ETAG]); + $result->setLastModified($date); + + return $result; + } + + /** + * Gets blob lastModified. + * + * @return \DateTime + */ + public function getLastModified() + { + return $this->_lastModified; + } + + /** + * Sets blob lastModified. + * + * @param \DateTime $lastModified value. + * + * @return void + */ + protected function setLastModified(\DateTime $lastModified) + { + Validate::isDate($lastModified); + $this->_lastModified = $lastModified; + } + + /** + * Gets blob etag. + * + * @return string + */ + public function getETag() + { + return $this->_etag; + } + + /** + * Sets blob etag. + * + * @param string $etag value. + * + * @return void + */ + protected function setETag($etag) + { + Validate::canCastAsString($etag, 'etag'); + $this->_etag = $etag; + } + + /** + * Gets blob contentLength. + * + * @return integer + */ + public function getContentLength() + { + return $this->_contentLength; + } + + /** + * Sets blob contentLength. + * + * @param integer $contentLength value. + * + * @return void + */ + protected function setContentLength($contentLength) + { + Validate::isInteger($contentLength, 'contentLength'); + $this->_contentLength = $contentLength; + } + + /** + * Gets page ranges + * + * @return array + */ + public function getRanges() + { + return $this->_pageRanges; + } + + /** + * Sets page ranges + * + * @param array $pageRanges page ranges to set + * + * @return void + */ + protected function setRanges(array $pageRanges) + { + $this->_pageRanges = array(); + foreach ($pageRanges as $pageRange) { + $this->_pageRanges[] = clone $pageRange; + } + } +} diff --git a/src/Blob/Models/PageWriteOption.php b/src/Blob/Models/PageWriteOption.php new file mode 100644 index 0000000..cadc9d0 --- /dev/null +++ b/src/Blob/Models/PageWriteOption.php @@ -0,0 +1,41 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +/** + * Holds available blob page write options + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class PageWriteOption +{ + const CLEAR_OPTION = 'clear'; + const UPDATE_OPTION = 'update'; +} diff --git a/src/Blob/Models/PublicAccessType.php b/src/Blob/Models/PublicAccessType.php new file mode 100644 index 0000000..81edb62 --- /dev/null +++ b/src/Blob/Models/PublicAccessType.php @@ -0,0 +1,67 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Blob\Internal\BlobResources as Resources; + +/** + * Holds public access types for a container. + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class PublicAccessType +{ + const NONE = null; + const BLOBS_ONLY = 'blob'; + const CONTAINER_AND_BLOBS = 'container'; + + /** + * Validates the public access. + * + * @param string $type The public access type. + * + * @internal + * + * @return boolean + */ + public static function isValid($type) + { + // When $type is null, switch statement will take it + // equal to self::NONE (EMPTY_STRING) + switch ($type) { + case self::NONE: + case self::BLOBS_ONLY: + case self::CONTAINER_AND_BLOBS: + return true; + default: + return false; + } + } +} diff --git a/src/Blob/Models/PutBlobResult.php b/src/Blob/Models/PutBlobResult.php new file mode 100644 index 0000000..d0ef2e9 --- /dev/null +++ b/src/Blob/Models/PutBlobResult.php @@ -0,0 +1,182 @@ + + * @copyright 2017 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Blob\Internal\BlobResources as Resources; +use MicrosoftAzure\Storage\Common\Internal\Utilities; + +/** + * The result of calling PutBlob API. + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2017 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class PutBlobResult +{ + private $contentMD5; + private $etag; + private $lastModified; + private $requestServerEncrypted; + + /** + * Creates PutBlobResult object from the response of the put blob request. + * + * @param array $headers The HTTP response headers in array representation. + * + * @internal + * + * @return PutBlobResult + */ + public static function create(array $headers) + { + $result = new PutBlobResult(); + + $result->setETag( + Utilities::tryGetValueInsensitive( + Resources::ETAG, + $headers + ) + ); + + if (Utilities::arrayKeyExistsInsensitive( + Resources::LAST_MODIFIED, + $headers + )) { + $lastModified = Utilities::tryGetValueInsensitive( + Resources::LAST_MODIFIED, + $headers + ); + $result->setLastModified(Utilities::rfc1123ToDateTime($lastModified)); + } + + $result->setContentMD5( + Utilities::tryGetValueInsensitive(Resources::CONTENT_MD5, $headers) + ); + + $result->setRequestServerEncrypted( + Utilities::toBoolean( + Utilities::tryGetValueInsensitive( + Resources::X_MS_REQUEST_SERVER_ENCRYPTED, + $headers + ), + true + ) + ); + + return $result; + } + + /** + * Gets ETag. + * + * @return string + */ + public function getETag() + { + return $this->etag; + } + + /** + * Sets ETag. + * + * @param string $etag value. + * + * @return void + */ + protected function setETag($etag) + { + $this->etag = $etag; + } + + /** + * Gets blob lastModified. + * + * @return \DateTime + */ + public function getLastModified() + { + return $this->lastModified; + } + + /** + * Sets blob lastModified. + * + * @param \DateTime $lastModified value. + * + * @return void + */ + protected function setLastModified(\DateTime $lastModified) + { + $this->lastModified = $lastModified; + } + + /** + * Gets block content MD5. + * + * @return string + */ + public function getContentMD5() + { + return $this->contentMD5; + } + + /** + * Sets the content MD5 value. + * + * @param string $contentMD5 conent MD5 as a string. + * + * @return void + */ + protected function setContentMD5($contentMD5) + { + $this->contentMD5 = $contentMD5; + } + + /** + * Gets the whether the contents of the request are successfully encrypted. + * + * @return boolean + */ + public function getRequestServerEncrypted() + { + return $this->requestServerEncrypted; + } + + /** + * Sets the request server encryption value. + * + * @param boolean $requestServerEncrypted + * + * @return void + */ + public function setRequestServerEncrypted($requestServerEncrypted) + { + $this->requestServerEncrypted = $requestServerEncrypted; + } +} diff --git a/src/Blob/Models/PutBlockResult.php b/src/Blob/Models/PutBlockResult.php new file mode 100644 index 0000000..33a4b9d --- /dev/null +++ b/src/Blob/Models/PutBlockResult.php @@ -0,0 +1,118 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Blob\Internal\BlobResources as Resources; +use MicrosoftAzure\Storage\Common\Internal\Utilities; + +/** + * The result of calling PutBlock API. + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class PutBlockResult +{ + private $contentMD5; + private $requestServerEncrypted; + + /** + * Creates PutBlockResult object from the response of the put block request. + * + * @param array $headers The HTTP response headers in array representation. + * + * @internal + * + * @return PutBlockResult + */ + public static function create(array $headers) + { + $result = new PutBlockResult(); + + $result->setContentMD5( + Utilities::tryGetValueInsensitive(Resources::CONTENT_MD5, $headers) + ); + + $result->setRequestServerEncrypted( + Utilities::toBoolean( + Utilities::tryGetValueInsensitive( + Resources::X_MS_REQUEST_SERVER_ENCRYPTED, + $headers + ), + true + ) + ); + + return $result; + } + + /** + * Gets block content MD5. + * + * @return string + */ + public function getContentMD5() + { + return $this->contentMD5; + } + + /** + * Sets the content MD5 value. + * + * @param string $contentMD5 conent MD5 as a string. + * + * @return void + */ + protected function setContentMD5($contentMD5) + { + $this->contentMD5 = $contentMD5; + } + + /** + * Gets the whether the contents of the request are successfully encrypted. + * + * @return boolean + */ + public function getRequestServerEncrypted() + { + return $this->requestServerEncrypted; + } + + /** + * Sets the request server encryption value. + * + * @param boolean $requestServerEncrypted + * + * @return void + */ + public function setRequestServerEncrypted($requestServerEncrypted) + { + $this->requestServerEncrypted = $requestServerEncrypted; + } +} diff --git a/src/Blob/Models/SetBlobMetadataResult.php b/src/Blob/Models/SetBlobMetadataResult.php new file mode 100644 index 0000000..532c8b0 --- /dev/null +++ b/src/Blob/Models/SetBlobMetadataResult.php @@ -0,0 +1,151 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Blob\Internal\BlobResources as Resources; +use MicrosoftAzure\Storage\Common\Internal\Validate; +use MicrosoftAzure\Storage\Common\Internal\Utilities; + +/** + * Holds results of calling getBlobMetadata wrapper + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class SetBlobMetadataResult +{ + private $etag; + private $lastModified; + private $requestServerEncrypted; + + /** + * Creates SetBlobMetadataResult from response headers. + * + * @param array $headers response headers + * + * @internal + * + * @return SetBlobMetadataResult + */ + public static function create(array $headers) + { + $result = new SetBlobMetadataResult(); + + $result->setETag(Utilities::tryGetValueInsensitive( + Resources::ETAG, + $headers + )); + + $date = Utilities::tryGetValueInsensitive( + Resources::LAST_MODIFIED, + $headers + ); + $result->setLastModified(Utilities::rfc1123ToDateTime($date)); + + $result->setRequestServerEncrypted( + Utilities::toBoolean( + Utilities::tryGetValueInsensitive( + Resources::X_MS_REQUEST_SERVER_ENCRYPTED, + $headers + ), + true + ) + ); + + return $result; + } + + /** + * Gets blob lastModified. + * + * @return \DateTime + */ + public function getLastModified() + { + return $this->lastModified; + } + + /** + * Sets blob lastModified. + * + * @param \DateTime $lastModified value. + * + * @return void + */ + protected function setLastModified(\DateTime $lastModified) + { + Validate::isDate($lastModified); + $this->lastModified = $lastModified; + } + + /** + * Gets blob etag. + * + * @return string + */ + public function getETag() + { + return $this->etag; + } + + /** + * Sets blob etag. + * + * @param string $etag value. + * + * @return void + */ + protected function setETag($etag) + { + Validate::canCastAsString($etag, 'etag'); + $this->etag = $etag; + } + + /** + * Gets the whether the contents of the request are successfully encrypted. + * + * @return boolean + */ + public function getRequestServerEncrypted() + { + return $this->requestServerEncrypted; + } + + /** + * Sets the request server encryption value. + * + * @param boolean $requestServerEncrypted + * + * @return void + */ + public function setRequestServerEncrypted($requestServerEncrypted) + { + $this->requestServerEncrypted = $requestServerEncrypted; + } +} diff --git a/src/Blob/Models/SetBlobPropertiesOptions.php b/src/Blob/Models/SetBlobPropertiesOptions.php new file mode 100644 index 0000000..70781b2 --- /dev/null +++ b/src/Blob/Models/SetBlobPropertiesOptions.php @@ -0,0 +1,252 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +/** + * Optional parameters for setBlobProperties wrapper + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class SetBlobPropertiesOptions extends BlobServiceOptions +{ + private $_blobProperties; + private $_sequenceNumberAction; + + /** + * Creates a new SetBlobPropertiesOptions with a specified BlobProperties + * instance. + * + * @param BlobProperties $blobProperties The blob properties instance. + */ + public function __construct(BlobProperties $blobProperties = null) + { + parent::__construct(); + $this->_blobProperties = is_null($blobProperties) + ? new BlobProperties() : clone $blobProperties; + } + + /** + * Gets blob sequenceNumber. + * + * @return integer + */ + public function getSequenceNumber() + { + return $this->_blobProperties->getSequenceNumber(); + } + + /** + * Sets blob sequenceNumber. + * + * @param integer $sequenceNumber value. + * + * @return void + */ + public function setSequenceNumber($sequenceNumber) + { + $this->_blobProperties->setSequenceNumber($sequenceNumber); + } + + /** + * Gets lease Id for the blob + * + * @return string + */ + public function getSequenceNumberAction() + { + return $this->_sequenceNumberAction; + } + + /** + * Sets lease Id for the blob + * + * @param string $sequenceNumberAction action. + * + * @return void + */ + public function setSequenceNumberAction($sequenceNumberAction) + { + $this->_sequenceNumberAction = $sequenceNumberAction; + } + + /** + * Gets blob contentLength. + * + * @return integer + */ + public function getContentLength() + { + return $this->_blobProperties->getContentLength(); + } + + /** + * Sets blob contentLength. + * + * @param integer $contentLength value. + * + * @return void + */ + public function setContentLength($contentLength) + { + $this->_blobProperties->setContentLength($contentLength); + } + + /** + * Gets ContentType. + * + * @return string + */ + public function getContentType() + { + return $this->_blobProperties->getContentType(); + } + + /** + * Sets ContentType. + * + * @param string $contentType value. + * + * @return void + */ + public function setContentType($contentType) + { + $this->_blobProperties->setContentType($contentType); + } + + /** + * Gets ContentEncoding. + * + * @return string + */ + public function getContentEncoding() + { + return $this->_blobProperties->getContentEncoding(); + } + + /** + * Sets ContentEncoding. + * + * @param string $contentEncoding value. + * + * @return void + */ + public function setContentEncoding($contentEncoding) + { + $this->_blobProperties->setContentEncoding($contentEncoding); + } + + /** + * Gets ContentLanguage. + * + * @return string + */ + public function getContentLanguage() + { + return $this->_blobProperties->getContentLanguage(); + } + + /** + * Sets ContentLanguage. + * + * @param string $contentLanguage value. + * + * @return void + */ + public function setContentLanguage($contentLanguage) + { + $this->_blobProperties->setContentLanguage($contentLanguage); + } + + /** + * Gets ContentMD5. + * + * @return void + */ + public function getContentMD5() + { + return $this->_blobProperties->getContentMD5(); + } + + /** + * Sets blob ContentMD5. + * + * @param string $contentMD5 value. + * + * @return void + */ + public function setContentMD5($contentMD5) + { + $this->_blobProperties->setContentMD5($contentMD5); + } + + /** + * Gets cache control. + * + * @return string + */ + public function getCacheControl() + { + return $this->_blobProperties->getCacheControl(); + } + + /** + * Sets cacheControl. + * + * @param string $cacheControl value to use. + * + * @return void + */ + public function setCacheControl($cacheControl) + { + $this->_blobProperties->setCacheControl($cacheControl); + } + + /** + * Gets content disposition. + * + * @return string + */ + public function getContentDisposition() + { + return $this->_blobProperties->getContentDisposition(); + } + + /** + * Sets contentDisposition. + * + * @param string $contentDisposition value to use. + * + * @return void + */ + public function setContentDisposition($contentDisposition) + { + $this->_blobProperties->setContentDisposition($contentDisposition); + } +} diff --git a/src/Blob/Models/SetBlobPropertiesResult.php b/src/Blob/Models/SetBlobPropertiesResult.php new file mode 100644 index 0000000..550d29b --- /dev/null +++ b/src/Blob/Models/SetBlobPropertiesResult.php @@ -0,0 +1,144 @@ + + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ + +namespace MicrosoftAzure\Storage\Blob\Models; + +use MicrosoftAzure\Storage\Blob\Internal\BlobResources as Resources; +use MicrosoftAzure\Storage\Common\Internal\Validate; +use MicrosoftAzure\Storage\Common\Internal\Utilities; + +/** + * Holds result of calling setBlobProperties wrapper + * + * @category Microsoft + * @package MicrosoftAzure\Storage\Blob\Models + * @author Azure Storage PHP SDK + * @copyright 2016 Microsoft Corporation + * @license https://github.com/azure/azure-storage-php/LICENSE + * @link https://github.com/azure/azure-storage-php + */ +class SetBlobPropertiesResult +{ + private $_lastModified; + private $_etag; + private $_sequenceNumber; + + /** + * Creates SetBlobPropertiesResult from response headers. + * + * @param array $headers response headers + * + * @internal + * + * @return SetBlobPropertiesResult + */ + public static function create(array $headers) + { + $result = new SetBlobPropertiesResult(); + $date = Utilities::tryGetValueInsensitive( + Resources::LAST_MODIFIED, + $headers + ); + $result->setLastModified(Utilities::rfc1123ToDateTime($date)); + $result->setETag(Utilities::tryGetValueInsensitive( + Resources::ETAG, + $headers + )); + $result->setSequenceNumber(Utilities::tryGetValueInsensitive( + Resources::X_MS_BLOB_SEQUENCE_NUMBER, + $headers + )); + + return $result; + } + + /** + * Gets blob lastModified. + * + * @return \DateTime + */ + public function getLastModified() + { + return $this->_lastModified; + } + + /** + * Sets blob lastModified. + * + * @param \DateTime $lastModified value. + * + * @return void + */ + protected function setLastModified(\DateTime $lastModified) + { + Validate::isDate($lastModified); + $this->_lastModified = $lastModified; + } + + /** + * Gets blob etag. + * + * @return string + */ + public function getETag() + { + return $this->_etag; + } + + /** + * Sets blob etag. + * + * @param string $etag value. + * + * @return void + */ + protected function setETag($etag) + { + Validate::canCastAsString($etag, 'etag'); + $this->_etag = $etag; + } + + /** + * Gets blob sequenceNumber. + * + * @return int + */ + public function getSequenceNumber() + { + return $this->_sequenceNumber; + } + + /** + * Sets blob sequenceNumber. + * + * @param int $sequenceNumber value. + * + * @return void + */ + protected function setSequenceNumber($sequenceNumber) + { + Validate::isInteger($sequenceNumber, 'sequenceNumber'); + $this->_sequenceNumber = $sequenceNumber; + } +}