зеркало из
1
0
Форкнуть 0

source code copied from azure-storage-php for v1.2.0-blob release

This commit is contained in:
Vincent Jiang (LEI) 2018-08-02 19:05:31 +08:00
Родитель 9a8c8a8f03
Коммит 6a89f277e8
11 изменённых файлов: 450 добавлений и 27 удалений

Просмотреть файл

@ -1,3 +1,10 @@
2018.08 - version 1.2.0
* Updated Azure Storage API version from 2016-05-31 to 2017-04-17.
* Added method `setBlobTier` method in `BlobRestProxy` to set blob tiers.
* Added support setting or getting blob tiers related properties when creating blobs, listing blobs, getting blob properties and copying blobs.
* Set the `getBlobUrl()` method in `BlobRestProxy` visibility to public.
2018.04 - version 1.1.0
* Private method BlobRestProxy::getBlobUrl now preserves primary URI path when exists.
@ -12,7 +19,7 @@
* Created `BlobSharedAccessSignatureHelper` and moved method `SharedAccessSignatureHelper::generateBlobServiceSharedAccessSignatureToken()` into `BlobSharedAccessSignatureHelper`.
* Added static builder methods `createBlobService` and `createContainerAnonymousAccess` into `BlobRestProxy`.
* Removed `dataSerializer` parameter from `BlobRextProxy` constructor.
* Removed `dataSerializer` parameter from `BlobRestProxy` 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.

Просмотреть файл

@ -1,6 +1,6 @@
{
"name": "microsoft/azure-storage-blob",
"version": "1.1.0",
"version": "1.2.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",
@ -12,7 +12,7 @@
],
"require": {
"php": ">=5.6.0",
"microsoft/azure-storage-common": "~1.1"
"microsoft/azure-storage-common": "~1.2.0"
},
"autoload": {
"psr-4": {

Просмотреть файл

@ -45,6 +45,7 @@ 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\CreatePageBlobOptions;
use MicrosoftAzure\Storage\Blob\Models\DeleteBlobOptions;
use MicrosoftAzure\Storage\Blob\Models\GetBlobMetadataOptions;
use MicrosoftAzure\Storage\Blob\Models\GetBlobMetadataResult;
@ -71,6 +72,7 @@ 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\Blob\Models\SetBlobTierOptions;
use MicrosoftAzure\Storage\Common\Internal\Authentication\SharedAccessSignatureAuthScheme;
use MicrosoftAzure\Storage\Common\Internal\Authentication\SharedKeyAuthScheme;
use MicrosoftAzure\Storage\Common\Internal\Http\HttpFormatter;
@ -376,7 +378,7 @@ class BlobRestProxy extends ServiceRestProxy implements IBlob
*
* @return string
*/
private function getBlobUrl($container, $blob)
public function getBlobUrl($container, $blob)
{
$encodedBlob = $this->createPath($container, $blob);
$uri = $this->getPsrPrimaryUri();
@ -1337,6 +1339,82 @@ class BlobRestProxy extends ServiceRestProxy implements IBlob
);
}
/**
* Sets blob tier on the blob.
*
* @param string $container name
* @param string $blob name of the blob
* @param Models\SetBlobTierOptions $options optional parameters
*
* @return void
*
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-blob-tier
*/
public function setBlobTier(
$container,
$blob,
Models\SetBlobTierOptions $options = null
) {
$this->setBlobTierAsync($container, $blob, $options)->wait();
}
/**
* Sets blob tier on the blob.
*
* @param string $container name
* @param string $blob name of the blob
* @param Models\SetBlobTierOptions $options optional parameters
*
* @return \GuzzleHttp\Promise\PromiseInterface
*
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-blob-tier
*/
public function setBlobTierAsync(
$container,
$blob,
Models\SetBlobTierOptions $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 SetBlobTierOptions();
}
$this->addOptionalQueryParam(
$queryParams,
Resources::QP_COMP,
'tier'
);
$this->addOptionalHeader(
$headers,
Resources::X_MS_ACCESS_TIER,
$options->getAccessTier()
);
$options->setLocationMode(LocationMode::PRIMARY_ONLY);
return $this->sendAsync(
$method,
$headers,
$queryParams,
$postParams,
$path,
array(Resources::STATUS_OK, Resources::STATUS_ACCEPTED),
Resources::EMPTY_STRING,
$options
);
}
/**
* Lists all of the blobs in the given container.
*
@ -1462,7 +1540,7 @@ class BlobRestProxy extends ServiceRestProxy implements IBlob
* The page blob size must be
* aligned to a 512-byte
* boundary.
* @param Models\CreateBlobOptions $options The optional parameters.
* @param Models\CreatePageBlobOptions $options The optional parameters.
*
* @return Models\PutBlobResult
*
@ -1472,7 +1550,7 @@ class BlobRestProxy extends ServiceRestProxy implements IBlob
$container,
$blob,
$length,
Models\CreateBlobOptions $options = null
Models\CreatePageBlobOptions $options = null
) {
return $this->createPageBlobAsync(
$container,
@ -1494,7 +1572,7 @@ class BlobRestProxy extends ServiceRestProxy implements IBlob
* The page blob size must be
* aligned to a 512-byte
* boundary.
* @param Models\CreateBlobOptions $options The optional parameters.
* @param Models\CreatePageBlobOptions $options The optional parameters.
*
* @return \GuzzleHttp\Promise\PromiseInterface
*
@ -1504,7 +1582,7 @@ class BlobRestProxy extends ServiceRestProxy implements IBlob
$container,
$blob,
$length,
Models\CreateBlobOptions $options = null
Models\CreatePageBlobOptions $options = null
) {
Validate::canCastAsString($container, 'container');
Validate::canCastAsString($blob, 'blob');
@ -1519,7 +1597,7 @@ class BlobRestProxy extends ServiceRestProxy implements IBlob
$path = $this->createPath($container, $blob);
if (is_null($options)) {
$options = new CreateBlobOptions();
$options = new CreatePageBlobOptions();
}
$this->addOptionalHeader(
@ -1537,6 +1615,11 @@ class BlobRestProxy extends ServiceRestProxy implements IBlob
Resources::X_MS_BLOB_SEQUENCE_NUMBER,
$options->getSequenceNumber()
);
$this->addOptionalHeader(
$headers,
Resources::X_MS_ACCESS_TIER,
$options->getAccessTier()
);
$headers = $this->addCreateBlobOptionalHeaders($options, $headers);
$options->setLocationMode(LocationMode::PRIMARY_ONLY);
@ -3521,7 +3604,7 @@ class BlobRestProxy extends ServiceRestProxy implements IBlob
* @param Models\GetBlobOptions $options optional parameters
*
* @return \GuzzleHttp\Promise\PromiseInterface
*
* @throws \Exception
* @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179440.aspx
*/
public function saveBlobToFileAsync(
@ -4024,6 +4107,12 @@ class BlobRestProxy extends ServiceRestProxy implements IBlob
$options->getSourceLeaseId()
);
$this->addOptionalHeader(
$headers,
Resources::X_MS_ACCESS_TIER,
$options->getAccessTier()
);
$options->setLocationMode(LocationMode::PRIMARY_ONLY);
return $this->sendAsync(

Просмотреть файл

@ -41,8 +41,8 @@ class BlobResources extends Resources
{
// @codingStandardsIgnoreStart
const BLOB_SDK_VERSION = '1.1.0';
const STORAGE_API_LATEST_VERSION = '2016-05-31';
const BLOB_SDK_VERSION = '1.2.0';
const STORAGE_API_LATEST_VERSION = '2017-04-17';
// Error messages
const INVALID_BTE_MSG = "The blob block type must exist in %s";
@ -83,6 +83,10 @@ class BlobResources extends Resources
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 X_MS_ACCESS_TIER = 'x-ms-access-tier';
const X_MS_ACCESS_TIER_INFERRED = 'x-ms-access-tier-inferred';
const X_MS_ACCESS_TIER_CHANGE_TIME = 'x-ms-access-tier-change-time';
const X_MS_ARCHIVE_STATUS = 'x-ms-archive-status';
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';

Просмотреть файл

@ -27,7 +27,6 @@ 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;
/**
@ -406,7 +405,7 @@ interface IBlob
* @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
* @param BlobModels\CreatePageBlobOptions $options optional parameters
*
* @return BlobModels\CopyBlobResult
*
@ -416,7 +415,7 @@ interface IBlob
$container,
$blob,
$length,
BlobModels\CreateBlobOptions $options = null
BlobModels\CreatePageBlobOptions $options = null
);
/**
@ -431,7 +430,7 @@ interface IBlob
* 1 TB. The page blob size
* must be aligned to a
* 512-byte boundary.
* @param BlobModels\CreateBlobOptions $options The optional parameters.
* @param BlobModels\CreatePageBlobOptions $options The optional parameters.
*
* @return \GuzzleHttp\Promise\PromiseInterface
*
@ -441,7 +440,7 @@ interface IBlob
$container,
$blob,
$length,
BlobModels\CreateBlobOptions $options = null
BlobModels\CreatePageBlobOptions $options = null
);
/**
@ -450,9 +449,9 @@ interface IBlob
*
* @param string $container The container name.
* @param string $blob The blob name.
* @param Models\CreateBlobOptions $options The optional parameters.
* @param BlobModels\CreateBlobOptions $options The optional parameters.
*
* @return Models\PutBlobResult
* @return BlobModels\PutBlobResult
*
* @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179451.aspx
*/
@ -469,7 +468,7 @@ interface IBlob
*
* @param string $container The container name.
* @param string $blob The blob name.
* @param Models\CreateBlobOptions $options The optional parameters.
* @param BlobModels\CreateBlobOptions $options The optional parameters.
*
* @return \GuzzleHttp\Promise\PromiseInterface
*
@ -721,9 +720,9 @@ interface IBlob
* @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
* @param BlobModels\AppendBlockOptions $options optional parameters
*
* @return Models\AppendBlockResult
* @return BlobModels\AppendBlockResult
*
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/append-block
*/
@ -740,7 +739,7 @@ interface IBlob
* @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
* @param BlobModels\AppendBlockOptions $options optional parameters
*
* @return \GuzzleHttp\Promise\PromiseInterface
*
@ -1021,6 +1020,40 @@ interface IBlob
BlobModels\ListPageBlobRangesOptions $options = null
);
/**
* Sets blob tier on the blob.
*
* @param string $container name
* @param string $blob name of the blob
* @param BlobModels\SetBlobTierOptions $options optional parameters
*
* @return void
*
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-blob-tier
*/
public function setBlobTier(
$container,
$blob,
BlobModels\SetBlobTierOptions $options = null
);
/**
* Sets blob tier on the blob.
*
* @param string $container name
* @param string $blob name of the blob
* @param BlobModels\SetBlobTierOptions $options optional parameters
*
* @return \GuzzleHttp\Promise\PromiseInterface
*
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-blob-tier
*/
public function setBlobTierAsync(
$container,
$blob,
BlobModels\SetBlobTierOptions $options = null
);
/**
* Sets system properties defined for a blob.
*
@ -1356,9 +1389,9 @@ interface IBlob
* @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
* @param BlobModels\BlobServiceOptions $options optional parameters
*
* @return Models\LeaseResult
* @return BlobModels\LeaseResult
*
* @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691972.aspx
*/
@ -1380,7 +1413,7 @@ interface IBlob
* @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
* @param BlobModels\BlobServiceOptions $options optional parameters
*
* @return \GuzzleHttp\Promise\PromiseInterface
*

Просмотреть файл

@ -0,0 +1,70 @@
<?php
/**
* LICENSE: The MIT License (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://github.com/azure/azure-storage-php/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* PHP version 5
*
* @category Microsoft
* @package MicrosoftAzure\Storage\Common\Models
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
* @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;
/**
* Trait implementing setting and getting accessTier.
*
* @category Microsoft
* @package MicrosoftAzure\Storage\Blob\Models
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
* @copyright 2018 Microsoft Corporation
* @license https://github.com/azure/azure-storage-php/LICENSE
* @link https://github.com/azure/azure-storage-php
*/
trait AccessTierTrait
{
/**
* @var string $accessTier Version 2017-04-17 and newer. For page blobs on a premium storage account, otherwise a block blob
* on blob storage account or storageV2 general account.
* Specifies the tier to be set on the blob. Currently, for block blob, tiers like "Hot", "Cool"
* and "Archive" can be used; for premium page blobs, "P4", "P6", "P10" and etc. can be set.
* Check following link for a full list of supported tiers.
* https://docs.microsoft.com/en-us/rest/api/storageservices/set-blob-tier
*/
private $accessTier;
/**
* Gets blob access tier.
*
* @return string
*/
public function getAccessTier()
{
return $this->accessTier;
}
/**
* Sets blob access tier.
*
* @param string $accessTier value.
*
* @return void
*/
public function setAccessTier($accessTier)
{
$this->accessTier = $accessTier;
}
}

Просмотреть файл

@ -61,6 +61,10 @@ class BlobProperties
private $copyDestinationSnapshot;
private $incrementalCopy;
private $rangeContentMD5;
private $accessTier;
private $accessTierInferred;
private $accessTierChangeTime;
private $archiveStatus;
/**
* Creates BlobProperties object from $parsed response in array representation of XML elements
@ -89,6 +93,27 @@ class BlobProperties
)
);
$result->setAccessTier((
Utilities::tryGetValue($clean, 'accesstier')
));
$result->setAccessTierInferred(
Utilities::toBoolean(
Utilities::tryGetValue($clean, 'accesstierinferred'),
true
)
);
$date = Utilities::tryGetValue($clean, 'accesstierchangetime');
if (!is_null($date)) {
$date = Utilities::rfc1123ToDateTime($date);
$result->setAccessTierChangeTime($date);
}
$result->setArchiveStatus(
Utilities::tryGetValue($clean, 'archivestatus')
);
return $result;
}
@ -145,6 +170,27 @@ class BlobProperties
)
);
$result->setAccessTier((
Utilities::tryGetValue($clean, Resources::X_MS_ACCESS_TIER)
));
$result->setAccessTierInferred(
Utilities::toBoolean(
Utilities::tryGetValue($clean, Resources::X_MS_ACCESS_TIER_INFERRED),
true
)
);
$date = Utilities::tryGetValue($clean, Resources::X_MS_ACCESS_TIER_CHANGE_TIME);
if (!is_null($date)) {
$date = Utilities::rfc1123ToDateTime($date);
$result->setAccessTierChangeTime($date);
}
$result->setArchiveStatus(
Utilities::tryGetValue($clean, Resources::X_MS_ARCHIVE_STATUS)
);
return $result;
}
@ -282,6 +328,96 @@ class BlobProperties
$this->contentEncoding = $contentEncoding;
}
/**
* Gets blob access tier.
*
* @return string
*/
public function getAccessTier()
{
return $this->accessTier;
}
/**
* Sets blob access tier.
*
* @param string $accessTier value.
*
* @return void
*/
public function setAccessTier($accessTier)
{
$this->accessTier = $accessTier;
}
/**
* Gets blob archive status.
*
* @return string
*/
public function getArchiveStatus()
{
return $this->archiveStatus;
}
/**
* Sets blob archive status.
*
* @param string $archiveStatus value.
*
* @return void
*/
public function setArchiveStatus($archiveStatus)
{
$this->archiveStatus = $archiveStatus;
}
/**
* Gets blob access inferred.
*
* @return boolean
*/
public function getAccessTierInferred()
{
return $this->accessTierInferred;
}
/**
* Sets blob access tier inferred.
*
* @param boolean $accessTierInferred value.
*
* @return void
*/
public function setAccessTierInferred($accessTierInferred)
{
Validate::isBoolean($accessTierInferred);
$this->accessTierInferred = $accessTierInferred;
}
/**
* Gets blob access tier change time.
*
* @return \DateTime
*/
public function getAccessTierChangeTime()
{
return $this->accessTierChangeTime;
}
/**
* Sets blob access tier change time.
*
* @param \DateTime $accessTierChangeTime value.
*
* @return void
*/
public function setAccessTierChangeTime(\DateTime $accessTierChangeTime)
{
Validate::isDate($accessTierChangeTime);
$this->accessTierChangeTime = $accessTierChangeTime;
}
/**
* Gets blob contentLanguage.
*

Просмотреть файл

@ -36,6 +36,8 @@ namespace MicrosoftAzure\Storage\Blob\Models;
*/
class CopyBlobFromURLOptions extends BlobServiceOptions
{
use AccessTierTrait;
private $sourceLeaseId;
private $sourceAccessConditions;
private $metadata;

Просмотреть файл

@ -36,7 +36,7 @@ use MicrosoftAzure\Storage\Common\Models\TransactionalMD5Trait;
* @license https://github.com/azure/azure-storage-php/LICENSE
* @link https://github.com/azure/azure-storage-php
*/
class CreatePageBlobFromContentOptions extends CreateBlobOptions
class CreatePageBlobFromContentOptions extends CreatePageBlobOptions
{
use TransactionalMD5Trait;
}

Просмотреть файл

@ -0,0 +1,40 @@
<?php
/**
* LICENSE: The MIT License (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://github.com/azure/azure-storage-php/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* PHP version 5
*
* @category Microsoft
* @package MicrosoftAzure\Storage\Blob\Models
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
* @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;
/**
* Optional parameters for CreatePageBlob.
*
* @category Microsoft
* @package MicrosoftAzure\Storage\Blob\Models
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
* @copyright 2018 Microsoft Corporation
* @license https://github.com/azure/azure-storage-php/LICENSE
* @link https://github.com/azure/azure-storage-php
*/
class CreatePageBlobOptions extends CreateBlobOptions
{
use AccessTierTrait;
}

Просмотреть файл

@ -0,0 +1,42 @@
<?php
/**
* LICENSE: The MIT License (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* https://github.com/azure/azure-storage-php/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* PHP version 5
*
* @category Microsoft
* @package MicrosoftAzure\Storage\Blob\Models
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
* @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\ServiceOptions;
/**
* Optional parameters for SetBlobTier.
*
* @category Microsoft
* @package MicrosoftAzure\Storage\Blob\Models
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
* @copyright 2018 Microsoft Corporation
* @license https://github.com/azure/azure-storage-php/LICENSE
* @link https://github.com/azure/azure-storage-php
*/
class SetBlobTierOptions extends ServiceOptions
{
use AccessTierTrait;
}