Обновление клиента (apps, 3rdparty, install)
This commit is contained in:
@@ -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.
|
||||
@@ -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.
|
||||
@@ -0,0 +1,58 @@
|
||||
2022.08 - version 1.5.4
|
||||
* Check `$copyProgress` is not null before using it in `strpos`.
|
||||
|
||||
2021.09 - version 1.5.3
|
||||
* Upgraded dependency for `azure-storage-common` to version 1.5.2.
|
||||
* Resolved some interface inconsistency between `IBlob`/`BlobRestProxy`.
|
||||
* Imported `Psr\Http\Message\StreamInterface` in `IBlob`.
|
||||
|
||||
2020.12 - version 1.5.2
|
||||
* Resolved an issue where access condition does not work for large block blob uploads.
|
||||
* Guzzle version is now updated to support both 6.x and 7.x.
|
||||
|
||||
2020.08 - version 1.5.1
|
||||
* Lower case query parameter names.
|
||||
|
||||
2020.01 - version 1.5.0
|
||||
|
||||
* Added support to include deleted in blob list.
|
||||
* Added support to undelete a blob.
|
||||
* Fixed the issue in SAS token where special characters were not correctly encoded.
|
||||
* Samples no longer uses ‘BlobRestProxy’ directly, instead, ‘ServicesBuilder’ is used.
|
||||
|
||||
2019.04 - version 1.4.0
|
||||
|
||||
* Added support for OAuth authentication.
|
||||
* Resolved some issues on Linux platform.
|
||||
|
||||
2019.03 - version 1.3.0
|
||||
|
||||
* Fixed a bug where blob name '0' cannot be created.
|
||||
* Documentation refinement.
|
||||
* `ListContainer` now can have ETag more robustly fetched from response header.
|
||||
|
||||
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.
|
||||
* MD files are modified for better readability and formatting.
|
||||
* CACERT can now be set when creating RestProxies using `$options` parameter.
|
||||
* Added a sample in `BlobSamples.php` to list all blobs with certain prefix. This is a recommended implementation of using continuation token to list all the blobs.
|
||||
* Removed unnecessary trailing spaces.
|
||||
* Assertions are re-factored in test cases.
|
||||
* Now the test framework uses `PHPUnit\Framework\TestCase` instead of `PHPUnit_Framework_TestCase`.
|
||||
|
||||
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 `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.
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
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:
|
||||
|
||||
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.
|
||||
File diff suppressed because it is too large
Load Diff
+213
@@ -0,0 +1,213 @@
|
||||
<?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
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @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 <dmsh@microsoft.com>
|
||||
* @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 = 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
<?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\Internal
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @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 <dmsh@microsoft.com>
|
||||
* @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.5.4';
|
||||
const STORAGE_API_LATEST_VERSION = '2017-11-09';
|
||||
|
||||
// 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 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';
|
||||
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
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,355 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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.
|
||||
* <p>
|
||||
* Setting this access condition modifies the request to include the HTTP
|
||||
* <i>If-Match</i> conditional header. If this access condition is set, the
|
||||
* operation is performed only if the ETag of the resource matches the specified
|
||||
* ETag.
|
||||
* <p>
|
||||
* For more information, see
|
||||
* <a href= 'http://go.microsoft.com/fwlink/?LinkID=224642&clcid=0x409'>
|
||||
* Specifying Conditional Headers for Blob Service Operations</a>.
|
||||
*
|
||||
* @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.
|
||||
* <p>
|
||||
* Setting this access condition modifies the request to include the HTTP
|
||||
* <i>If-Modified-Since</i> conditional header. If this access condition is set,
|
||||
* the operation is performed only if the resource has been modified since the
|
||||
* specified time.
|
||||
* <p>
|
||||
* For more information, see
|
||||
* <a href= 'http://go.microsoft.com/fwlink/?LinkID=224642&clcid=0x409'>
|
||||
* Specifying Conditional Headers for Blob Service Operations</a>.
|
||||
*
|
||||
* @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.
|
||||
* <p>
|
||||
* Setting this access condition modifies the request to include the HTTP
|
||||
* <i>If-None-Match</i> 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.
|
||||
* <p>
|
||||
* For more information,
|
||||
* see <a href= 'http://go.microsoft.com/fwlink/?LinkID=224642&clcid=0x409'>
|
||||
* Specifying Conditional Headers for Blob Service Operations</a>.
|
||||
*
|
||||
* @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.
|
||||
* <p>
|
||||
* Setting this access condition modifies the request to include the HTTP
|
||||
* <i>If-Unmodified-Since</i> conditional header. If this access condition is
|
||||
* set, the operation is performed only if the resource has not been modified
|
||||
* since the specified time.
|
||||
* <p>
|
||||
* For more information, see
|
||||
* <a href= 'http://go.microsoft.com/fwlink/?LinkID=224642&clcid=0x409'>
|
||||
* Specifying Conditional Headers for Blob Service Operations</a>.
|
||||
*
|
||||
* @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.
|
||||
* <p>
|
||||
* Setting this access condition modifies the request to include the HTTP
|
||||
* <i>x-ms-blob-condition-appendpos</i> conditional header. If this access condition
|
||||
* is set, the operation is performed only if the append position is equal to this number
|
||||
* <p>
|
||||
* For more information,
|
||||
* see <a href= 'https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/append-block'>
|
||||
* Specifying Conditional Headers for Blob Service Operations</a>.
|
||||
*
|
||||
* @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.
|
||||
* <p>
|
||||
* Setting this access condition modifies the request to include the HTTP
|
||||
* <i>x-ms-blob-condition-maxsize</i> 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.
|
||||
* <p>
|
||||
* For more information,
|
||||
* see <a href= 'https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/append-block'>
|
||||
* Specifying Conditional Headers for Blob Service Operations</a>.
|
||||
*
|
||||
* @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.
|
||||
* <p>
|
||||
* Setting this access condition modifies the request to include the HTTP
|
||||
* <i>x-ms-if-sequence-number-lt</i> 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.
|
||||
* <p>
|
||||
* For more information,
|
||||
* see <a href= 'https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/put-page'>
|
||||
* Specifying Conditional Headers for Blob Service Operations</a>.
|
||||
*
|
||||
* @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.
|
||||
* <p>
|
||||
* Setting this access condition modifies the request to include the HTTP
|
||||
* <i>x-ms-if-sequence-number-eq</i> 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.
|
||||
* <p>
|
||||
* For more information,
|
||||
* see <a href= 'https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/put-page'>
|
||||
* Specifying Conditional Headers for Blob Service Operations</a>.
|
||||
*
|
||||
* @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.
|
||||
* <p>
|
||||
* Setting this access condition modifies the request to include the HTTP
|
||||
* <i>x-ms-if-sequence-number-le</i> 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.
|
||||
* <p>
|
||||
* For more information,
|
||||
* see <a href= 'https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/put-page'>
|
||||
* Specifying Conditional Headers for Blob Service Operations</a>.
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,887 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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 $creationTime;
|
||||
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;
|
||||
private $accessTier;
|
||||
private $accessTierInferred;
|
||||
private $accessTierChangeTime;
|
||||
private $archiveStatus;
|
||||
private $deletedTime;
|
||||
private $remainingRetentionDays;
|
||||
|
||||
/**
|
||||
* 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
|
||||
)
|
||||
);
|
||||
|
||||
$result->setAccessTier((
|
||||
Utilities::tryGetValue($clean, 'accesstier')
|
||||
));
|
||||
|
||||
$result->setAccessTierInferred(
|
||||
Utilities::toBoolean(
|
||||
Utilities::tryGetValue($clean, 'accesstierinferred'),
|
||||
true
|
||||
)
|
||||
);
|
||||
|
||||
$accesstierchangetime = Utilities::tryGetValue($clean, 'accesstierchangetime');
|
||||
if (!is_null($accesstierchangetime)) {
|
||||
$accesstierchangetime = Utilities::rfc1123ToDateTime($accesstierchangetime);
|
||||
$result->setAccessTierChangeTime($accesstierchangetime);
|
||||
}
|
||||
|
||||
$result->setArchiveStatus(
|
||||
Utilities::tryGetValue($clean, 'archivestatus')
|
||||
);
|
||||
|
||||
$deletedtime = Utilities::tryGetValue($clean, 'deletedtime');
|
||||
if (!is_null($deletedtime)) {
|
||||
$deletedtime = Utilities::rfc1123ToDateTime($deletedtime);
|
||||
$result->setDeletedTime($deletedtime);
|
||||
}
|
||||
|
||||
$remainingretentiondays = Utilities::tryGetValue($clean, 'remainingretentiondays');
|
||||
if (!is_null($remainingretentiondays)) {
|
||||
$result->setRemainingRetentionDays((int) $remainingretentiondays);
|
||||
}
|
||||
|
||||
$creationtime = Utilities::tryGetValue($clean, 'creation-time');
|
||||
if (!is_null($creationtime)) {
|
||||
$creationtime = Utilities::rfc1123ToDateTime($creationtime);
|
||||
$result->setCreationTime($creationtime);
|
||||
}
|
||||
|
||||
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
|
||||
)
|
||||
);
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 creationTime.
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getCreationTime()
|
||||
{
|
||||
return $this->creationTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets blob creationTime.
|
||||
*
|
||||
* @param \DateTime $creationTime value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setCreationTime(\DateTime $creationTime)
|
||||
{
|
||||
Validate::isDate($creationTime);
|
||||
$this->creationTime = $creationTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 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 deleted time.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDeletedTime()
|
||||
{
|
||||
return $this->deletedTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets blob deleted time.
|
||||
*
|
||||
* @param \DateTime $deletedTime value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDeletedTime(\DateTime $deletedTime)
|
||||
{
|
||||
$this->deletedTime = $deletedTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets blob remaining retention days.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getRemainingRetentionDays()
|
||||
{
|
||||
return $this->remainingRetentionDays;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets blob remaining retention days.
|
||||
*
|
||||
* @param integer $remainingRetentionDays value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setRemainingRetentionDays($remainingRetentionDays)
|
||||
{
|
||||
$this->remainingRetentionDays = $remainingRetentionDays;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @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_LOWER_CASE)
|
||||
);
|
||||
|
||||
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)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 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 <dmsh@microsoft.com>
|
||||
* @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';
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
+224
@@ -0,0 +1,224 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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());
|
||||
$result->setAccessConditions($options->getAccessConditions());
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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();
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
+184
@@ -0,0 +1,184 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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
|
||||
{
|
||||
use AccessTierTrait;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,294 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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 (!is_null($copyProgress) && 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 (!is_null($copyProgress) && 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;
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
+207
@@ -0,0 +1,207 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
+42
@@ -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\TransactionalMD5Trait;
|
||||
|
||||
/**
|
||||
* Optional parameters for CreateBlockBlob.
|
||||
*
|
||||
* @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 CreateBlockBlobOptions extends CreateBlobOptions
|
||||
{
|
||||
use TransactionalMD5Trait;
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
+42
@@ -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\TransactionalMD5Trait;
|
||||
|
||||
/**
|
||||
* Optional parameters for createPageBlobFromContent.
|
||||
*
|
||||
* @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 CreatePageBlobFromContentOptions extends CreatePageBlobOptions
|
||||
{
|
||||
use TransactionalMD5Trait;
|
||||
}
|
||||
+40
@@ -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,88 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
+175
@@ -0,0 +1,175 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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';
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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];
|
||||
}
|
||||
}
|
||||
+252
@@ -0,0 +1,252 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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_LOWER_CASE)
|
||||
);
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
private $_includeDeleted;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if deleted is included or not.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getIncludeDeleted()
|
||||
{
|
||||
return $this->_includeDeleted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the include deleted flag.
|
||||
*
|
||||
* @param bool $includeDeleted value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setIncludeDeleted($includeDeleted)
|
||||
{
|
||||
Validate::isBoolean($includeDeleted);
|
||||
$this->_includeDeleted = $includeDeleted;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
+251
@@ -0,0 +1,251 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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(Utilities::tryGetValueInsensitive(Resources::ETAG, $value['Properties']));
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
+182
@@ -0,0 +1,182 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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';
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
+252
@@ -0,0 +1,252 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
<?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 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 <dmsh@microsoft.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
<?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 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 deleteBlob wrapper
|
||||
*
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Blob\Models
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
class UndeleteBlobOptions extends BlobServiceOptions
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
Tracking Breaking changes in 1.0.0
|
||||
|
||||
* Removed `ServiceBuilder.php`, moved static builder methods into `BlobRestProxy`, `TableRestProxy`, `QueueRestProxy` and `FileRestProxy`.
|
||||
* Moved method `SharedAccessSignatureHelper::generateBlobServiceSharedAccessSignatureToken()` into `BlobSharedAccessSignatureHelper`.
|
||||
* Moved method `SharedAccessSignatureHelper::generateTableServiceSharedAccessSignatureToken()` into `TableSharedAccessSignatureHelper`.
|
||||
* Moved method `SharedAccessSignatureHelper::generateQueueServiceSharedAccessSignatureToken()` into `QueueSharedAccessSignatureHelper`.
|
||||
* Moved method `SharedAccessSignatureHelper::generateFileServiceSharedAccessSignatureToken()` into `FileSharedAccessSignatureHelper`.
|
||||
* `CommonMiddleWare` constructor requires storage service version as parameter now.
|
||||
* `AccessPolicy` class is now an abstract class, added children classes `BlobAccessPolicy`, `ContainerAccessPolicy`, `TableAccessPolicy`, `QueueAccessPolicy`, `FileAccessPolicy` and `ShareAccessPolicy`.
|
||||
* Deprecated PHP 5.5 support.
|
||||
@@ -0,0 +1 @@
|
||||
This [repository](https://github.com/azure/azure-storage-common-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.
|
||||
@@ -0,0 +1,57 @@
|
||||
2021.09 - version 1.5.2
|
||||
* Added support for guzzle 7.3.
|
||||
* Resolve some warnings when calling `Psr7\stream_for`, uses `Utils::streamFor` instead.
|
||||
* Added colon to non-UTC timestamps.
|
||||
* Fixed type hint for `ServiceException::getResponse()`.
|
||||
* Fixed random number range that might cause an overflow in the guid generation.
|
||||
* Added logic to convert to exception when promise is rejected with string.
|
||||
* Compares `strlen` result with an integer instead of string.
|
||||
|
||||
2020.12 - version 1.5.1
|
||||
* Guzzle version is now updated to support both 6.x and 7.x.
|
||||
|
||||
2020.08 - version 1.5.0
|
||||
* Resolved TLS 1.2 issue and some test issues.
|
||||
* Check $uri null type before array/string access.
|
||||
* Accept DateTimeImmutable as EdmType input.
|
||||
* Added client-request-id to requests.
|
||||
* Updated getContinuationToken return type.
|
||||
* Call static methods using `static::` not `self::`.
|
||||
* Added $isSecondary parameter for appendBlobRetryDecider.
|
||||
* Retry on no response from server after a successful connection
|
||||
|
||||
2020.01 - version 1.4.1
|
||||
* Changed to perform override existence instead of value check for ‘$options[‘verify’]’ in ‘ServiceRestProxy’.
|
||||
|
||||
2019.04 - version 1.4.0
|
||||
* Added support for OAuth authentication.
|
||||
* Resolved some issues on Linux platform.
|
||||
|
||||
2019.03 - version 1.3.0
|
||||
* Documentation refinement.
|
||||
|
||||
2018.08 - version 1.2.0
|
||||
|
||||
* Fixed a bug `generateCanonicalResource` returns an empty string if `$resource` starts with "/".
|
||||
* Supported optional middleware retry on connection failures.
|
||||
* Fixed a typo of `DEAFULT_RETRY_INTERVAL`.
|
||||
|
||||
2018.04 - version 1.1.0
|
||||
|
||||
* MD files are modified for better readability and formatting.
|
||||
* CACERT can now be set when creating RestProxies using `$options` parameter.
|
||||
* Removed unnecessary trailing spaces.
|
||||
* Assertions are re-factored in test cases.
|
||||
* Now the test framework uses `PHPUnit\Framework\TestCase` instead of `PHPUnit_Framework_TestCase`.
|
||||
|
||||
2018.01 - version 1.0.0
|
||||
|
||||
* Removed `ServiceBuilder.php`, moved static builder methods into `BlobRestProxy`, `TableRestProxy`, `QueueRestProxy` and `FileRestProxy`.
|
||||
* Moved method `SharedAccessSignatureHelper::generateBlobServiceSharedAccessSignatureToken()` into `BlobSharedAccessSignatureHelper`.
|
||||
* Moved method `SharedAccessSignatureHelper::generateTableServiceSharedAccessSignatureToken()` into `TableSharedAccessSignatureHelper`.
|
||||
* Moved method `SharedAccessSignatureHelper::generateQueueServiceSharedAccessSignatureToken()` into `QueueSharedAccessSignatureHelper`.
|
||||
* Moved method `SharedAccessSignatureHelper::generateFileServiceSharedAccessSignatureToken()` into `FileSharedAccessSignatureHelper`.
|
||||
* `CommonMiddleWare` constructor requires storage service version as parameter now.
|
||||
* `AccessPolicy` class is now an abstract class, added children classes `BlobAccessPolicy`, `ContainerAccessPolicy`, `TableAccessPolicy`, `QueueAccessPolicy`, `FileAccessPolicy` and `ShareAccessPolicy`.
|
||||
* Fixed a bug that `Utilities::allZero()` will return true for non-zero data chunks.
|
||||
* Deprecated PHP 5.5 support.
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
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:
|
||||
|
||||
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.
|
||||
+155
@@ -0,0 +1,155 @@
|
||||
<?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
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common;
|
||||
|
||||
use MicrosoftAzure\Storage\Common\Internal\Utilities;
|
||||
use MicrosoftAzure\Storage\Common\Internal\Validate;
|
||||
use MicrosoftAzure\Storage\Common\Internal\ConnectionStringSource;
|
||||
|
||||
/**
|
||||
* Configuration manager for accessing Windows Azure settings.
|
||||
*
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
class CloudConfigurationManager
|
||||
{
|
||||
private static $_isInitialized = false;
|
||||
private static $_sources;
|
||||
|
||||
/**
|
||||
* Restrict users from creating instances from this class
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the connection string source providers.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function _init()
|
||||
{
|
||||
if (!self::$_isInitialized) {
|
||||
self::$_sources = array();
|
||||
|
||||
// Get list of default connection string sources.
|
||||
$default = ConnectionStringSource::getDefaultSources();
|
||||
foreach ($default as $name => $provider) {
|
||||
self::$_sources[$name] = $provider;
|
||||
}
|
||||
|
||||
self::$_isInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a connection string from all available sources.
|
||||
*
|
||||
* @param string $key The connection string key name.
|
||||
*
|
||||
* @return string If the key does not exist return null.
|
||||
*/
|
||||
public static function getConnectionString($key)
|
||||
{
|
||||
Validate::canCastAsString($key, 'key');
|
||||
|
||||
self::_init();
|
||||
$value = null;
|
||||
|
||||
foreach (self::$_sources as $source) {
|
||||
$value = call_user_func_array($source, array($key));
|
||||
|
||||
if (!empty($value)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new connection string source provider. If the source to get
|
||||
* registered is a default source, only the name of the source is required.
|
||||
*
|
||||
* @param string $name The source name.
|
||||
* @param callable $provider The source callback.
|
||||
* @param boolean $prepend When true, the $provider is processed first when
|
||||
* calling getConnectionString. When false (the default) the $provider is
|
||||
* processed after the existing callbacks.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function registerSource($name, $provider = null, $prepend = false)
|
||||
{
|
||||
Validate::canCastAsString($name, 'name');
|
||||
Validate::notNullOrEmpty($name, 'name');
|
||||
|
||||
self::_init();
|
||||
$default = ConnectionStringSource::getDefaultSources();
|
||||
|
||||
// Try to get callback if the user is trying to register a default source.
|
||||
$provider = Utilities::tryGetValue($default, $name, $provider);
|
||||
|
||||
Validate::notNullOrEmpty($provider, 'callback');
|
||||
|
||||
if ($prepend) {
|
||||
self::$_sources = array_merge(
|
||||
array($name => $provider),
|
||||
self::$_sources
|
||||
);
|
||||
} else {
|
||||
self::$_sources[$name] = $provider;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a connection string source.
|
||||
*
|
||||
* @param string $name The source name.
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
public static function unregisterSource($name)
|
||||
{
|
||||
Validate::canCastAsString($name, 'name');
|
||||
Validate::notNullOrEmpty($name, 'name');
|
||||
|
||||
self::_init();
|
||||
|
||||
$sourceCallback = Utilities::tryGetValue(self::$_sources, $name);
|
||||
|
||||
if (!is_null($sourceCallback)) {
|
||||
unset(self::$_sources[$name]);
|
||||
}
|
||||
|
||||
return $sourceCallback;
|
||||
}
|
||||
}
|
||||
Vendored
+55
@@ -0,0 +1,55 @@
|
||||
<?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\Exceptions
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Exceptions;
|
||||
|
||||
use MicrosoftAzure\Storage\Common\Internal\Resources;
|
||||
|
||||
/**
|
||||
* Exception thrown if an argument type does not match with the expected type.
|
||||
*
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Exceptions
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
class InvalidArgumentTypeException extends \InvalidArgumentException
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $validType The valid type that should be provided by the user.
|
||||
* @param string $name The parameter name.
|
||||
*
|
||||
* @return InvalidArgumentTypeException
|
||||
*/
|
||||
public function __construct($validType, $name = null)
|
||||
{
|
||||
parent::__construct(
|
||||
sprintf(Resources::INVALID_PARAM_MSG, $name, $validType)
|
||||
);
|
||||
}
|
||||
}
|
||||
+177
@@ -0,0 +1,177 @@
|
||||
<?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\Exceptions
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Exceptions;
|
||||
|
||||
use MicrosoftAzure\Storage\Common\Internal\Serialization\XmlSerializer;
|
||||
use MicrosoftAzure\Storage\Common\Internal\Resources;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Fires when the response code is incorrect.
|
||||
*
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Exceptions
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
class ServiceException extends \LogicException
|
||||
{
|
||||
private $response;
|
||||
private $errorText;
|
||||
private $errorMessage;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param ResponseInterface $response The response received that causes the
|
||||
* exception.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return ServiceException
|
||||
*/
|
||||
public function __construct(ResponseInterface $response)
|
||||
{
|
||||
parent::__construct(
|
||||
sprintf(
|
||||
Resources::AZURE_ERROR_MSG,
|
||||
$response->getStatusCode(),
|
||||
$response->getReasonPhrase(),
|
||||
$response->getBody()
|
||||
)
|
||||
);
|
||||
$this->code = $response->getStatusCode();
|
||||
$this->response = $response;
|
||||
$this->errorText = $response->getReasonPhrase();
|
||||
$this->errorMessage = self::parseErrorMessage($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Error message to be parsed.
|
||||
*
|
||||
* @param ResponseInterface $response The response with a response body.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function parseErrorMessage(ResponseInterface $response)
|
||||
{
|
||||
//try to parse using xml serializer, if failed, return the whole body
|
||||
//as the error message.
|
||||
$serializer = new XmlSerializer();
|
||||
$errorMessage = '';
|
||||
try {
|
||||
$internalErrors = libxml_use_internal_errors(true);
|
||||
$parsedArray = $serializer->unserialize($response->getBody());
|
||||
$messages = array();
|
||||
foreach (libxml_get_errors() as $error) {
|
||||
$messages[] = $error->message;
|
||||
}
|
||||
if (!empty($messages)) {
|
||||
throw new \Exception(
|
||||
sprintf(Resources::ERROR_CANNOT_PARSE_XML, implode('; ', $messages))
|
||||
);
|
||||
}
|
||||
libxml_use_internal_errors($internalErrors);
|
||||
if (array_key_exists(Resources::XTAG_MESSAGE, $parsedArray)) {
|
||||
$errorMessage = $parsedArray[Resources::XTAG_MESSAGE];
|
||||
} else {
|
||||
$errorMessage = $response->getBody();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$errorMessage = $response->getBody();
|
||||
}
|
||||
return $errorMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets error text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getErrorText()
|
||||
{
|
||||
return $this->errorText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets detailed error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getErrorMessage()
|
||||
{
|
||||
return $this->errorMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the request ID of the failure.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRequestID()
|
||||
{
|
||||
$requestID = '';
|
||||
if (array_key_exists(
|
||||
Resources::X_MS_REQUEST_ID,
|
||||
$this->getResponse()->getHeaders()
|
||||
)) {
|
||||
$requestID = $this->getResponse()
|
||||
->getHeaders()[Resources::X_MS_REQUEST_ID][0];
|
||||
}
|
||||
return $requestID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Date of the failure.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDate()
|
||||
{
|
||||
$date = '';
|
||||
if (array_key_exists(
|
||||
Resources::DATE,
|
||||
$this->getResponse()->getHeaders()
|
||||
)) {
|
||||
$date = $this->getResponse()
|
||||
->getHeaders()[Resources::DATE][0];
|
||||
}
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the response of the failue.
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
return $this->response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
<?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
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Models
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2017 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal;
|
||||
|
||||
use MicrosoftAzure\Storage\Common\Models\AccessPolicy;
|
||||
use MicrosoftAzure\Storage\Common\Models\SignedIdentifier;
|
||||
use MicrosoftAzure\Storage\Common\Internal\Serialization\XmlSerializer;
|
||||
|
||||
/**
|
||||
* Provide base class for service ACLs.
|
||||
*
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Models
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2017 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
abstract class ACLBase
|
||||
{
|
||||
private $signedIdentifiers = array();
|
||||
private $resourceType = '';
|
||||
|
||||
/**
|
||||
* Create an AccessPolicy object by resource type.
|
||||
*
|
||||
* @return AccessPolicy
|
||||
*/
|
||||
abstract protected static function createAccessPolicy();
|
||||
|
||||
/**
|
||||
* Validate if the resource type for the class.
|
||||
*
|
||||
* @param string $resourceType the resource type to be validated.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract protected static function validateResourceType($resourceType);
|
||||
|
||||
/**
|
||||
* Converts signed identifiers to array representation for XML serialization
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
$array = array();
|
||||
|
||||
foreach ($this->getSignedIdentifiers() as $value) {
|
||||
$array[] = $value->toArray();
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts this signed identifiers to XML representation.
|
||||
*
|
||||
* @param XmlSerializer $xmlSerializer The XML serializer.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toXml(XmlSerializer $serializer)
|
||||
{
|
||||
$properties = array(
|
||||
XmlSerializer::DEFAULT_TAG => Resources::XTAG_SIGNED_IDENTIFIER,
|
||||
XmlSerializer::ROOT_NAME => Resources::XTAG_SIGNED_IDENTIFIERS
|
||||
);
|
||||
|
||||
return $serializer->serialize($this->toArray(), $properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the signed identifiers from a given parsed XML in array
|
||||
* representation.
|
||||
*
|
||||
* @param array|null $parsed The parsed XML into array representation.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function fromXmlArray(array $parsed = null)
|
||||
{
|
||||
$this->setSignedIdentifiers(array());
|
||||
|
||||
// Initialize signed identifiers.
|
||||
if (!empty($parsed) &&
|
||||
is_array($parsed[Resources::XTAG_SIGNED_IDENTIFIER])
|
||||
) {
|
||||
$entries = $parsed[Resources::XTAG_SIGNED_IDENTIFIER];
|
||||
$temp = Utilities::getArray($entries);
|
||||
|
||||
foreach ($temp as $value) {
|
||||
$accessPolicy = $value[Resources::XTAG_ACCESS_POLICY];
|
||||
$startString = urldecode(
|
||||
$accessPolicy[Resources::XTAG_SIGNED_START]
|
||||
);
|
||||
$expiryString = urldecode(
|
||||
$accessPolicy[Resources::XTAG_SIGNED_EXPIRY]
|
||||
);
|
||||
$start = Utilities::convertToDateTime($startString);
|
||||
$expiry = Utilities::convertToDateTime($expiryString);
|
||||
$permission = $accessPolicy[Resources::XTAG_SIGNED_PERMISSION];
|
||||
$id = $value[Resources::XTAG_SIGNED_ID];
|
||||
$this->addSignedIdentifier($id, $start, $expiry, $permission);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type of resource this ACL relate to.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getResourceType()
|
||||
{
|
||||
return $this->resourceType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the type of resource this ACL relate to.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setResourceType($resourceType)
|
||||
{
|
||||
static::validateResourceType($resourceType);
|
||||
$this->resourceType = $resourceType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a signed identifier to the ACL.
|
||||
*
|
||||
* @param string $id A unique id for this signed identifier.
|
||||
* @param \DateTime $start The time at which the Shared Access
|
||||
* Signature becomes valid. If omitted, start
|
||||
* time for this call is assumed to be the
|
||||
* time when the service receives the
|
||||
* request.
|
||||
* @param \DateTime $expiry The time at which the Shared Access
|
||||
* Signature becomes invalid.
|
||||
* @param string $permissions The permissions associated with the Shared
|
||||
* Access Signature. The user is restricted to
|
||||
* operations allowed by the permissions.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @see https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/establishing-a-stored-access-policy
|
||||
*/
|
||||
public function addSignedIdentifier(
|
||||
$id,
|
||||
\DateTime $start,
|
||||
\DateTime $expiry,
|
||||
$permissions
|
||||
) {
|
||||
Validate::canCastAsString($id, 'id');
|
||||
if ($start != null) {
|
||||
Validate::isDate($start);
|
||||
}
|
||||
Validate::isDate($expiry);
|
||||
Validate::canCastAsString($permissions, 'permissions');
|
||||
|
||||
$accessPolicy = static::createAccessPolicy();
|
||||
$accessPolicy->setStart($start);
|
||||
$accessPolicy->setExpiry($expiry);
|
||||
$accessPolicy->setPermission($permissions);
|
||||
|
||||
$signedIdentifier = new SignedIdentifier();
|
||||
$signedIdentifier->setId($id);
|
||||
$signedIdentifier->setAccessPolicy($accessPolicy);
|
||||
|
||||
// Remove the signed identifier with the same ID.
|
||||
$this->removeSignedIdentifier($id);
|
||||
|
||||
// There can be no more than 5 signed identifiers at the same time.
|
||||
Validate::isTrue(
|
||||
count($this->getSignedIdentifiers()) < 5,
|
||||
Resources::ERROR_TOO_MANY_SIGNED_IDENTIFIERS
|
||||
);
|
||||
|
||||
$this->signedIdentifiers[] = $signedIdentifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the signed identifier with given ID.
|
||||
*
|
||||
* @param string $id The ID of the signed identifier to be removed.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function removeSignedIdentifier($id)
|
||||
{
|
||||
Validate::canCastAsString($id, 'id');
|
||||
//var_dump($this->signedIdentifiers);
|
||||
for ($i = 0; $i < count($this->signedIdentifiers); ++$i) {
|
||||
if ($this->signedIdentifiers[$i]->getId() == $id) {
|
||||
array_splice($this->signedIdentifiers, $i, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets signed identifiers.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSignedIdentifiers()
|
||||
{
|
||||
return $this->signedIdentifiers;
|
||||
}
|
||||
|
||||
public function setSignedIdentifiers(array $signedIdentifiers)
|
||||
{
|
||||
// There can be no more than 5 signed identifiers at the same time.
|
||||
Validate::isTrue(
|
||||
count($signedIdentifiers) <= 5,
|
||||
Resources::ERROR_TOO_MANY_SIGNED_IDENTIFIERS
|
||||
);
|
||||
$this->signedIdentifiers = $signedIdentifiers;
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
<?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\Internal\Authentication
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal\Authentication;
|
||||
|
||||
use GuzzleHttp\Psr7\Request;
|
||||
|
||||
/**
|
||||
* Interface for azure authentication schemes.
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal\Authentication
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
interface IAuthScheme
|
||||
{
|
||||
/**
|
||||
* Signs a request.
|
||||
*
|
||||
* @param \GuzzleHttp\Psr7\Request $request HTTP request object.
|
||||
*
|
||||
* @abstract
|
||||
*
|
||||
* @return \GuzzleHttp\Psr7\Request
|
||||
*/
|
||||
public function signRequest(Request $request);
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
<?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\Internal\Authentication
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal\Authentication;
|
||||
|
||||
use GuzzleHttp\Psr7\Request;
|
||||
use MicrosoftAzure\Storage\Common\Internal\Resources;
|
||||
|
||||
/**
|
||||
* Base class for azure authentication schemes.
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal\Authentication
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
class SharedAccessSignatureAuthScheme implements IAuthScheme
|
||||
{
|
||||
/**
|
||||
* The sas token
|
||||
*/
|
||||
protected $sasToken;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $sasToken shared access signature token.
|
||||
*
|
||||
*/
|
||||
public function __construct($sasToken)
|
||||
{
|
||||
// Remove '?' in front of the SAS token if existing
|
||||
$this->sasToken = str_replace('?', '', $sasToken, $i);
|
||||
|
||||
if ($i > 1) {
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf(
|
||||
Resources::INVALID_SAS_TOKEN,
|
||||
$sasToken
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds authentication header to the request headers.
|
||||
*
|
||||
* @param \GuzzleHttp\Psr7\Request $request HTTP request object.
|
||||
*
|
||||
* @abstract
|
||||
*
|
||||
* @return \GuzzleHttp\Psr7\Request
|
||||
*/
|
||||
public function signRequest(Request $request)
|
||||
{
|
||||
// initial URI
|
||||
$uri = $request->getUri();
|
||||
|
||||
// new query values from SAS token
|
||||
$queryValues = explode('&', $this->sasToken);
|
||||
|
||||
// append SAS token query values to existing URI
|
||||
foreach ($queryValues as $queryField) {
|
||||
list($key, $value) = explode('=', $queryField);
|
||||
|
||||
$uri = \GuzzleHttp\Psr7\Uri::withQueryValue($uri, $key, $value);
|
||||
}
|
||||
|
||||
// replace URI
|
||||
return $request->withUri($uri, true);
|
||||
}
|
||||
}
|
||||
Vendored
+317
@@ -0,0 +1,317 @@
|
||||
<?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\Internal\Authentication
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal\Authentication;
|
||||
|
||||
use GuzzleHttp\Psr7\Query;
|
||||
use GuzzleHttp\Psr7\Request;
|
||||
use MicrosoftAzure\Storage\Common\Internal\Http\HttpFormatter;
|
||||
use MicrosoftAzure\Storage\Common\Internal\Resources;
|
||||
use MicrosoftAzure\Storage\Common\Internal\Utilities;
|
||||
|
||||
/**
|
||||
* Provides shared key authentication scheme for blob and queue. For more info
|
||||
* check: http://msdn.microsoft.com/en-us/library/windowsazure/dd179428.aspx
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal\Authentication
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
class SharedKeyAuthScheme implements IAuthScheme
|
||||
{
|
||||
/**
|
||||
* The account name
|
||||
*/
|
||||
protected $accountName;
|
||||
|
||||
/**
|
||||
* The account key
|
||||
*/
|
||||
protected $accountKey;
|
||||
|
||||
/**
|
||||
* The included headers
|
||||
*/
|
||||
protected $includedHeaders;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $accountName storage account name.
|
||||
* @param string $accountKey storage account primary or secondary key.
|
||||
*
|
||||
* @return SharedKeyAuthScheme
|
||||
*/
|
||||
public function __construct($accountName, $accountKey)
|
||||
{
|
||||
$this->accountKey = $accountKey;
|
||||
$this->accountName = $accountName;
|
||||
|
||||
$this->includedHeaders = array();
|
||||
$this->includedHeaders[] = Resources::CONTENT_ENCODING;
|
||||
$this->includedHeaders[] = Resources::CONTENT_LANGUAGE;
|
||||
$this->includedHeaders[] = Resources::CONTENT_LENGTH;
|
||||
$this->includedHeaders[] = Resources::CONTENT_MD5;
|
||||
$this->includedHeaders[] = Resources::CONTENT_TYPE;
|
||||
$this->includedHeaders[] = Resources::DATE;
|
||||
$this->includedHeaders[] = Resources::IF_MODIFIED_SINCE;
|
||||
$this->includedHeaders[] = Resources::IF_MATCH;
|
||||
$this->includedHeaders[] = Resources::IF_NONE_MATCH;
|
||||
$this->includedHeaders[] = Resources::IF_UNMODIFIED_SINCE;
|
||||
$this->includedHeaders[] = Resources::RANGE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the authorization signature for blob and queue shared key.
|
||||
*
|
||||
* @param array $headers request headers.
|
||||
* @param string $url reuqest url.
|
||||
* @param array $queryParams query variables.
|
||||
* @param string $httpMethod request http method.
|
||||
*
|
||||
* @see Blob and Queue Services (Shared Key Authentication) at
|
||||
* http://msdn.microsoft.com/en-us/library/windowsazure/dd179428.aspx
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function computeSignature(
|
||||
array $headers,
|
||||
$url,
|
||||
array $queryParams,
|
||||
$httpMethod
|
||||
) {
|
||||
$canonicalizedHeaders = $this->computeCanonicalizedHeaders($headers);
|
||||
|
||||
$canonicalizedResource = $this->computeCanonicalizedResource(
|
||||
$url,
|
||||
$queryParams
|
||||
);
|
||||
|
||||
$stringToSign = array();
|
||||
$stringToSign[] = strtoupper($httpMethod);
|
||||
|
||||
foreach ($this->includedHeaders as $header) {
|
||||
$stringToSign[] = Utilities::tryGetValueInsensitive($header, $headers);
|
||||
}
|
||||
|
||||
if (count($canonicalizedHeaders) > 0) {
|
||||
$stringToSign[] = implode("\n", $canonicalizedHeaders);
|
||||
}
|
||||
|
||||
$stringToSign[] = $canonicalizedResource;
|
||||
$stringToSign = implode("\n", $stringToSign);
|
||||
|
||||
return $stringToSign;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns authorization header to be included in the request.
|
||||
*
|
||||
* @param array $headers request headers.
|
||||
* @param string $url reuqest url.
|
||||
* @param array $queryParams query variables.
|
||||
* @param string $httpMethod request http method.
|
||||
*
|
||||
* @see Specifying the Authorization Header section at
|
||||
* http://msdn.microsoft.com/en-us/library/windowsazure/dd179428.aspx
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAuthorizationHeader(
|
||||
array $headers,
|
||||
$url,
|
||||
array $queryParams,
|
||||
$httpMethod
|
||||
) {
|
||||
$signature = $this->computeSignature(
|
||||
$headers,
|
||||
$url,
|
||||
$queryParams,
|
||||
$httpMethod
|
||||
);
|
||||
|
||||
return 'SharedKey ' . $this->accountName . ':' . base64_encode(
|
||||
hash_hmac('sha256', $signature, base64_decode($this->accountKey), true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes canonicalized headers for headers array.
|
||||
*
|
||||
* @param array $headers request headers.
|
||||
*
|
||||
* @see Constructing the Canonicalized Headers String section at
|
||||
* http://msdn.microsoft.com/en-us/library/windowsazure/dd179428.aspx
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function computeCanonicalizedHeaders($headers)
|
||||
{
|
||||
$canonicalizedHeaders = array();
|
||||
$normalizedHeaders = array();
|
||||
$validPrefix = Resources::X_MS_HEADER_PREFIX;
|
||||
|
||||
if (is_null($normalizedHeaders)) {
|
||||
return $canonicalizedHeaders;
|
||||
}
|
||||
|
||||
foreach ($headers as $header => $value) {
|
||||
// Convert header to lower case.
|
||||
$header = strtolower($header);
|
||||
|
||||
// Retrieve all headers for the resource that begin with x-ms-,
|
||||
// including the x-ms-date header.
|
||||
if (Utilities::startsWith($header, $validPrefix)) {
|
||||
// Unfold the string by replacing any breaking white space
|
||||
// (meaning what splits the headers, which is \r\n) with a single
|
||||
// space.
|
||||
$value = str_replace("\r\n", ' ', $value);
|
||||
|
||||
// Trim any white space around the colon in the header.
|
||||
$value = ltrim($value);
|
||||
$header = rtrim($header);
|
||||
|
||||
$normalizedHeaders[$header] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// Sort the headers lexicographically by header name, in ascending order.
|
||||
// Note that each header may appear only once in the string.
|
||||
ksort($normalizedHeaders);
|
||||
|
||||
foreach ($normalizedHeaders as $key => $value) {
|
||||
$canonicalizedHeaders[] = $key . ':' . $value;
|
||||
}
|
||||
|
||||
return $canonicalizedHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes canonicalized resources from URL using Table formar
|
||||
*
|
||||
* @param string $url request url.
|
||||
* @param array $queryParams request query variables.
|
||||
*
|
||||
* @see Constructing the Canonicalized Resource String section at
|
||||
* http://msdn.microsoft.com/en-us/library/windowsazure/dd179428.aspx
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function computeCanonicalizedResourceForTable($url, $queryParams)
|
||||
{
|
||||
$queryParams = array_change_key_case($queryParams);
|
||||
|
||||
// 1. Beginning with an empty string (""), append a forward slash (/),
|
||||
// followed by the name of the account that owns the accessed resource.
|
||||
$canonicalizedResource = '/' . $this->accountName;
|
||||
|
||||
// 2. Append the resource's encoded URI path, without any query parameters.
|
||||
$canonicalizedResource .= parse_url($url, PHP_URL_PATH);
|
||||
|
||||
// 3. The query string should include the question mark and the comp
|
||||
// parameter (for example, ?comp=metadata). No other parameters should
|
||||
// be included on the query string.
|
||||
if (array_key_exists(Resources::QP_COMP, $queryParams)) {
|
||||
$canonicalizedResource .= '?' . Resources::QP_COMP . '=';
|
||||
$canonicalizedResource .= $queryParams[Resources::QP_COMP];
|
||||
}
|
||||
|
||||
return $canonicalizedResource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes canonicalized resources from URL.
|
||||
*
|
||||
* @param string $url request url.
|
||||
* @param array $queryParams request query variables.
|
||||
*
|
||||
* @see Constructing the Canonicalized Resource String section at
|
||||
* http://msdn.microsoft.com/en-us/library/windowsazure/dd179428.aspx
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function computeCanonicalizedResource($url, $queryParams)
|
||||
{
|
||||
$queryParams = array_change_key_case($queryParams);
|
||||
|
||||
// 1. Beginning with an empty string (""), append a forward slash (/),
|
||||
// followed by the name of the account that owns the accessed resource.
|
||||
$canonicalizedResource = '/' . $this->accountName;
|
||||
|
||||
// 2. Append the resource's encoded URI path, without any query parameters.
|
||||
$canonicalizedResource .= parse_url($url, PHP_URL_PATH);
|
||||
|
||||
// 3. Retrieve all query parameters on the resource URI, including the comp
|
||||
// parameter if it exists.
|
||||
// 4. Sort the query parameters lexicographically by parameter name, in
|
||||
// ascending order.
|
||||
if (count($queryParams) > 0) {
|
||||
ksort($queryParams);
|
||||
}
|
||||
|
||||
// 5. Convert all parameter names to lowercase.
|
||||
// 6. URL-decode each query parameter name and value.
|
||||
// 7. Append each query parameter name and value to the string in the
|
||||
// following format:
|
||||
// parameter-name:parameter-value
|
||||
// 9. Group query parameters
|
||||
// 10. Append a new line character (\n) after each name-value pair.
|
||||
foreach ($queryParams as $key => $value) {
|
||||
// $value must already be ordered lexicographically
|
||||
// See: ServiceRestProxy::groupQueryValues
|
||||
$canonicalizedResource .= "\n" . $key . ':' . $value;
|
||||
}
|
||||
|
||||
return $canonicalizedResource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds authentication header to the request headers.
|
||||
*
|
||||
* @param \GuzzleHttp\Psr7\Request $request HTTP request object.
|
||||
*
|
||||
* @abstract
|
||||
*
|
||||
* @return \GuzzleHttp\Psr7\Request
|
||||
*/
|
||||
public function signRequest(Request $request)
|
||||
{
|
||||
$requestHeaders = HttpFormatter::formatHeaders($request->getHeaders());
|
||||
|
||||
$signedKey = $this->getAuthorizationHeader(
|
||||
$requestHeaders,
|
||||
$request->getUri(),
|
||||
Query::parse(
|
||||
$request->getUri()->getQuery()
|
||||
),
|
||||
$request->getMethod()
|
||||
);
|
||||
|
||||
return $request->withHeader(Resources::AUTHENTICATION, $signedKey);
|
||||
}
|
||||
}
|
||||
Vendored
+73
@@ -0,0 +1,73 @@
|
||||
<?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\Internal\Authentication
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2019 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal\Authentication;
|
||||
|
||||
use GuzzleHttp\Psr7\Request;
|
||||
use MicrosoftAzure\Storage\Common\Internal\Resources;
|
||||
use MicrosoftAzure\Storage\Common\Internal\Validate;
|
||||
|
||||
/**
|
||||
* Azure authentication scheme for token credential.
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal\Authentication
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2019 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
class TokenAuthScheme implements IAuthScheme
|
||||
{
|
||||
/**
|
||||
* The authentication token
|
||||
*/
|
||||
protected $tokenRef;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $token the token used for AAD authentication.
|
||||
*/
|
||||
public function __construct(&$token)
|
||||
{
|
||||
$this->tokenRef =& $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds authentication header to the request headers.
|
||||
*
|
||||
* @param \GuzzleHttp\Psr7\Request $request HTTP request object.
|
||||
*
|
||||
* @abstract
|
||||
*
|
||||
* @return \GuzzleHttp\Psr7\Request
|
||||
*/
|
||||
public function signRequest(Request $request)
|
||||
{
|
||||
$bearerToken = "Bearer ". $this->tokenRef;
|
||||
return $request->withHeader(Resources::AUTHENTICATION, $bearerToken);
|
||||
}
|
||||
}
|
||||
+335
@@ -0,0 +1,335 @@
|
||||
<?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\Internal
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal;
|
||||
|
||||
/**
|
||||
* Helper methods for parsing connection strings. The rules for formatting connection
|
||||
* strings are defined here:
|
||||
* www.connectionstrings.com/articles/show/important-rules-for-connection-strings
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
class ConnectionStringParser
|
||||
{
|
||||
const EXPECT_KEY = 'ExpectKey';
|
||||
const EXPECT_ASSIGNMENT = 'ExpectAssignment';
|
||||
const EXPECT_VALUE = 'ExpectValue';
|
||||
const EXPECT_SEPARATOR = 'ExpectSeparator';
|
||||
|
||||
private $_argumentName;
|
||||
private $_value;
|
||||
private $_pos;
|
||||
private $_state;
|
||||
|
||||
/**
|
||||
* Parses the connection string into a collection of key/value pairs.
|
||||
*
|
||||
* @param string $argumentName Name of the argument to be used in error
|
||||
* messages.
|
||||
* @param string $connectionString Connection string.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function parseConnectionString($argumentName, $connectionString)
|
||||
{
|
||||
Validate::canCastAsString($argumentName, 'argumentName');
|
||||
Validate::notNullOrEmpty($argumentName, 'argumentName');
|
||||
Validate::canCastAsString($connectionString, 'connectionString');
|
||||
Validate::notNullOrEmpty($connectionString, 'connectionString');
|
||||
|
||||
$parser = new ConnectionStringParser($argumentName, $connectionString);
|
||||
return $parser->_parse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the object.
|
||||
*
|
||||
* @param string $argumentName Name of the argument to be used in error
|
||||
* messages.
|
||||
* @param string $value Connection string.
|
||||
*/
|
||||
private function __construct($argumentName, $value)
|
||||
{
|
||||
$this->_argumentName = $argumentName;
|
||||
$this->_value = $value;
|
||||
$this->_pos = 0;
|
||||
$this->_state = ConnectionStringParser::EXPECT_KEY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the connection string.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
private function _parse()
|
||||
{
|
||||
$key = null;
|
||||
$value = null;
|
||||
$connectionStringValues = array();
|
||||
|
||||
while (true) {
|
||||
$this->_skipWhiteSpaces();
|
||||
|
||||
if ($this->_pos == strlen($this->_value)
|
||||
&& $this->_state != ConnectionStringParser::EXPECT_VALUE
|
||||
) {
|
||||
// Not stopping after the end has been reached and a value is
|
||||
// expected results in creating an empty value, which we expect.
|
||||
break;
|
||||
}
|
||||
|
||||
switch ($this->_state) {
|
||||
case ConnectionStringParser::EXPECT_KEY:
|
||||
$key = $this->_extractKey();
|
||||
$this->_state = ConnectionStringParser::EXPECT_ASSIGNMENT;
|
||||
break;
|
||||
|
||||
case ConnectionStringParser::EXPECT_ASSIGNMENT:
|
||||
$this->_skipOperator('=');
|
||||
$this->_state = ConnectionStringParser::EXPECT_VALUE;
|
||||
break;
|
||||
|
||||
case ConnectionStringParser::EXPECT_VALUE:
|
||||
$value = $this->_extractValue();
|
||||
$this->_state =
|
||||
ConnectionStringParser::EXPECT_SEPARATOR;
|
||||
$connectionStringValues[$key] = $value;
|
||||
$key = null;
|
||||
$value = null;
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->_skipOperator(';');
|
||||
$this->_state = ConnectionStringParser::EXPECT_KEY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Must end parsing in the valid state (expected key or separator)
|
||||
if ($this->_state == ConnectionStringParser::EXPECT_ASSIGNMENT) {
|
||||
throw $this->_createException(
|
||||
$this->_pos,
|
||||
Resources::MISSING_CONNECTION_STRING_CHAR,
|
||||
'='
|
||||
);
|
||||
}
|
||||
|
||||
return $connectionStringValues;
|
||||
}
|
||||
|
||||
/**
|
||||
*Generates an invalid connection string exception with the detailed error
|
||||
* message.
|
||||
*
|
||||
* @param integer $position The position of the error.
|
||||
* @param string $errorString The short error formatting string.
|
||||
*
|
||||
* @return \RuntimeException
|
||||
*/
|
||||
private function _createException($position, $errorString)
|
||||
{
|
||||
$arguments = func_get_args();
|
||||
|
||||
// Remove first and second arguments (position and error string)
|
||||
unset($arguments[0], $arguments[1]);
|
||||
|
||||
// Create a short error message.
|
||||
$errorString = vsprintf($errorString, $arguments);
|
||||
|
||||
// Add position.
|
||||
$errorString = sprintf(
|
||||
Resources::ERROR_PARSING_STRING,
|
||||
$errorString,
|
||||
$position
|
||||
);
|
||||
|
||||
// Create final error message.
|
||||
$errorString = sprintf(
|
||||
Resources::INVALID_CONNECTION_STRING,
|
||||
$this->_argumentName,
|
||||
$errorString
|
||||
);
|
||||
|
||||
return new \RuntimeException($errorString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips whitespaces at the current position.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function _skipWhiteSpaces()
|
||||
{
|
||||
while ($this->_pos < strlen($this->_value)
|
||||
&& ctype_space($this->_value[$this->_pos])
|
||||
) {
|
||||
$this->_pos++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the key's value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _extractValue()
|
||||
{
|
||||
$value = Resources::EMPTY_STRING;
|
||||
|
||||
if ($this->_pos < strlen($this->_value)) {
|
||||
$ch = $this->_value[$this->_pos];
|
||||
|
||||
if ($ch == '"' || $ch == '\'') {
|
||||
// Value is contained between double quotes or skipped single quotes.
|
||||
$this->_pos++;
|
||||
$value = $this->_extractString($ch);
|
||||
} else {
|
||||
$firstPos = $this->_pos;
|
||||
$isFound = false;
|
||||
|
||||
while ($this->_pos < strlen($this->_value) && !$isFound) {
|
||||
$ch = $this->_value[$this->_pos];
|
||||
|
||||
if ($ch == ';') {
|
||||
$isFound = true;
|
||||
} else {
|
||||
$this->_pos++;
|
||||
}
|
||||
}
|
||||
|
||||
$value = rtrim(
|
||||
substr($this->_value, $firstPos, $this->_pos - $firstPos)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts key at the current position.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _extractKey()
|
||||
{
|
||||
$key = null;
|
||||
$firstPos = $this->_pos;
|
||||
$ch = $this->_value[$this->_pos];
|
||||
|
||||
if ($ch == '"' || $ch == '\'') {
|
||||
$this->_pos++;
|
||||
$key = $this->_extractString($ch);
|
||||
} elseif ($ch == ';' || $ch == '=') {
|
||||
// Key name was expected.
|
||||
throw $this->_createException(
|
||||
$firstPos,
|
||||
Resources::ERROR_CONNECTION_STRING_MISSING_KEY
|
||||
);
|
||||
} else {
|
||||
while ($this->_pos < strlen($this->_value)) {
|
||||
$ch = $this->_value[$this->_pos];
|
||||
|
||||
// At this point we've read the key, break.
|
||||
if ($ch == '=') {
|
||||
break;
|
||||
}
|
||||
|
||||
$this->_pos++;
|
||||
}
|
||||
$key = rtrim(substr($this->_value, $firstPos, $this->_pos - $firstPos));
|
||||
}
|
||||
|
||||
if (strlen($key) == 0) {
|
||||
// Empty key name.
|
||||
throw $this->_createException(
|
||||
$firstPos,
|
||||
Resources::ERROR_CONNECTION_STRING_EMPTY_KEY
|
||||
);
|
||||
}
|
||||
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the string until the given quotation mark.
|
||||
*
|
||||
* @param string $quote The quotation mark terminating the string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _extractString($quote)
|
||||
{
|
||||
$firstPos = $this->_pos;
|
||||
|
||||
while ($this->_pos < strlen($this->_value)
|
||||
&& $this->_value[$this->_pos] != $quote
|
||||
) {
|
||||
$this->_pos++;
|
||||
}
|
||||
|
||||
if ($this->_pos == strlen($this->_value)) {
|
||||
// Runaway string.
|
||||
throw $this->_createException(
|
||||
$this->_pos,
|
||||
Resources::ERROR_CONNECTION_STRING_MISSING_CHARACTER,
|
||||
$quote
|
||||
);
|
||||
}
|
||||
|
||||
return substr($this->_value, $firstPos, $this->_pos++ - $firstPos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips specified operator.
|
||||
*
|
||||
* @param string $operatorChar The operator character.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
private function _skipOperator($operatorChar)
|
||||
{
|
||||
if ($this->_value[$this->_pos] != $operatorChar) {
|
||||
// Character was expected.
|
||||
throw $this->_createException(
|
||||
$this->_pos,
|
||||
Resources::MISSING_CONNECTION_STRING_CHAR,
|
||||
$operatorChar
|
||||
);
|
||||
}
|
||||
|
||||
$this->_pos++;
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
<?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\Internal
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal;
|
||||
|
||||
/**
|
||||
* Holder for default connection string sources used in CloudConfigurationManager.
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
class ConnectionStringSource
|
||||
{
|
||||
private static $_defaultSources;
|
||||
private static $_isInitialized;
|
||||
const ENVIRONMENT_SOURCE = 'environment_source';
|
||||
|
||||
/**
|
||||
* Initializes the default sources.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function _init()
|
||||
{
|
||||
if (!self::$_isInitialized) {
|
||||
self::$_defaultSources = array(
|
||||
self::ENVIRONMENT_SOURCE => array(__CLASS__, 'environmentSource')
|
||||
);
|
||||
self::$_isInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a connection string value from the system environment.
|
||||
*
|
||||
* @param string $key The connection string name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function environmentSource($key)
|
||||
{
|
||||
Validate::canCastAsString($key, 'key');
|
||||
|
||||
return getenv($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets list of default sources.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getDefaultSources()
|
||||
{
|
||||
self::_init();
|
||||
return self::$_defaultSources;
|
||||
}
|
||||
}
|
||||
+432
@@ -0,0 +1,432 @@
|
||||
<?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\Internal\Http
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal\Http;
|
||||
|
||||
use MicrosoftAzure\Storage\Common\Internal\Utilities;
|
||||
use MicrosoftAzure\Storage\Common\Internal\Resources;
|
||||
use MicrosoftAzure\Storage\Common\Internal\Validate;
|
||||
use MicrosoftAzure\Storage\Common\Models\ServiceOptions;
|
||||
|
||||
/**
|
||||
* Holds basic elements for making HTTP call.
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal\Http
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
class HttpCallContext
|
||||
{
|
||||
private $_method;
|
||||
private $_headers;
|
||||
private $_queryParams;
|
||||
private $_postParameters;
|
||||
private $_uri;
|
||||
private $_path;
|
||||
private $_statusCodes;
|
||||
private $_body;
|
||||
private $_serviceOptions;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_method = null;
|
||||
$this->_body = null;
|
||||
$this->_path = null;
|
||||
$this->_uri = null;
|
||||
$this->_queryParams = array();
|
||||
$this->_postParameters = array();
|
||||
$this->_statusCodes = array();
|
||||
$this->_headers = array();
|
||||
$this->_serviceOptions = new ServiceOptions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets method.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMethod()
|
||||
{
|
||||
return $this->_method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets method.
|
||||
*
|
||||
* @param string $method The method value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setMethod($method)
|
||||
{
|
||||
Validate::canCastAsString($method, 'method');
|
||||
|
||||
$this->_method = $method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets headers.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHeaders()
|
||||
{
|
||||
return $this->_headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets headers.
|
||||
*
|
||||
* Ignores the header if its value is empty.
|
||||
*
|
||||
* @param array $headers The headers value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setHeaders(array $headers)
|
||||
{
|
||||
$this->_headers = array();
|
||||
foreach ($headers as $key => $value) {
|
||||
$this->addHeader($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets queryParams.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getQueryParameters()
|
||||
{
|
||||
return $this->_queryParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets queryParams.
|
||||
*
|
||||
* Ignores the query variable if its value is empty.
|
||||
*
|
||||
* @param array $queryParams The queryParams value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setQueryParameters(array $queryParams)
|
||||
{
|
||||
$this->_queryParams = array();
|
||||
foreach ($queryParams as $key => $value) {
|
||||
$this->addQueryParameter($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets uri.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUri()
|
||||
{
|
||||
return $this->_uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets uri.
|
||||
*
|
||||
* @param string $uri The uri value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUri($uri)
|
||||
{
|
||||
Validate::canCastAsString($uri, 'uri');
|
||||
|
||||
$this->_uri = $uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPath()
|
||||
{
|
||||
return $this->_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets path.
|
||||
*
|
||||
* @param string $path The path value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setPath($path)
|
||||
{
|
||||
Validate::canCastAsString($path, 'path');
|
||||
|
||||
$this->_path = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets statusCodes.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStatusCodes()
|
||||
{
|
||||
return $this->_statusCodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets statusCodes.
|
||||
*
|
||||
* @param array $statusCodes The statusCodes value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setStatusCodes(array $statusCodes)
|
||||
{
|
||||
$this->_statusCodes = array();
|
||||
foreach ($statusCodes as $value) {
|
||||
$this->addStatusCode($value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets body.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
return $this->_body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets body.
|
||||
*
|
||||
* @param string $body The body value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setBody($body)
|
||||
{
|
||||
Validate::canCastAsString($body, 'body');
|
||||
|
||||
$this->_body = $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds or sets header pair.
|
||||
*
|
||||
* @param string $name The HTTP header name.
|
||||
* @param string $value The HTTP header value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addHeader($name, $value)
|
||||
{
|
||||
Validate::canCastAsString($name, 'name');
|
||||
Validate::canCastAsString($value, 'value');
|
||||
|
||||
$this->_headers[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds or sets header pair.
|
||||
*
|
||||
* Ignores header if it's value satisfies empty().
|
||||
*
|
||||
* @param string $name The HTTP header name.
|
||||
* @param string $value The HTTP header value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addOptionalHeader($name, $value)
|
||||
{
|
||||
Validate::canCastAsString($name, 'name');
|
||||
Validate::canCastAsString($value, 'value');
|
||||
|
||||
if (!empty($value)) {
|
||||
$this->_headers[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes header from the HTTP request headers.
|
||||
*
|
||||
* @param string $name The HTTP header name.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function removeHeader($name)
|
||||
{
|
||||
Validate::canCastAsString($name, 'name');
|
||||
Validate::notNullOrEmpty($name, 'name');
|
||||
|
||||
unset($this->_headers[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds or sets query parameter pair.
|
||||
*
|
||||
* @param string $name The URI query parameter name.
|
||||
* @param string $value The URI query parameter value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addQueryParameter($name, $value)
|
||||
{
|
||||
Validate::canCastAsString($name, 'name');
|
||||
Validate::canCastAsString($value, 'value');
|
||||
|
||||
$this->_queryParams[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets HTTP POST parameters.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPostParameters()
|
||||
{
|
||||
return $this->_postParameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets HTTP POST parameters.
|
||||
*
|
||||
* @param array $postParameters The HTTP POST parameters.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setPostParameters(array $postParameters)
|
||||
{
|
||||
Validate::isArray($postParameters, 'postParameters');
|
||||
$this->_postParameters = $postParameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds or sets query parameter pair.
|
||||
*
|
||||
* Ignores query parameter if it's value satisfies empty().
|
||||
*
|
||||
* @param string $name The URI query parameter name.
|
||||
* @param string $value The URI query parameter value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addOptionalQueryParameter($name, $value)
|
||||
{
|
||||
Validate::canCastAsString($name, 'name');
|
||||
Validate::canCastAsString($value, 'value');
|
||||
|
||||
if (!empty($value)) {
|
||||
$this->_queryParams[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds status code to the expected status codes.
|
||||
*
|
||||
* @param integer $statusCode The expected status code.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addStatusCode($statusCode)
|
||||
{
|
||||
Validate::isInteger($statusCode, 'statusCode');
|
||||
|
||||
$this->_statusCodes[] = $statusCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets header value.
|
||||
*
|
||||
* @param string $name The header name.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getHeader($name)
|
||||
{
|
||||
return Utilities::tryGetValue($this->_headers, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the saved service options
|
||||
*
|
||||
* @return ServiceOptions
|
||||
*/
|
||||
public function getServiceOptions()
|
||||
{
|
||||
if ($this->_serviceOptions == null) {
|
||||
$this->_serviceOptions = new ServiceOptions();
|
||||
}
|
||||
return $this->_serviceOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the service options
|
||||
*
|
||||
* @param ServiceOptions $serviceOptions the service options to be set.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setServiceOptions(ServiceOptions $serviceOptions)
|
||||
{
|
||||
$this->_serviceOptions = $serviceOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the context object to string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$headers = Resources::EMPTY_STRING;
|
||||
$uri = $this->_uri;
|
||||
|
||||
if ($uri === null) {
|
||||
$uri = '/';
|
||||
} elseif ($uri[strlen($uri)-1] != '/') {
|
||||
$uri = $uri.'/';
|
||||
}
|
||||
|
||||
foreach ($this->_headers as $key => $value) {
|
||||
$headers .= "$key: $value\n";
|
||||
}
|
||||
|
||||
$str = "$this->_method $uri$this->_path HTTP/1.1\n$headers\n";
|
||||
$str .= "$this->_body";
|
||||
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
<?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\Internal\Http
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal\Http;
|
||||
|
||||
/**
|
||||
* Helper class to format the http headers
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal\Http
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
class HttpFormatter
|
||||
{
|
||||
/**
|
||||
* Convert a http headers array into an uniformed format for further process
|
||||
*
|
||||
* @param array $headers headers for format
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function formatHeaders(array $headers)
|
||||
{
|
||||
$result = array();
|
||||
foreach ($headers as $key => $value) {
|
||||
if (is_array($value) && count($value) == 1) {
|
||||
$result[strtolower($key)] = $value[0];
|
||||
} else {
|
||||
$result[strtolower($key)] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
<?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
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2017 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal;
|
||||
|
||||
/**
|
||||
* Trait implementing common logic for metadata, last-modified and etag. The
|
||||
* code is shared for multiple REST APIs.
|
||||
*
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2017 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
trait MetadataTrait
|
||||
{
|
||||
private $lastModified;
|
||||
private $etag;
|
||||
private $metadata;
|
||||
|
||||
/**
|
||||
* Any operation that modifies the share or its properties or metadata
|
||||
* updates the last modified time. Operations on files do not affect the
|
||||
* last modified time of the share.
|
||||
*
|
||||
* @return \DateTime.
|
||||
*/
|
||||
public function getLastModified()
|
||||
{
|
||||
return $this->lastModified;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets share lastModified.
|
||||
*
|
||||
* @param \DateTime $lastModified value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setLastModified(\DateTime $lastModified)
|
||||
{
|
||||
$this->lastModified = $lastModified;
|
||||
}
|
||||
|
||||
/**
|
||||
* The entity tag for the share. If the request version is 2011-08-18 or
|
||||
* newer, the ETag value will be in quotes.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getETag()
|
||||
{
|
||||
return $this->etag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets share etag.
|
||||
*
|
||||
* @param string $etag value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setETag($etag)
|
||||
{
|
||||
$this->etag = $etag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
protected function setMetadata(array $metadata)
|
||||
{
|
||||
$this->metadata = $metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance using the response headers from the API call.
|
||||
*
|
||||
* @param array $responseHeaders The array contains all the response headers
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return GetShareMetadataResult
|
||||
*/
|
||||
public static function createMetadataResult(array $responseHeaders)
|
||||
{
|
||||
$result = new static();
|
||||
$metadata = Utilities::getMetadataArray($responseHeaders);
|
||||
$date = Utilities::tryGetValueInsensitive(
|
||||
Resources::LAST_MODIFIED,
|
||||
$responseHeaders
|
||||
);
|
||||
$date = Utilities::rfc1123ToDateTime($date);
|
||||
$result->setETag(Utilities::tryGetValueInsensitive(
|
||||
Resources::ETAG,
|
||||
$responseHeaders
|
||||
));
|
||||
$result->setMetadata($metadata);
|
||||
$result->setLastModified($date);
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Vendored
+132
@@ -0,0 +1,132 @@
|
||||
<?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\Internal
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2017 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal\Middlewares;
|
||||
|
||||
use MicrosoftAzure\Storage\Common\Middlewares\MiddlewareBase;
|
||||
use MicrosoftAzure\Storage\Common\Internal\Authentication\IAuthScheme;
|
||||
use MicrosoftAzure\Storage\Common\Internal\Resources;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
|
||||
/**
|
||||
* CommonRequestMiddleware is the middleware used to add the necessary headers
|
||||
* and to sign the request with provided authentication scheme. This middleware
|
||||
* is by default applied to each of the request.
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2017 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
class CommonRequestMiddleware extends MiddlewareBase
|
||||
{
|
||||
private $authenticationScheme;
|
||||
private $headers;
|
||||
private $msVersion;
|
||||
private $userAgent;
|
||||
|
||||
/**
|
||||
* Creates CommonRequestMiddleware with the passed scheme and headers to
|
||||
* be added.
|
||||
*
|
||||
* @param IAuthScheme $authenticationScheme The authentication scheme.
|
||||
* @param string $storageAPIVersion Azure Storage Service API version,
|
||||
* like '2016-05-31'.
|
||||
* @param string $serviceSDKVersion Like '1.0.1' or '1.2.0'.
|
||||
* @param array $headers The headers to be added.
|
||||
*/
|
||||
public function __construct(
|
||||
IAuthScheme $authenticationScheme = null,
|
||||
$storageAPIVersion,
|
||||
$serviceSDKVersion,
|
||||
array $headers = array()
|
||||
) {
|
||||
$this->authenticationScheme = $authenticationScheme;
|
||||
$this->msVersion = $storageAPIVersion;
|
||||
$this->userAgent = self::getUserAgent($serviceSDKVersion);
|
||||
$this->headers = $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the provided headers, the date, then sign the request using the
|
||||
* authentication scheme, and return it.
|
||||
*
|
||||
* @param RequestInterface $request un-signed request.
|
||||
*
|
||||
* @return RequestInterface
|
||||
*/
|
||||
protected function onRequest(RequestInterface $request)
|
||||
{
|
||||
$result = $request;
|
||||
|
||||
//Adding headers.
|
||||
foreach ($this->headers as $key => $value) {
|
||||
$headers = $result->getHeaders();
|
||||
if (!array_key_exists($key, $headers)) {
|
||||
$result = $result->withHeader($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
//rewriting version and user-agent.
|
||||
$result = $result->withHeader(
|
||||
Resources::X_MS_VERSION,
|
||||
$this->msVersion
|
||||
);
|
||||
$result = $result->withHeader(
|
||||
Resources::USER_AGENT,
|
||||
$this->userAgent
|
||||
);
|
||||
|
||||
//Adding date.
|
||||
$date = gmdate(Resources::AZURE_DATE_FORMAT, time());
|
||||
$result = $result->withHeader(Resources::DATE, $date);
|
||||
|
||||
//Adding client request-ID if not specified by the user.
|
||||
if (!$result->hasHeader(Resources::X_MS_CLIENT_REQUEST_ID)) {
|
||||
$result = $result->withHeader(Resources::X_MS_CLIENT_REQUEST_ID, \uniqid());
|
||||
}
|
||||
//Sign the request if authentication scheme is not null.
|
||||
$request = $this->authenticationScheme == null ?
|
||||
$request : $this->authenticationScheme->signRequest($result);
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the user agent string used in request header.
|
||||
*
|
||||
* @param $serviceSDKVersion
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function getUserAgent($serviceSDKVersion)
|
||||
{
|
||||
// e.g. User-Agent: Azure-Storage/1.0.1-1.1.1 (PHP 5.5.32)/WINNT
|
||||
return 'Azure-Storage/' . $serviceSDKVersion . '-' .
|
||||
Resources::COMMON_SDK_VERSION .
|
||||
' (PHP ' . PHP_VERSION . ')' . '/' . php_uname("s");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,422 @@
|
||||
<?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\Internal
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal;
|
||||
|
||||
/**
|
||||
* Project resources.
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
class Resources
|
||||
{
|
||||
// @codingStandardsIgnoreStart
|
||||
|
||||
// Connection strings
|
||||
const USE_DEVELOPMENT_STORAGE_NAME = 'UseDevelopmentStorage';
|
||||
const DEVELOPMENT_STORAGE_PROXY_URI_NAME = 'DevelopmentStorageProxyUri';
|
||||
const DEFAULT_ENDPOINTS_PROTOCOL_NAME = 'DefaultEndpointsProtocol';
|
||||
const ACCOUNT_NAME_NAME = 'AccountName';
|
||||
const ACCOUNT_KEY_NAME = 'AccountKey';
|
||||
const SAS_TOKEN_NAME = 'SharedAccessSignature';
|
||||
const BLOB_ENDPOINT_NAME = 'BlobEndpoint';
|
||||
const QUEUE_ENDPOINT_NAME = 'QueueEndpoint';
|
||||
const TABLE_ENDPOINT_NAME = 'TableEndpoint';
|
||||
const FILE_ENDPOINT_NAME = 'FileEndpoint';
|
||||
const SHARED_ACCESS_SIGNATURE_NAME = 'SharedAccessSignature';
|
||||
const ENDPOINT_SUFFIX_NAME = 'EndpointSuffix';
|
||||
const DEFAULT_ENDPOINT_SUFFIX = 'core.windows.net';
|
||||
const DEV_STORE_NAME = 'devstoreaccount1';
|
||||
const DEV_STORE_KEY = 'Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==';
|
||||
const BLOB_BASE_DNS_NAME = 'blob.core.windows.net';
|
||||
const BLOB_DNS_PREFIX = 'blob.';
|
||||
const QUEUE_BASE_DNS_NAME = 'queue.core.windows.net';
|
||||
const QUEUE_DNS_PREFIX = 'queue.';
|
||||
const TABLE_BASE_DNS_NAME = 'table.core.windows.net';
|
||||
const TABLE_DNS_PREFIX = 'table.';
|
||||
const FILE_BASE_DNS_NAME = 'file.core.windows.net';
|
||||
const FILE_DNS_PREFIX = 'file.';
|
||||
const DEV_STORE_CONNECTION_STRING = 'BlobEndpoint=127.0.0.1:10000;QueueEndpoint=127.0.0.1:10001;TableEndpoint=127.0.0.1:10002;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==';
|
||||
const SUBSCRIPTION_ID_NAME = 'SubscriptionID';
|
||||
const CERTIFICATE_PATH_NAME = 'CertificatePath';
|
||||
const SECONDARY_STRING = '-secondary';
|
||||
const PRIMARY_STRING = '-primary';
|
||||
|
||||
// Messages
|
||||
const INVALID_FUNCTION_NAME = 'The class %s does not have a function named %s.';
|
||||
const INVALID_TYPE_MSG = 'The provided variable should be of type: ';
|
||||
const INVALID_META_MSG = 'Metadata cannot contain newline characters.';
|
||||
const AZURE_ERROR_MSG = "Fail:\nCode: %s\nValue: %s\ndetails (if any): %s.";
|
||||
const NOT_IMPLEMENTED_MSG = 'This method is not implemented.';
|
||||
const NULL_OR_EMPTY_MSG = "'%s' can't be NULL or empty.";
|
||||
const NULL_MSG = "'%s' can't be NULL.";
|
||||
const INVALID_URL_MSG = 'Provided URL is invalid.';
|
||||
const INVALID_HT_MSG = 'The header type provided is invalid.';
|
||||
const INVALID_VERSION_MSG = 'Server does not support any known protocol versions.';
|
||||
const INVALID_EXC_OBJ_MSG = 'Exception object type should be ServiceException.';
|
||||
const INVALID_PARAM_MSG = "The provided variable '%s' should be of type '%s'";
|
||||
const INVALID_VALUE_MSG = "The provided variable '%s' has unexpected value. Reason: '%s'";
|
||||
const INVALID_STRING_LENGTH = "The provided variable '%s' should be of %s characters long";
|
||||
const INVALID_SVC_PROP_MSG = 'The provided service properties is invalid.';
|
||||
const UNKNOWN_SRILZER_MSG = 'The provided serializer type is unknown';
|
||||
const INVALID_CREATE_SERVICE_OPTIONS_MSG = 'Must provide valid location or affinity group.';
|
||||
const INVALID_UPDATE_SERVICE_OPTIONS_MSG = 'Must provide either description or label.';
|
||||
const INVALID_CONFIG_MSG = 'Config object must be of type Configuration';
|
||||
const INVALID_CONFIG_HOSTNAME = "The provided hostname '%s' is invalid.";
|
||||
const INVALID_CONFIG_URI = "The provided URI '%s' is invalid. It has to pass the check 'filter_var(<user_uri>, FILTER_VALIDATE_URL)'.";
|
||||
const INVALID_CONFIG_VALUE = "The provided config value '%s' does not belong to the valid values subset:\n%s";
|
||||
const INVALID_ACCOUNT_KEY_FORMAT = "The provided account key '%s' is not a valid base64 string. It has to pass the check 'base64_decode(<user_account_key>, true)'.";
|
||||
const MISSING_CONNECTION_STRING_SETTINGS = "The provided connection string '%s' does not have complete configuration settings.";
|
||||
const INVALID_CONNECTION_STRING_SETTING_KEY = "The setting key '%s' is not found in the expected configuration setting keys:\n%s";
|
||||
const INVALID_CERTIFICATE_PATH = "The provided certificate path '%s' is invalid.";
|
||||
const INSTANCE_TYPE_VALIDATION_MSG = 'The type of %s is %s but is expected to be %s.';
|
||||
const INVALID_MESSAGE_OBJECT_TO_SERIALIZE = 'The given object does not have required methods, so it could not be serialized.';
|
||||
const MISSING_CONNECTION_STRING_CHAR = "Missing %s character";
|
||||
const ERROR_PARSING_STRING = "'%s' at position %d.";
|
||||
const INVALID_CONNECTION_STRING = "Argument '%s' is not a valid connection string: '%s'";
|
||||
const ERROR_CONNECTION_STRING_MISSING_KEY = 'Missing key name';
|
||||
const ERROR_CONNECTION_STRING_EMPTY_KEY = 'Empty key name';
|
||||
const ERROR_CONNECTION_STRING_MISSING_CHARACTER = "Missing %s character";
|
||||
const ERROR_EMPTY_SETTINGS = 'No keys were found in the connection string';
|
||||
const MISSING_LOCK_LOCATION_MSG = 'The lock location of the brokered message is missing.';
|
||||
const INVALID_SAS_TOKEN = 'The shared access signatures (SAS) provided is not valid \'%s\'';
|
||||
const INVALID_SLOT = "The provided deployment slot '%s' is not valid. Only 'staging' and 'production' are accepted.";
|
||||
const INVALID_DEPLOYMENT_LOCATOR_MSG = 'A slot or deployment name must be provided.';
|
||||
const INVALID_CHANGE_MODE_MSG = "The change mode must be 'Auto' or 'Manual'. Use Mode class constants for that purpose.";
|
||||
const INVALID_DEPLOYMENT_STATUS_MSG = "The change mode must be 'Running' or 'Suspended'. Use DeploymentStatus class constants for that purpose.";
|
||||
const ERROR_OAUTH_GET_ACCESS_TOKEN = 'Unable to get oauth access token for endpoint \'%s\', account name \'%s\'';
|
||||
const ERROR_OAUTH_SERVICE_MISSING = 'OAuth service missing for account name \'%s\'';
|
||||
const ERROR_METHOD_NOT_FOUND = 'Method \'%s\' not found in object class \'%s\'';
|
||||
const ERROR_INVALID_DATE_STRING = 'Parameter \'%s\' is not a date formatted string \'%s\'';
|
||||
const ERROR_FILE_COULD_NOT_BE_OPENED = 'Error: file with given path could not be opened or created.';
|
||||
const INVALID_PARAM_GENERAL = 'The provided parameter \'%s\' is invalid';
|
||||
const INVALID_NEGATIVE_PARAM = 'The provided parameter \'%s\' should be positive number.';
|
||||
const SIGNED_SERVICE_INVALID_VALIDATION_MSG = 'The signed service should only be a combination of the letters b(lob) q(ueue) t(able) or f(ile).';
|
||||
const SIGNED_RESOURCE_TYPE_INVALID_VALIDATION_MSG = 'The signed resource type should only be a combination of the letters s(ervice) c(container) or o(bject).';
|
||||
const STRING_NOT_WITH_GIVEN_COMBINATION = 'The string should only be a combination of the letters %s.';
|
||||
const SIGNED_PROTOCOL_INVALID_VALIDATION_MSG = 'The signed protocol is invalid: possible values are https or https,http.';
|
||||
const ERROR_RESOURCE_TYPE_NOT_SUPPORTED = 'The given resource type cannot be recognized or is not supported.';
|
||||
const ERROR_TOO_MANY_SIGNED_IDENTIFIERS = 'There can be at most 5 signed identifiers at the same time.';
|
||||
const INVALID_PERMISSION_PROVIDED = 'Invalid permission provided, the permission of resource type \'%s\' can only be of \'%s\'';
|
||||
const INVALID_RESOURCE_TYPE = 'Provided resource type is invalid.';
|
||||
const ERROR_KEY_NOT_EXIST = "The key '%s' does not exist in the given array.";
|
||||
const RESOURCE_RANGE_LENGTH_MUST_SET = "The start and end/length of the range must be set.";
|
||||
const INVALID_ACCEPT_CONTENT_TYPE = "The given accept content type is not valid.";
|
||||
const ERROR_CANNOT_PARSE_XML = "Cannot parse XML, reasons: %s";
|
||||
const INVALID_SCHEME = 'HTTP scheme can only be string \'http\' or \'https\'.';
|
||||
const AAD_TOKEN_MUST_START_WITH_BEARER = 'AAD token is invalid, please make sure that it has format \'Bearer ################\'';
|
||||
|
||||
// HTTP Headers
|
||||
const X_MS_HEADER_PREFIX = 'x-ms-';
|
||||
const X_MS_META_HEADER_PREFIX = 'x-ms-meta-';
|
||||
const X_MS_VERSION = 'x-ms-version';
|
||||
const X_MS_DATE = 'x-ms-date';
|
||||
const X_MS_COPY_ACTION = 'x-ms-copy-action';
|
||||
const X_MS_COPY_ID = 'x-ms-copy-id';
|
||||
const X_MS_COPY_COMPLETION_TIME = 'x-ms-copy-completion-time';
|
||||
const X_MS_COPY_STATUS = 'x-ms-copy-status';
|
||||
const X_MS_COPY_STATUS_DESCRIPTION = 'x-ms-copy-status-description';
|
||||
const X_MS_COPY_SOURCE = 'x-ms-copy-source';
|
||||
const X_MS_COPY_PROGRESS = 'x-ms-copy-progress';
|
||||
const X_MS_RANGE = 'x-ms-range';
|
||||
const X_MS_RANGE_GET_CONTENT_MD5 = 'x-ms-range-get-content-md5';
|
||||
const X_MS_DELETE_SNAPSHOTS = 'x-ms-delete-snapshots';
|
||||
const X_MS_SNAPSHOT = 'x-ms-snapshot';
|
||||
const X_MS_SOURCE_IF_MODIFIED_SINCE = 'x-ms-source-if-modified-since';
|
||||
const X_MS_SOURCE_IF_UNMODIFIED_SINCE = 'x-ms-source-if-unmodified-since';
|
||||
const X_MS_SOURCE_IF_MATCH = 'x-ms-source-if-match';
|
||||
const X_MS_SOURCE_IF_NONE_MATCH = 'x-ms-source-if-none-match';
|
||||
const X_MS_SOURCE_LEASE_ID = 'x-ms-source-lease-id';
|
||||
const X_MS_CONTINUATION_NEXTTABLENAME = 'x-ms-continuation-nexttablename';
|
||||
const X_MS_CONTINUATION_NEXTPARTITIONKEY = 'x-ms-continuation-nextpartitionkey';
|
||||
const X_MS_CONTINUATION_NEXTROWKEY = 'x-ms-continuation-nextrowkey';
|
||||
const X_MS_REQUEST_ID = 'x-ms-request-id';
|
||||
const X_MS_CLIENT_REQUEST_ID = 'x-ms-client-request-id';
|
||||
const X_MS_CONTINUATION_LOCATION_MODE = 'x-ms-continuation-location-mode';
|
||||
const X_MS_TYPE = 'x-ms-type';
|
||||
const X_MS_CONTENT_LENGTH = 'x-ms-content-length';
|
||||
const X_MS_CACHE_CONTROL = 'x-ms-cache-control';
|
||||
const X_MS_CONTENT_TYPE = 'x-ms-content-type';
|
||||
const X_MS_CONTENT_MD5 = 'x-ms-content-md5';
|
||||
const X_MS_CONTENT_ENCODING = 'x-ms-content-encoding';
|
||||
const X_MS_CONTENT_LANGUAGE = 'x-ms-content-language';
|
||||
const X_MS_CONTENT_DISPOSITION = 'x-ms-content-disposition';
|
||||
const X_MS_WRITE = 'x-ms-write';
|
||||
const ETAG = 'etag';
|
||||
const LAST_MODIFIED = 'last-modified';
|
||||
const DATE = 'date';
|
||||
const AUTHENTICATION = 'authorization';
|
||||
const WRAP_AUTHORIZATION = 'WRAP access_token="%s"';
|
||||
const CONTENT_ENCODING = 'content-encoding';
|
||||
const CONTENT_LANGUAGE = 'content-language';
|
||||
const CONTENT_LENGTH = 'content-length';
|
||||
const CONTENT_LENGTH_NO_SPACE = 'contentlength';
|
||||
const CONTENT_MD5 = 'content-md5';
|
||||
const CONTENT_TYPE_LOWER_CASE = 'content-type';
|
||||
const CONTENT_TYPE = 'Content-Type';
|
||||
const CONTENT_ID = 'content-id';
|
||||
const CONTENT_RANGE = 'content-range';
|
||||
const CACHE_CONTROL = 'cache-control';
|
||||
const CONTENT_DISPOSITION = 'content-disposition';
|
||||
const IF_MODIFIED_SINCE = 'if-modified-since';
|
||||
const IF_MATCH = 'if-match';
|
||||
const IF_NONE_MATCH = 'if-none-match';
|
||||
const IF_UNMODIFIED_SINCE = 'if-unmodified-since';
|
||||
const RANGE = 'range';
|
||||
const DATA_SERVICE_VERSION = 'dataserviceversion';
|
||||
const MAX_DATA_SERVICE_VERSION = 'maxdataserviceversion';
|
||||
const ACCEPT_HEADER = 'accept';
|
||||
const ACCEPT_CHARSET = 'accept-charset';
|
||||
const USER_AGENT = 'User-Agent';
|
||||
const PREFER = 'Prefer';
|
||||
|
||||
// HTTP Methods
|
||||
const HTTP_GET = 'GET';
|
||||
const HTTP_PUT = 'PUT';
|
||||
const HTTP_POST = 'POST';
|
||||
const HTTP_HEAD = 'HEAD';
|
||||
const HTTP_DELETE = 'DELETE';
|
||||
const HTTP_MERGE = 'MERGE';
|
||||
|
||||
// Misc
|
||||
const EMPTY_STRING = '';
|
||||
const SEPARATOR = ',';
|
||||
const AZURE_DATE_FORMAT = 'D, d M Y H:i:s T';
|
||||
const TIMESTAMP_FORMAT = 'Y-m-d H:i:s';
|
||||
const EMULATED = 'EMULATED';
|
||||
const EMULATOR_BLOB_URI = '127.0.0.1:10000';
|
||||
const EMULATOR_QUEUE_URI = '127.0.0.1:10001';
|
||||
const EMULATOR_TABLE_URI = '127.0.0.1:10002';
|
||||
const ASTERISK = '*';
|
||||
const SERVICE_MANAGEMENT_URL = 'https://management.core.windows.net';
|
||||
const HTTP_SCHEME = 'http';
|
||||
const HTTPS_SCHEME = 'https';
|
||||
const SETTING_NAME = 'SettingName';
|
||||
const SETTING_CONSTRAINT = 'SettingConstraint';
|
||||
const DEV_STORE_URI = 'http://127.0.0.1';
|
||||
const SERVICE_URI_FORMAT = "%s://%s.%s";
|
||||
const WRAP_ENDPOINT_URI_FORMAT = "https://%s-sb.accesscontrol.windows.net/WRAPv0.9";
|
||||
const MB_IN_BYTES_1 = 1048576;
|
||||
const MB_IN_BYTES_4 = 4194304;
|
||||
const MB_IN_BYTES_32 = 33554432;
|
||||
const MB_IN_BYTES_64 = 67108864;
|
||||
const MB_IN_BYTES_128 = 134217728;
|
||||
const MB_IN_BYTES_256 = 268435456;
|
||||
const MB_IN_BYTES_100 = 104857600;
|
||||
const GB_IN_BYTES = 1073741824;
|
||||
const GB_IN_BYTES_200 = 214748364800;
|
||||
const MAX_BLOB_BLOCKS = 50000;
|
||||
const MAX_BLOCK_BLOB_SIZE = 5242880000000;
|
||||
const RETURN_CONTENT = 'return-content';
|
||||
const NUMBER_OF_CONCURRENCY = 25;//Guzzle's default value
|
||||
const DEFAULT_NUMBER_OF_RETRIES = 3;
|
||||
const DEFAULT_RETRY_INTERVAL = 1000;//Milliseconds
|
||||
const BEARER = 'Bearer ';
|
||||
|
||||
// Header values
|
||||
const COMMON_SDK_VERSION = '1.5.2';
|
||||
const INT32_MAX = 2147483647;
|
||||
const INT32_MIN = -2147483648;
|
||||
|
||||
// Query parameter names
|
||||
const QP_ENTRIES = 'Entries';
|
||||
const QP_PREFIX = 'Prefix';
|
||||
const QP_PREFIX_LOWERCASE = 'prefix';
|
||||
const QP_MAX_RESULTS = 'MaxResults';
|
||||
const QP_MAX_RESULTS_LOWERCASE = 'maxresults';
|
||||
const QP_MARKER = 'Marker';
|
||||
const QP_MARKER_LOWERCASE = 'marker';
|
||||
const QP_METADATA = 'Metadata';
|
||||
const QP_NEXT_MARKER = 'NextMarker';
|
||||
const QP_COMP = 'comp';
|
||||
const QP_INCLUDE = 'include';
|
||||
const QP_TIMEOUT = 'timeout';
|
||||
const QP_REST_TYPE = 'restype';
|
||||
const QP_SNAPSHOT = 'snapshot';
|
||||
const QP_COPY_ID = 'copyid';
|
||||
const QP_NAME = 'Name';
|
||||
const QP_PROPERTIES = 'Properties';
|
||||
const QP_LAST_MODIFIED = 'Last-Modified';
|
||||
const QP_ETAG = 'Etag';
|
||||
const QP_QUOTA = 'Quota';
|
||||
const QP_CONTENT_LENGTH = 'Content-Length';
|
||||
|
||||
// Request body content types
|
||||
const URL_ENCODED_CONTENT_TYPE = 'application/x-www-form-urlencoded';
|
||||
const BINARY_FILE_TYPE = 'application/octet-stream';
|
||||
const HTTP_TYPE = 'application/http';
|
||||
const MULTIPART_MIXED_TYPE = 'multipart/mixed';
|
||||
|
||||
// Common used XML tags
|
||||
const XTAG_ATTRIBUTES = '@attributes';
|
||||
const XTAG_NAMESPACE = '@namespace';
|
||||
const XTAG_LABEL = 'Label';
|
||||
const XTAG_NAME = 'Name';
|
||||
const XTAG_DESCRIPTION = 'Description';
|
||||
const XTAG_LOCATION = 'Location';
|
||||
const XTAG_AFFINITY_GROUP = 'AffinityGroup';
|
||||
const XTAG_HOSTED_SERVICES = 'HostedServices';
|
||||
const XTAG_STORAGE_SERVICES = 'StorageServices';
|
||||
const XTAG_STORAGE_SERVICE = 'StorageService';
|
||||
const XTAG_DISPLAY_NAME = 'DisplayName';
|
||||
const XTAG_SERVICE_NAME = 'ServiceName';
|
||||
const XTAG_URL = 'Url';
|
||||
const XTAG_ID = 'ID';
|
||||
const XTAG_STATUS = 'Status';
|
||||
const XTAG_HTTP_STATUS_CODE = 'HttpStatusCode';
|
||||
const XTAG_CODE = 'Code';
|
||||
const XTAG_MESSAGE = 'Message';
|
||||
const XTAG_STORAGE_SERVICE_PROPERTIES = 'StorageServiceProperties';
|
||||
const XTAG_SERVICE_ENDPOINT = 'ServiceEndpoint';
|
||||
const XTAG_ENDPOINT = 'Endpoint';
|
||||
const XTAG_ENDPOINTS = 'Endpoints';
|
||||
const XTAG_PRIMARY = 'Primary';
|
||||
const XTAG_SECONDARY = 'Secondary';
|
||||
const XTAG_KEY_TYPE = 'KeyType';
|
||||
const XTAG_STORAGE_SERVICE_KEYS = 'StorageServiceKeys';
|
||||
const XTAG_ERROR = 'Error';
|
||||
const XTAG_HOSTED_SERVICE = 'HostedService';
|
||||
const XTAG_HOSTED_SERVICE_PROPERTIES = 'HostedServiceProperties';
|
||||
const XTAG_CREATE_HOSTED_SERVICE = 'CreateHostedService';
|
||||
const XTAG_CREATE_STORAGE_SERVICE_INPUT = 'CreateStorageServiceInput';
|
||||
const XTAG_UPDATE_STORAGE_SERVICE_INPUT = 'UpdateStorageServiceInput';
|
||||
const XTAG_CREATE_AFFINITY_GROUP = 'CreateAffinityGroup';
|
||||
const XTAG_UPDATE_AFFINITY_GROUP = 'UpdateAffinityGroup';
|
||||
const XTAG_UPDATE_HOSTED_SERVICE = 'UpdateHostedService';
|
||||
const XTAG_PACKAGE_URL = 'PackageUrl';
|
||||
const XTAG_CONFIGURATION = 'Configuration';
|
||||
const XTAG_START_DEPLOYMENT = 'StartDeployment';
|
||||
const XTAG_TREAT_WARNINGS_AS_ERROR = 'TreatWarningsAsError';
|
||||
const XTAG_CREATE_DEPLOYMENT = 'CreateDeployment';
|
||||
const XTAG_DEPLOYMENT_SLOT = 'DeploymentSlot';
|
||||
const XTAG_PRIVATE_ID = 'PrivateID';
|
||||
const XTAG_ROLE_INSTANCE_LIST = 'RoleInstanceList';
|
||||
const XTAG_UPGRADE_DOMAIN_COUNT = 'UpgradeDomainCount';
|
||||
const XTAG_ROLE_LIST = 'RoleList';
|
||||
const XTAG_SDK_VERSION = 'SdkVersion';
|
||||
const XTAG_INPUT_ENDPOINT_LIST = 'InputEndpointList';
|
||||
const XTAG_LOCKED = 'Locked';
|
||||
const XTAG_ROLLBACK_ALLOWED = 'RollbackAllowed';
|
||||
const XTAG_UPGRADE_STATUS = 'UpgradeStatus';
|
||||
const XTAG_UPGRADE_TYPE = 'UpgradeType';
|
||||
const XTAG_CURRENT_UPGRADE_DOMAIN_STATE = 'CurrentUpgradeDomainState';
|
||||
const XTAG_CURRENT_UPGRADE_DOMAIN = 'CurrentUpgradeDomain';
|
||||
const XTAG_ROLE_NAME = 'RoleName';
|
||||
const XTAG_INSTANCE_NAME = 'InstanceName';
|
||||
const XTAG_INSTANCE_STATUS = 'InstanceStatus';
|
||||
const XTAG_INSTANCE_UPGRADE_DOMAIN = 'InstanceUpgradeDomain';
|
||||
const XTAG_INSTANCE_FAULT_DOMAIN = 'InstanceFaultDomain';
|
||||
const XTAG_INSTANCE_SIZE = 'InstanceSize';
|
||||
const XTAG_INSTANCE_STATE_DETAILS = 'InstanceStateDetails';
|
||||
const XTAG_INSTANCE_ERROR_CODE = 'InstanceErrorCode';
|
||||
const XTAG_OS_VERSION = 'OsVersion';
|
||||
const XTAG_ROLE_INSTANCE = 'RoleInstance';
|
||||
const XTAG_ROLE = 'Role';
|
||||
const XTAG_INPUT_ENDPOINT = 'InputEndpoint';
|
||||
const XTAG_VIP = 'Vip';
|
||||
const XTAG_PORT = 'Port';
|
||||
const XTAG_DEPLOYMENT = 'Deployment';
|
||||
const XTAG_DEPLOYMENTS = 'Deployments';
|
||||
const XTAG_REGENERATE_KEYS = 'RegenerateKeys';
|
||||
const XTAG_SWAP = 'Swap';
|
||||
const XTAG_PRODUCTION = 'Production';
|
||||
const XTAG_SOURCE_DEPLOYMENT = 'SourceDeployment';
|
||||
const XTAG_CHANGE_CONFIGURATION = 'ChangeConfiguration';
|
||||
const XTAG_MODE = 'Mode';
|
||||
const XTAG_UPDATE_DEPLOYMENT_STATUS = 'UpdateDeploymentStatus';
|
||||
const XTAG_ROLE_TO_UPGRADE = 'RoleToUpgrade';
|
||||
const XTAG_FORCE = 'Force';
|
||||
const XTAG_UPGRADE_DEPLOYMENT = 'UpgradeDeployment';
|
||||
const XTAG_UPGRADE_DOMAIN = 'UpgradeDomain';
|
||||
const XTAG_WALK_UPGRADE_DOMAIN = 'WalkUpgradeDomain';
|
||||
const XTAG_ROLLBACK_UPDATE_OR_UPGRADE = 'RollbackUpdateOrUpgrade';
|
||||
const XTAG_CONTAINER_NAME = 'ContainerName';
|
||||
const XTAG_ACCOUNT_NAME = 'AccountName';
|
||||
const XTAG_LOGGING = 'Logging';
|
||||
const XTAG_HOUR_METRICS = 'HourMetrics';
|
||||
const XTAG_MINUTE_METRICS = 'MinuteMetrics';
|
||||
const XTAG_CORS = 'Cors';
|
||||
const XTAG_CORS_RULE = 'CorsRule';
|
||||
const XTAG_ALLOWED_ORIGINS = 'AllowedOrigins';
|
||||
const XTAG_ALLOWED_METHODS = 'AllowedMethods';
|
||||
const XTAG_ALLOWED_HEADERS = 'AllowedHeaders';
|
||||
const XTAG_EXPOSED_HEADERS = 'ExposedHeaders';
|
||||
const XTAG_MAX_AGE_IN_SECONDS = 'MaxAgeInSeconds';
|
||||
const XTAG_SIGNED_IDENTIFIERS = 'SignedIdentifiers';
|
||||
const XTAG_SIGNED_IDENTIFIER = 'SignedIdentifier';
|
||||
const XTAG_ACCESS_POLICY = 'AccessPolicy';
|
||||
const XTAG_SIGNED_START = 'Start';
|
||||
const XTAG_SIGNED_EXPIRY = 'Expiry';
|
||||
const XTAG_SIGNED_PERMISSION = 'Permission';
|
||||
const XTAG_SIGNED_ID = 'Id';
|
||||
const XTAG_DEFAULT_SERVICE_VERSION = 'DefaultServiceVersion';
|
||||
const XTAG_GEO_REPLICATION = 'GeoReplication';
|
||||
const XTAG_LAST_SYNC_TIME = 'LastSyncTime';
|
||||
const XTAG_PAGE_RANGE = 'PageRange';
|
||||
const XTAG_CLEAR_RANGE = 'ClearRange';
|
||||
const XTAG_RANGE_START = 'Start';
|
||||
const XTAG_RANGE_END = 'End';
|
||||
|
||||
// PHP URL Keys
|
||||
const PHP_URL_SCHEME = 'scheme';
|
||||
const PHP_URL_HOST = 'host';
|
||||
const PHP_URL_PORT = 'port';
|
||||
const PHP_URL_USER = 'user';
|
||||
const PHP_URL_PASS = 'pass';
|
||||
const PHP_URL_PATH = 'path';
|
||||
const PHP_URL_QUERY = 'query';
|
||||
const PHP_URL_FRAGMENT = 'fragment';
|
||||
|
||||
// Status Codes
|
||||
const STATUS_OK = 200;
|
||||
const STATUS_CREATED = 201;
|
||||
const STATUS_ACCEPTED = 202;
|
||||
const STATUS_NO_CONTENT = 204;
|
||||
const STATUS_PARTIAL_CONTENT = 206;
|
||||
const STATUS_MOVED_PERMANENTLY = 301;
|
||||
|
||||
// Resource Types
|
||||
const RESOURCE_TYPE_BLOB = 'b';
|
||||
const RESOURCE_TYPE_CONTAINER = 'c';
|
||||
const RESOURCE_TYPE_QUEUE = 'q';
|
||||
const RESOURCE_TYPE_TABLE = 't';
|
||||
const RESOURCE_TYPE_SHARE = 's';
|
||||
const RESOURCE_TYPE_FILE = 'f';
|
||||
|
||||
// Request Options String
|
||||
const ROS_LOCATION_MODE = 'location_mode';
|
||||
const ROS_SECONDARY_URI = 'secondary_uri';
|
||||
const ROS_PRIMARY_URI = 'primary_uri';
|
||||
const ROS_DECODE_CONTENT = 'decode_content';
|
||||
const ROS_STREAM = 'stream';
|
||||
const ROS_HANDLER = 'requestHandler';
|
||||
|
||||
// @codingStandardsIgnoreEnd
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
<?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
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal;
|
||||
|
||||
use MicrosoftAzure\Storage\Common\Internal\IMiddleware;
|
||||
|
||||
/**
|
||||
* Base class for all REST proxies.
|
||||
*
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
class RestProxy
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $middlewares;
|
||||
|
||||
/**
|
||||
* @var Serialization\ISerializer
|
||||
*/
|
||||
protected $dataSerializer;
|
||||
|
||||
/**
|
||||
* Initializes new RestProxy object.
|
||||
*
|
||||
* @param Serialization\ISerializer $dataSerializer The data serializer.
|
||||
*/
|
||||
public function __construct(Serialization\ISerializer $dataSerializer = null)
|
||||
{
|
||||
$this->middlewares = array();
|
||||
$this->dataSerializer = $dataSerializer;
|
||||
//For logging the request and responses.
|
||||
// $this->middlewares[] = new HistoryMiddleware('.\\messages.log');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets middlewares that will be handling the request and response.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMiddlewares()
|
||||
{
|
||||
return $this->middlewares;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a new middleware into the middlewares array. The newly added
|
||||
* middleware will be the most inner middleware when executed.
|
||||
*
|
||||
* @param callable|IMiddleware $middleware the middleware to be added.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function pushMiddleware($middleware)
|
||||
{
|
||||
$this->middlewares[] = $middleware;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds optional query parameter.
|
||||
*
|
||||
* Doesn't add the value if it satisfies empty().
|
||||
*
|
||||
* @param array &$queryParameters The query parameters.
|
||||
* @param string $key The query variable name.
|
||||
* @param string $value The query variable value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function addOptionalQueryParam(array &$queryParameters, $key, $value)
|
||||
{
|
||||
Validate::isArray($queryParameters, 'queryParameters');
|
||||
Validate::canCastAsString($key, 'key');
|
||||
Validate::canCastAsString($value, 'value');
|
||||
|
||||
if (!is_null($value) && Resources::EMPTY_STRING !== $value) {
|
||||
$queryParameters[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds optional header.
|
||||
*
|
||||
* Doesn't add the value if it satisfies empty().
|
||||
*
|
||||
* @param array &$headers The HTTP header parameters.
|
||||
* @param string $key The HTTP header name.
|
||||
* @param string $value The HTTP header value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function addOptionalHeader(array &$headers, $key, $value)
|
||||
{
|
||||
Validate::isArray($headers, 'headers');
|
||||
Validate::canCastAsString($key, 'key');
|
||||
Validate::canCastAsString($value, 'value');
|
||||
|
||||
if (!is_null($value) && Resources::EMPTY_STRING !== $value) {
|
||||
$headers[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
+70
@@ -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\Internal\Serialization
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal\Serialization;
|
||||
|
||||
/**
|
||||
* The serialization interface.
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal\Serialization
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
interface ISerializer
|
||||
{
|
||||
/**
|
||||
* Serialize an object into a XML.
|
||||
*
|
||||
* @param Object $targetObject The target object to be serialized.
|
||||
* @param string $rootName The name of the root.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function objectSerialize($targetObject, $rootName);
|
||||
|
||||
/**
|
||||
* Serializes given array. The array indices must be string to use them as
|
||||
* as element name.
|
||||
*
|
||||
* @param array $array The object to serialize represented in array.
|
||||
* @param array $properties The used properties in the serialization process.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function serialize(array $array, array $properties = null);
|
||||
|
||||
|
||||
/**
|
||||
* Unserializes given serialized string.
|
||||
*
|
||||
* @param string $serialized The serialized object in string representation.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function unserialize($serialized);
|
||||
}
|
||||
Vendored
+96
@@ -0,0 +1,96 @@
|
||||
<?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\Internal\Serialization
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal\Serialization;
|
||||
|
||||
use MicrosoftAzure\Storage\Common\Internal\Validate;
|
||||
|
||||
/**
|
||||
* Perform JSON serialization / deserialization
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal\Serialization
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
class JsonSerializer implements ISerializer
|
||||
{
|
||||
/**
|
||||
* Serialize an object with specified root element name.
|
||||
*
|
||||
* @param object $targetObject The target object.
|
||||
* @param string $rootName The name of the root element.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function objectSerialize($targetObject, $rootName)
|
||||
{
|
||||
Validate::notNull($targetObject, 'targetObject');
|
||||
Validate::canCastAsString($rootName, 'rootName');
|
||||
|
||||
$contianer = new \stdClass();
|
||||
|
||||
$contianer->$rootName = $targetObject;
|
||||
|
||||
return json_encode($contianer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes given array. The array indices must be string to use them as
|
||||
* as element name.
|
||||
*
|
||||
* @param array $array The object to serialize represented in array.
|
||||
* @param array $properties The used properties in the serialization process.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function serialize(array $array = null, array $properties = null)
|
||||
{
|
||||
Validate::isArray($array, 'array');
|
||||
|
||||
return json_encode($array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unserializes given serialized string to array.
|
||||
*
|
||||
* @param string $serialized The serialized object in string representation.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function unserialize($serialized)
|
||||
{
|
||||
Validate::canCastAsString($serialized, 'serialized');
|
||||
|
||||
$json = json_decode($serialized);
|
||||
if ($json && !is_array($json)) {
|
||||
return get_object_vars($json);
|
||||
} else {
|
||||
return $json;
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+178
@@ -0,0 +1,178 @@
|
||||
<?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\Internal\Serialization
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2017 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal\Serialization;
|
||||
|
||||
use MicrosoftAzure\Storage\Common\Internal\Validate;
|
||||
use MicrosoftAzure\Storage\Common\Internal\Resources;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
|
||||
/**
|
||||
* Provides functionality to serialize a message to a string.
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal\Serialization
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2017 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
class MessageSerializer
|
||||
{
|
||||
/**
|
||||
* Serialize a message to a string. The message object must be either a type
|
||||
* of \Exception, or have following methods implemented.
|
||||
* getHeaders()
|
||||
* getProtocolVersion()
|
||||
* (getUri() && getMethod()) || (getStatusCode() && getReasonPhrase())
|
||||
*
|
||||
* @param object $message The message to be serialized.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function objectSerialize($targetObject)
|
||||
{
|
||||
//if the object is of exception type, serialize it using the methods
|
||||
//without checking the methods.
|
||||
if ($targetObject instanceof RequestException) {
|
||||
return self::serializeRequestException($targetObject);
|
||||
} elseif ($targetObject instanceof \Exception) {
|
||||
return self::serializeException($targetObject);
|
||||
}
|
||||
|
||||
Validate::methodExists($targetObject, 'getHeaders', 'targetObject');
|
||||
Validate::methodExists($targetObject, 'getProtocolVersion', 'targetObject');
|
||||
|
||||
// Serialize according to the implemented method.
|
||||
if (method_exists($targetObject, 'getUri') &&
|
||||
method_exists($targetObject, 'getMethod')) {
|
||||
return self::serializeRequest($targetObject);
|
||||
} elseif (method_exists($targetObject, 'getStatusCode') &&
|
||||
method_exists($targetObject, 'getReasonPhrase')) {
|
||||
return self::serializeResponse($targetObject);
|
||||
} else {
|
||||
throw new \InvalidArgumentException(
|
||||
Resources::INVALID_MESSAGE_OBJECT_TO_SERIALIZE
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the request type that implemented the following methods:
|
||||
* getHeaders()
|
||||
* getProtocolVersion()
|
||||
* getUri()
|
||||
* getMethod()
|
||||
*
|
||||
* @param object $request The request to be serialized.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function serializeRequest($request)
|
||||
{
|
||||
$headers = $request->getHeaders();
|
||||
$version = $request->getProtocolVersion();
|
||||
$uri = $request->getUri();
|
||||
$method = $request->getMethod();
|
||||
|
||||
$resultString = "Request:\n";
|
||||
$resultString .= "URI: {$uri}\nHTTP Version: {$version}\nMethod: {$method}\n";
|
||||
$resultString .= self::serializeHeaders($headers);
|
||||
|
||||
return $resultString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the response type that implemented the following methods:
|
||||
* getHeaders()
|
||||
* getProtocolVersion()
|
||||
* getStatusCode()
|
||||
* getReasonPhrase()
|
||||
*
|
||||
* @param object $response The response to be serialized
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function serializeResponse($response)
|
||||
{
|
||||
$headers = $response->getHeaders();
|
||||
$version = $response->getProtocolVersion();
|
||||
$status = $response->getStatusCode();
|
||||
$reason = $response->getReasonPhrase();
|
||||
|
||||
$resultString = "Response:\n";
|
||||
$resultString .= "Status Code: {$status}\nReason: {$reason}\n";
|
||||
$resultString .= "HTTP Version: {$version}\n";
|
||||
$resultString .= self::serializeHeaders($headers);
|
||||
|
||||
return $resultString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the message headers.
|
||||
*
|
||||
* @param array $headers The headers to be serialized.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function serializeHeaders(array $headers)
|
||||
{
|
||||
$resultString = "Headers:\n";
|
||||
foreach ($headers as $key => $value) {
|
||||
$resultString .= sprintf("%s: %s\n", $key, $value[0]);
|
||||
}
|
||||
|
||||
return $resultString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the request exception.
|
||||
*
|
||||
* @param RequestException $e the request exception to be serialized.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function serializeRequestException(RequestException $e)
|
||||
{
|
||||
$resultString = sprintf("Reason:\n%s\n", $e);
|
||||
if ($e->hasResponse()) {
|
||||
$resultString .= self::serializeResponse($e->getResponse());
|
||||
}
|
||||
|
||||
return $resultString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the general exception
|
||||
*
|
||||
* @param \Exception $e general exception to be serialized.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function serializeException(\Exception $e)
|
||||
{
|
||||
return sprintf("Reason:\n%s\n", $e);
|
||||
}
|
||||
}
|
||||
Vendored
+245
@@ -0,0 +1,245 @@
|
||||
<?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\Internal\Serialization
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal\Serialization;
|
||||
|
||||
use MicrosoftAzure\Storage\Common\Internal\Utilities;
|
||||
use MicrosoftAzure\Storage\Common\Internal\Resources;
|
||||
use MicrosoftAzure\Storage\Common\Internal\Validate;
|
||||
|
||||
/**
|
||||
* Short description
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal\Serialization
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
class XmlSerializer implements ISerializer
|
||||
{
|
||||
const STANDALONE = 'standalone';
|
||||
const ROOT_NAME = 'rootName';
|
||||
const DEFAULT_TAG = 'defaultTag';
|
||||
|
||||
/**
|
||||
* Converts a SimpleXML object to an Array recursively
|
||||
* ensuring all sub-elements are arrays as well.
|
||||
*
|
||||
* @param string $sxml The SimpleXML object.
|
||||
* @param array $arr The array into which to store results.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function sxml2arr($sxml, array $arr = null)
|
||||
{
|
||||
foreach ((array) $sxml as $key => $value) {
|
||||
if (is_object($value) || (is_array($value))) {
|
||||
$arr[$key] = $this->sxml2arr($value);
|
||||
} else {
|
||||
$arr[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes an array and produces XML based on it.
|
||||
*
|
||||
* @param XMLWriter $xmlw XMLWriter object that was previously instanted
|
||||
* and is used for creating the XML.
|
||||
* @param array $data Array to be converted to XML.
|
||||
* @param string $defaultTag Default XML tag to be used if none specified.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function arr2xml(\XMLWriter $xmlw, array $data, $defaultTag = null)
|
||||
{
|
||||
foreach ($data as $key => $value) {
|
||||
if ($key === Resources::XTAG_ATTRIBUTES) {
|
||||
foreach ($value as $attributeName => $attributeValue) {
|
||||
$xmlw->writeAttribute($attributeName, $attributeValue);
|
||||
}
|
||||
} elseif (is_array($value)) {
|
||||
if (!is_int($key)) {
|
||||
if ($key != Resources::EMPTY_STRING) {
|
||||
$xmlw->startElement($key);
|
||||
} else {
|
||||
$xmlw->startElement($defaultTag);
|
||||
}
|
||||
}
|
||||
|
||||
$this->arr2xml($xmlw, $value);
|
||||
|
||||
if (!is_int($key)) {
|
||||
$xmlw->endElement();
|
||||
}
|
||||
} else {
|
||||
$xmlw->writeElement($key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the attributes of a specified object if get attributes
|
||||
* method is exposed.
|
||||
*
|
||||
* @param object $targetObject The target object.
|
||||
* @param array $methodArray The array of method of the target object.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private static function getInstanceAttributes($targetObject, array $methodArray)
|
||||
{
|
||||
foreach ($methodArray as $method) {
|
||||
if ($method->name == 'getAttributes') {
|
||||
$classProperty = $method->invoke($targetObject);
|
||||
return $classProperty;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize an object with specified root element name.
|
||||
*
|
||||
* @param object $targetObject The target object.
|
||||
* @param string $rootName The name of the root element.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function objectSerialize($targetObject, $rootName)
|
||||
{
|
||||
Validate::notNull($targetObject, 'targetObject');
|
||||
Validate::canCastAsString($rootName, 'rootName');
|
||||
$xmlWriter = new \XmlWriter();
|
||||
$xmlWriter->openMemory();
|
||||
$xmlWriter->setIndent(true);
|
||||
$reflectionClass = new \ReflectionClass($targetObject);
|
||||
$methodArray = $reflectionClass->getMethods();
|
||||
$attributes = self::getInstanceAttributes(
|
||||
$targetObject,
|
||||
$methodArray
|
||||
);
|
||||
|
||||
$xmlWriter->startElement($rootName);
|
||||
if (!is_null($attributes)) {
|
||||
foreach (array_keys($attributes) as $attributeKey) {
|
||||
$xmlWriter->writeAttribute(
|
||||
$attributeKey,
|
||||
$attributes[$attributeKey]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($methodArray as $method) {
|
||||
if ((strpos($method->name, 'get') === 0)
|
||||
&& $method->isPublic()
|
||||
&& ($method->name != 'getAttributes')
|
||||
) {
|
||||
$variableName = substr($method->name, 3);
|
||||
$variableValue = $method->invoke($targetObject);
|
||||
if (!empty($variableValue)) {
|
||||
if (gettype($variableValue) === 'object') {
|
||||
$xmlWriter->writeRaw(
|
||||
XmlSerializer::objectSerialize(
|
||||
$variableValue,
|
||||
$variableName
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$xmlWriter->writeElement($variableName, $variableValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$xmlWriter->endElement();
|
||||
return $xmlWriter->outputMemory(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes given array. The array indices must be string to use them as
|
||||
* as element name.
|
||||
*
|
||||
* @param array $array The object to serialize represented in array.
|
||||
* @param array $properties The used properties in the serialization process.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function serialize(array $array, array $properties = null)
|
||||
{
|
||||
$xmlVersion = '1.0';
|
||||
$xmlEncoding = 'UTF-8';
|
||||
$standalone = Utilities::tryGetValue($properties, self::STANDALONE);
|
||||
$defaultTag = Utilities::tryGetValue($properties, self::DEFAULT_TAG);
|
||||
$rootName = Utilities::tryGetValue($properties, self::ROOT_NAME);
|
||||
$docNamespace = Utilities::tryGetValue(
|
||||
$array,
|
||||
Resources::XTAG_NAMESPACE,
|
||||
null
|
||||
);
|
||||
|
||||
if (!is_array($array)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$xmlw = new \XmlWriter();
|
||||
$xmlw->openMemory();
|
||||
$xmlw->setIndent(true);
|
||||
$xmlw->startDocument($xmlVersion, $xmlEncoding, $standalone);
|
||||
|
||||
if (is_null($docNamespace)) {
|
||||
$xmlw->startElement($rootName);
|
||||
} else {
|
||||
foreach ($docNamespace as $uri => $prefix) {
|
||||
$xmlw->startElementNS($prefix, $rootName, $uri);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
unset($array[Resources::XTAG_NAMESPACE]);
|
||||
self::arr2xml($xmlw, $array, $defaultTag);
|
||||
|
||||
$xmlw->endElement();
|
||||
|
||||
return $xmlw->outputMemory(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unserializes given serialized string.
|
||||
*
|
||||
* @param string $serialized The serialized object in string representation.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function unserialize($serialized)
|
||||
{
|
||||
$sxml = new \SimpleXMLElement($serialized);
|
||||
|
||||
return $this->sxml2arr($sxml);
|
||||
}
|
||||
}
|
||||
+658
@@ -0,0 +1,658 @@
|
||||
<?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\Internal
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal;
|
||||
|
||||
use MicrosoftAzure\Storage\Common\Exceptions\ServiceException;
|
||||
use MicrosoftAzure\Storage\Common\Internal\RetryMiddlewareFactory;
|
||||
use MicrosoftAzure\Storage\Common\Internal\Serialization\XmlSerializer;
|
||||
use MicrosoftAzure\Storage\Common\Models\ServiceOptions;
|
||||
use MicrosoftAzure\Storage\Common\Internal\Http\HttpCallContext;
|
||||
use MicrosoftAzure\Storage\Common\Internal\Middlewares\MiddlewareBase;
|
||||
use MicrosoftAzure\Storage\Common\Middlewares\MiddlewareStack;
|
||||
use MicrosoftAzure\Storage\Common\LocationMode;
|
||||
use GuzzleHttp\Promise\EachPromise;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use GuzzleHttp\Psr7\Request;
|
||||
use GuzzleHttp\Psr7\Uri;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Psr7;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Base class for all services rest proxies.
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
class ServiceRestProxy extends RestProxy
|
||||
{
|
||||
private $accountName;
|
||||
private $psrPrimaryUri;
|
||||
private $psrSecondaryUri;
|
||||
private $options;
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* Initializes new ServiceRestProxy object.
|
||||
*
|
||||
* @param string $primaryUri The storage account
|
||||
* primary uri.
|
||||
* @param string $secondaryUri The storage account
|
||||
* secondary uri.
|
||||
* @param string $accountName The name of the account.
|
||||
* @param array $options Array of options for
|
||||
* the service
|
||||
*/
|
||||
public function __construct(
|
||||
$primaryUri,
|
||||
$secondaryUri,
|
||||
$accountName,
|
||||
array $options = []
|
||||
) {
|
||||
$primaryUri = Utilities::appendDelimiter($primaryUri, '/');
|
||||
$secondaryUri = Utilities::appendDelimiter($secondaryUri, '/');
|
||||
|
||||
$dataSerializer = new XmlSerializer();
|
||||
parent::__construct($dataSerializer);
|
||||
|
||||
$this->accountName = $accountName;
|
||||
$this->psrPrimaryUri = new Uri($primaryUri);
|
||||
$this->psrSecondaryUri = new Uri($secondaryUri);
|
||||
$this->options = array_merge(array('http' => array()), $options);
|
||||
$this->client = self::createClient($this->options['http']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Guzzle client for future usage.
|
||||
*
|
||||
* @param array $options Optional parameters for the client.
|
||||
*
|
||||
* @return Client
|
||||
*/
|
||||
private static function createClient(array $options)
|
||||
{
|
||||
$verify = true;
|
||||
//Disable SSL if proxy has been set, and set the proxy in the client.
|
||||
$proxy = getenv('HTTP_PROXY');
|
||||
// For testing with Fiddler
|
||||
// $proxy = 'localhost:8888';
|
||||
// $verify = false;
|
||||
if (!empty($proxy)) {
|
||||
$options['proxy'] = $proxy;
|
||||
}
|
||||
|
||||
if (isset($options['verify'])) {
|
||||
$verify = $options['verify'];
|
||||
}
|
||||
|
||||
return (new \GuzzleHttp\Client(
|
||||
array_merge(
|
||||
$options,
|
||||
array(
|
||||
"defaults" => array(
|
||||
"allow_redirects" => true,
|
||||
"exceptions" => true,
|
||||
"decode_content" => true,
|
||||
"config" => [
|
||||
"curl" => [
|
||||
CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1_2
|
||||
]
|
||||
]
|
||||
),
|
||||
'cookies' => true,
|
||||
'verify' => $verify,
|
||||
)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the account name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAccountName()
|
||||
{
|
||||
return $this->accountName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a middleware stack with given middleware.
|
||||
*
|
||||
* @param ServiceOptions $serviceOptions The options user passed in.
|
||||
*
|
||||
* @return MiddlewareStack
|
||||
*/
|
||||
protected function createMiddlewareStack(ServiceOptions $serviceOptions)
|
||||
{
|
||||
//If handler stack is not defined by the user, create a default
|
||||
//middleware stack.
|
||||
$stack = null;
|
||||
if (array_key_exists('stack', $this->options['http'])) {
|
||||
$stack = $this->options['http']['stack'];
|
||||
} elseif ($serviceOptions->getMiddlewareStack() != null) {
|
||||
$stack = $serviceOptions->getMiddlewareStack();
|
||||
} else {
|
||||
$stack = new MiddlewareStack();
|
||||
}
|
||||
|
||||
//Push all the middlewares specified in the $serviceOptions to the
|
||||
//handlerstack.
|
||||
if ($serviceOptions->getMiddlewares() != array()) {
|
||||
foreach ($serviceOptions->getMiddlewares() as $middleware) {
|
||||
$stack->push($middleware);
|
||||
}
|
||||
}
|
||||
|
||||
//Push all the middlewares specified in the $options to the
|
||||
//handlerstack.
|
||||
if (array_key_exists('middlewares', $this->options)) {
|
||||
foreach ($this->options['middlewares'] as $middleware) {
|
||||
$stack->push($middleware);
|
||||
}
|
||||
}
|
||||
|
||||
//Push all the middlewares specified in $this->middlewares to the
|
||||
//handlerstack.
|
||||
foreach ($this->getMiddlewares() as $middleware) {
|
||||
$stack->push($middleware);
|
||||
}
|
||||
|
||||
return $stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the requests concurrently. Number of concurrency can be modified
|
||||
* by inserting a new key/value pair with the key 'number_of_concurrency'
|
||||
* into the $requestOptions of $serviceOptions. Return only the promise.
|
||||
*
|
||||
* @param callable $generator the generator function to generate
|
||||
* request upon fulfillment
|
||||
* @param int $statusCode The expected status code for each of the
|
||||
* request generated by generator.
|
||||
* @param ServiceOptions $options The service options for the concurrent
|
||||
* requests.
|
||||
*
|
||||
* @return \GuzzleHttp\Promise\Promise|\GuzzleHttp\Promise\PromiseInterface
|
||||
*/
|
||||
protected function sendConcurrentAsync(
|
||||
callable $generator,
|
||||
$statusCode,
|
||||
ServiceOptions $options
|
||||
) {
|
||||
$client = $this->client;
|
||||
$middlewareStack = $this->createMiddlewareStack($options);
|
||||
|
||||
$sendAsync = function ($request, $options) use ($client) {
|
||||
if ($request->getMethod() == 'HEAD') {
|
||||
$options['decode_content'] = false;
|
||||
}
|
||||
return $client->sendAsync($request, $options);
|
||||
};
|
||||
|
||||
$handler = $middlewareStack->apply($sendAsync);
|
||||
|
||||
$requestOptions = $this->generateRequestOptions($options, $handler);
|
||||
|
||||
$promises = \call_user_func(
|
||||
function () use (
|
||||
$generator,
|
||||
$handler,
|
||||
$requestOptions
|
||||
) {
|
||||
while (is_callable($generator) && ($request = $generator())) {
|
||||
yield \call_user_func($handler, $request, $requestOptions);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
$eachPromise = new EachPromise($promises, [
|
||||
'concurrency' => $options->getNumberOfConcurrency(),
|
||||
'fulfilled' => function ($response, $index) use ($statusCode) {
|
||||
//the promise is fulfilled, evaluate the response
|
||||
self::throwIfError(
|
||||
$response,
|
||||
$statusCode
|
||||
);
|
||||
},
|
||||
'rejected' => function ($reason, $index) {
|
||||
//Still rejected even if the retry logic has been applied.
|
||||
//Throwing exception.
|
||||
throw $reason;
|
||||
}
|
||||
]);
|
||||
|
||||
return $eachPromise->promise();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create the request to be sent.
|
||||
*
|
||||
* @param string $method The method of the HTTP request
|
||||
* @param array $headers The header field of the request
|
||||
* @param array $queryParams The query parameter of the request
|
||||
* @param array $postParameters The HTTP POST parameters
|
||||
* @param string $path URL path
|
||||
* @param string $body Request body
|
||||
*
|
||||
* @return \GuzzleHttp\Psr7\Request
|
||||
*/
|
||||
protected function createRequest(
|
||||
$method,
|
||||
array $headers,
|
||||
array $queryParams,
|
||||
array $postParameters,
|
||||
$path,
|
||||
$locationMode,
|
||||
$body = Resources::EMPTY_STRING
|
||||
) {
|
||||
if ($locationMode == LocationMode::SECONDARY_ONLY ||
|
||||
$locationMode == LocationMode::SECONDARY_THEN_PRIMARY) {
|
||||
$uri = $this->psrSecondaryUri;
|
||||
} else {
|
||||
$uri = $this->psrPrimaryUri;
|
||||
}
|
||||
|
||||
//Append the path, not replacing it.
|
||||
if ($path != null) {
|
||||
$exPath = $uri->getPath();
|
||||
if ($exPath != '') {
|
||||
//Remove the duplicated slash in the path.
|
||||
if ($path != '' && $path[0] == '/') {
|
||||
$path = $exPath . substr($path, 1);
|
||||
} else {
|
||||
$path = $exPath . $path;
|
||||
}
|
||||
}
|
||||
$uri = $uri->withPath($path);
|
||||
}
|
||||
|
||||
// add query parameters into headers
|
||||
if ($queryParams != null) {
|
||||
$queryString = Psr7\Query::build($queryParams);
|
||||
$uri = $uri->withQuery($queryString);
|
||||
}
|
||||
|
||||
// add post parameters into bodies
|
||||
$actualBody = null;
|
||||
if (empty($body)) {
|
||||
if (empty($headers[Resources::CONTENT_TYPE])) {
|
||||
$headers[Resources::CONTENT_TYPE] = Resources::URL_ENCODED_CONTENT_TYPE;
|
||||
$actualBody = Psr7\Query::build($postParameters);
|
||||
}
|
||||
} else {
|
||||
$actualBody = $body;
|
||||
}
|
||||
|
||||
$request = new Request(
|
||||
$method,
|
||||
$uri,
|
||||
$headers,
|
||||
$actualBody
|
||||
);
|
||||
|
||||
//add content-length to header
|
||||
$bodySize = $request->getBody()->getSize();
|
||||
if ($bodySize > 0) {
|
||||
$request = $request->withHeader('content-length', $bodySize);
|
||||
}
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create promise of sending HTTP request with the specified parameters.
|
||||
*
|
||||
* @param string $method HTTP method used in the request
|
||||
* @param array $headers HTTP headers.
|
||||
* @param array $queryParams URL query parameters.
|
||||
* @param array $postParameters The HTTP POST parameters.
|
||||
* @param string $path URL path
|
||||
* @param array|int $expected Expected Status Codes.
|
||||
* @param string $body Request body
|
||||
* @param ServiceOptions $serviceOptions Service options
|
||||
*
|
||||
* @return \GuzzleHttp\Promise\PromiseInterface
|
||||
*/
|
||||
protected function sendAsync(
|
||||
$method,
|
||||
array $headers,
|
||||
array $queryParams,
|
||||
array $postParameters,
|
||||
$path,
|
||||
$expected = Resources::STATUS_OK,
|
||||
$body = Resources::EMPTY_STRING,
|
||||
ServiceOptions $serviceOptions = null
|
||||
) {
|
||||
if ($serviceOptions == null) {
|
||||
$serviceOptions = new ServiceOptions();
|
||||
}
|
||||
$this->addOptionalQueryParam(
|
||||
$queryParams,
|
||||
Resources::QP_TIMEOUT,
|
||||
$serviceOptions->getTimeout()
|
||||
);
|
||||
|
||||
$request = $this->createRequest(
|
||||
$method,
|
||||
$headers,
|
||||
$queryParams,
|
||||
$postParameters,
|
||||
$path,
|
||||
$serviceOptions->getLocationMode(),
|
||||
$body
|
||||
);
|
||||
|
||||
$client = $this->client;
|
||||
|
||||
$middlewareStack = $this->createMiddlewareStack($serviceOptions);
|
||||
|
||||
$sendAsync = function ($request, $options) use ($client) {
|
||||
return $client->sendAsync($request, $options);
|
||||
};
|
||||
|
||||
$handler = $middlewareStack->apply($sendAsync);
|
||||
|
||||
$requestOptions =
|
||||
$this->generateRequestOptions($serviceOptions, $handler);
|
||||
|
||||
if ($request->getMethod() == 'HEAD') {
|
||||
$requestOptions[Resources::ROS_DECODE_CONTENT] = false;
|
||||
}
|
||||
|
||||
$promise = \call_user_func($handler, $request, $requestOptions);
|
||||
|
||||
return $promise->then(
|
||||
function ($response) use ($expected, $requestOptions) {
|
||||
self::throwIfError(
|
||||
$response,
|
||||
$expected
|
||||
);
|
||||
|
||||
return self::addLocationHeaderToResponse(
|
||||
$response,
|
||||
$requestOptions[Resources::ROS_LOCATION_MODE]
|
||||
);
|
||||
},
|
||||
function ($reason) use ($expected) {
|
||||
return $this->onRejected($reason, $expected);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|\Exception $reason Rejection reason.
|
||||
* @param array|int $expected Expected Status Codes.
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
protected function onRejected($reason, $expected)
|
||||
{
|
||||
if (!($reason instanceof \Exception)) {
|
||||
throw new \RuntimeException($reason);
|
||||
}
|
||||
if (!($reason instanceof RequestException)) {
|
||||
throw $reason;
|
||||
}
|
||||
$response = $reason->getResponse();
|
||||
if ($response != null) {
|
||||
self::throwIfError(
|
||||
$response,
|
||||
$expected
|
||||
);
|
||||
} else {
|
||||
//if could not get response but promise rejected, throw reason.
|
||||
throw $reason;
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the request options using the given service options and stored
|
||||
* information.
|
||||
*
|
||||
* @param ServiceOptions $serviceOptions The service options used to
|
||||
* generate request options.
|
||||
* @param callable $handler The handler used to send the
|
||||
* request.
|
||||
* @return array
|
||||
*/
|
||||
protected function generateRequestOptions(
|
||||
ServiceOptions $serviceOptions,
|
||||
callable $handler
|
||||
) {
|
||||
$result = array();
|
||||
$result[Resources::ROS_LOCATION_MODE] = $serviceOptions->getLocationMode();
|
||||
$result[Resources::ROS_STREAM] = $serviceOptions->getIsStreaming();
|
||||
$result[Resources::ROS_DECODE_CONTENT] = $serviceOptions->getDecodeContent();
|
||||
$result[Resources::ROS_HANDLER] = $handler;
|
||||
$result[Resources::ROS_SECONDARY_URI] = $this->getPsrSecondaryUri();
|
||||
$result[Resources::ROS_PRIMARY_URI] = $this->getPsrPrimaryUri();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the context.
|
||||
*
|
||||
* @param HttpCallContext $context The context of the request.
|
||||
* @return \GuzzleHttp\Psr7\Response
|
||||
*/
|
||||
protected function sendContext(HttpCallContext $context)
|
||||
{
|
||||
return $this->sendContextAsync($context)->wait();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the promise to send the context.
|
||||
*
|
||||
* @param HttpCallContext $context The context of the request.
|
||||
*
|
||||
* @return \GuzzleHttp\Promise\PromiseInterface
|
||||
*/
|
||||
protected function sendContextAsync(HttpCallContext $context)
|
||||
{
|
||||
return $this->sendAsync(
|
||||
$context->getMethod(),
|
||||
$context->getHeaders(),
|
||||
$context->getQueryParameters(),
|
||||
$context->getPostParameters(),
|
||||
$context->getPath(),
|
||||
$context->getStatusCodes(),
|
||||
$context->getBody(),
|
||||
$context->getServiceOptions()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws ServiceException if the received status code is not expected.
|
||||
*
|
||||
* @param ResponseInterface $response The response received
|
||||
* @param array|int $expected The expected status codes.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws ServiceException
|
||||
*/
|
||||
public static function throwIfError(ResponseInterface $response, $expected)
|
||||
{
|
||||
$expectedStatusCodes = is_array($expected) ? $expected : array($expected);
|
||||
|
||||
if (!in_array($response->getStatusCode(), $expectedStatusCodes)) {
|
||||
throw new ServiceException($response);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds HTTP POST parameter to the specified
|
||||
*
|
||||
* @param array $postParameters An array of HTTP POST parameters.
|
||||
* @param string $key The key of a HTTP POST parameter.
|
||||
* @param string $value the value of a HTTP POST parameter.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function addPostParameter(
|
||||
array $postParameters,
|
||||
$key,
|
||||
$value
|
||||
) {
|
||||
Validate::isArray($postParameters, 'postParameters');
|
||||
$postParameters[$key] = $value;
|
||||
return $postParameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups set of values into one value separated with Resources::SEPARATOR
|
||||
*
|
||||
* @param array $values array of values to be grouped.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function groupQueryValues(array $values)
|
||||
{
|
||||
Validate::isArray($values, 'values');
|
||||
$joined = Resources::EMPTY_STRING;
|
||||
|
||||
sort($values);
|
||||
|
||||
foreach ($values as $value) {
|
||||
if (!is_null($value) && !empty($value)) {
|
||||
$joined .= $value . Resources::SEPARATOR;
|
||||
}
|
||||
}
|
||||
|
||||
return trim($joined, Resources::SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds metadata elements to headers array
|
||||
*
|
||||
* @param array $headers HTTP request headers
|
||||
* @param array $metadata user specified metadata
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function addMetadataHeaders(array $headers, array $metadata = null)
|
||||
{
|
||||
Utilities::validateMetadata($metadata);
|
||||
|
||||
$metadata = $this->generateMetadataHeaders($metadata);
|
||||
$headers = array_merge($headers, $metadata);
|
||||
|
||||
return $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates metadata headers by prefixing each element with 'x-ms-meta'.
|
||||
*
|
||||
* @param array $metadata user defined metadata.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function generateMetadataHeaders(array $metadata = null)
|
||||
{
|
||||
$metadataHeaders = array();
|
||||
|
||||
if (is_array($metadata) && !is_null($metadata)) {
|
||||
foreach ($metadata as $key => $value) {
|
||||
$headerName = Resources::X_MS_META_HEADER_PREFIX;
|
||||
if (strpos($value, "\r") !== false
|
||||
|| strpos($value, "\n") !== false
|
||||
) {
|
||||
throw new \InvalidArgumentException(Resources::INVALID_META_MSG);
|
||||
}
|
||||
|
||||
// Metadata name is case-presrved and case insensitive
|
||||
$headerName .= $key;
|
||||
$metadataHeaders[$headerName] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $metadataHeaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the primary URI in PSR form.
|
||||
*
|
||||
* @return Uri
|
||||
*/
|
||||
public function getPsrPrimaryUri()
|
||||
{
|
||||
return $this->psrPrimaryUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the secondary URI in PSR form.
|
||||
*
|
||||
* @return Uri
|
||||
*/
|
||||
public function getPsrSecondaryUri()
|
||||
{
|
||||
return $this->psrSecondaryUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the header that indicates the location mode to the response header.
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
private static function addLocationHeaderToResponse(
|
||||
ResponseInterface $response,
|
||||
$locationMode
|
||||
) {
|
||||
//If the response already has this header, return itself.
|
||||
if ($response->hasHeader(Resources::X_MS_CONTINUATION_LOCATION_MODE)) {
|
||||
return $response;
|
||||
}
|
||||
//Otherwise, add the header that indicates the endpoint to be used if
|
||||
//continuation token is used for subsequent request. Notice that if the
|
||||
//response does not have location header set at the moment, it means
|
||||
//that the user have not set a retry middleware.
|
||||
if ($locationMode == LocationMode::PRIMARY_THEN_SECONDARY) {
|
||||
$response = $response->withHeader(
|
||||
Resources::X_MS_CONTINUATION_LOCATION_MODE,
|
||||
LocationMode::PRIMARY_ONLY
|
||||
);
|
||||
} elseif ($locationMode == LocationMode::SECONDARY_THEN_PRIMARY) {
|
||||
$response = $response->withHeader(
|
||||
Resources::X_MS_CONTINUATION_LOCATION_MODE,
|
||||
LocationMode::SECONDARY_ONLY
|
||||
);
|
||||
} elseif ($locationMode == LocationMode::SECONDARY_ONLY ||
|
||||
$locationMode == LocationMode::PRIMARY_ONLY) {
|
||||
$response = $response->withHeader(
|
||||
Resources::X_MS_CONTINUATION_LOCATION_MODE,
|
||||
$locationMode
|
||||
);
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
+259
@@ -0,0 +1,259 @@
|
||||
<?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
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2017 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal;
|
||||
|
||||
use MicrosoftAzure\Storage\Common\LocationMode;
|
||||
use MicrosoftAzure\Storage\Common\Models\ServiceOptions;
|
||||
use MicrosoftAzure\Storage\Common\Models\ServiceProperties;
|
||||
use MicrosoftAzure\Storage\Common\Models\GetServicePropertiesResult;
|
||||
use MicrosoftAzure\Storage\Common\Models\GetServiceStatsResult;
|
||||
|
||||
/**
|
||||
* Trait implementing common REST API for all the services, including the
|
||||
* following:
|
||||
* Get/Set Service Properties
|
||||
* Get service stats
|
||||
*
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2017 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
trait ServiceRestTrait
|
||||
{
|
||||
/**
|
||||
* Gets the properties of the service.
|
||||
*
|
||||
* @param ServiceOptions $options The optional parameters.
|
||||
*
|
||||
* @return \MicrosoftAzure\Storage\Common\Models\GetServicePropertiesResult
|
||||
*
|
||||
* @see http://msdn.microsoft.com/en-us/library/windowsazure/hh452239.aspx
|
||||
*/
|
||||
public function getServiceProperties(
|
||||
ServiceOptions $options = null
|
||||
) {
|
||||
return $this->getServicePropertiesAsync($options)->wait();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
) {
|
||||
$method = Resources::HTTP_GET;
|
||||
$headers = array();
|
||||
$queryParams = array();
|
||||
$postParams = array();
|
||||
$path = Resources::EMPTY_STRING;
|
||||
|
||||
if (is_null($options)) {
|
||||
$options = new ServiceOptions();
|
||||
}
|
||||
|
||||
$this->addOptionalQueryParam(
|
||||
$queryParams,
|
||||
Resources::QP_REST_TYPE,
|
||||
'service'
|
||||
);
|
||||
$this->addOptionalQueryParam(
|
||||
$queryParams,
|
||||
Resources::QP_COMP,
|
||||
'properties'
|
||||
);
|
||||
|
||||
$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 GetServicePropertiesResult::create($parsed);
|
||||
}, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets 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 The service properties.
|
||||
* @param ServiceOptions $options The optional parameters.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @see http://msdn.microsoft.com/en-us/library/windowsazure/hh452235.aspx
|
||||
*/
|
||||
public function setServiceProperties(
|
||||
ServiceProperties $serviceProperties,
|
||||
ServiceOptions $options = null
|
||||
) {
|
||||
$this->setServicePropertiesAsync($serviceProperties, $options)->wait();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 The service properties.
|
||||
* @param ServiceOptions $options The 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
|
||||
) {
|
||||
Validate::isTrue(
|
||||
$serviceProperties instanceof ServiceProperties,
|
||||
Resources::INVALID_SVC_PROP_MSG
|
||||
);
|
||||
|
||||
$method = Resources::HTTP_PUT;
|
||||
$headers = array();
|
||||
$queryParams = array();
|
||||
$postParams = array();
|
||||
$path = Resources::EMPTY_STRING;
|
||||
$body = $serviceProperties->toXml($this->dataSerializer);
|
||||
|
||||
if (is_null($options)) {
|
||||
$options = new ServiceOptions();
|
||||
}
|
||||
|
||||
$this->addOptionalQueryParam(
|
||||
$queryParams,
|
||||
Resources::QP_REST_TYPE,
|
||||
'service'
|
||||
);
|
||||
$this->addOptionalQueryParam(
|
||||
$queryParams,
|
||||
Resources::QP_COMP,
|
||||
'properties'
|
||||
);
|
||||
$this->addOptionalHeader(
|
||||
$headers,
|
||||
Resources::CONTENT_TYPE,
|
||||
Resources::URL_ENCODED_CONTENT_TYPE
|
||||
);
|
||||
|
||||
$options->setLocationMode(LocationMode::PRIMARY_ONLY);
|
||||
|
||||
return $this->sendAsync(
|
||||
$method,
|
||||
$headers,
|
||||
$queryParams,
|
||||
$postParams,
|
||||
$path,
|
||||
Resources::STATUS_ACCEPTED,
|
||||
$body,
|
||||
$options
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 GetServiceStatsResult
|
||||
*/
|
||||
public function getServiceStats(ServiceOptions $options = null)
|
||||
{
|
||||
return $this->getServiceStatsAsync($options)->wait();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public function getServiceStatsAsync(ServiceOptions $options = null)
|
||||
{
|
||||
$method = Resources::HTTP_GET;
|
||||
$headers = array();
|
||||
$queryParams = array();
|
||||
$postParams = array();
|
||||
$path = Resources::EMPTY_STRING;
|
||||
|
||||
if (is_null($options)) {
|
||||
$options = new ServiceOptions();
|
||||
}
|
||||
|
||||
$this->addOptionalQueryParam(
|
||||
$queryParams,
|
||||
Resources::QP_REST_TYPE,
|
||||
'service'
|
||||
);
|
||||
$this->addOptionalQueryParam(
|
||||
$queryParams,
|
||||
Resources::QP_COMP,
|
||||
'stats'
|
||||
);
|
||||
|
||||
$dataSerializer = $this->dataSerializer;
|
||||
|
||||
$options->setLocationMode(LocationMode::SECONDARY_ONLY);
|
||||
|
||||
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 GetServiceStatsResult::create($parsed);
|
||||
}, null);
|
||||
}
|
||||
}
|
||||
+288
@@ -0,0 +1,288 @@
|
||||
<?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
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal;
|
||||
|
||||
/**
|
||||
* Base class for all REST services settings.
|
||||
*
|
||||
* Derived classes must implement the following members:
|
||||
* 1- $isInitialized: A static property that indicates whether the class's static
|
||||
* members have been initialized.
|
||||
* 2- init(): A protected static method that initializes static members.
|
||||
* 3- $validSettingKeys: A static property that contains valid setting keys for this
|
||||
* service.
|
||||
* 4- createFromConnectionString($connectionString): A public static function that
|
||||
* takes a connection string and returns the created settings object.
|
||||
*
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
abstract class ServiceSettings
|
||||
{
|
||||
/**
|
||||
* Throws an exception if the connection string format does not match any of the
|
||||
* available formats.
|
||||
*
|
||||
* @param string $connectionString The invalid formatted connection string.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
protected static function noMatch($connectionString)
|
||||
{
|
||||
throw new \RuntimeException(
|
||||
sprintf(Resources::MISSING_CONNECTION_STRING_SETTINGS, $connectionString)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the connection string and then validate that the parsed keys belong to
|
||||
* the $validSettingKeys
|
||||
*
|
||||
* @param string $connectionString The user provided connection string.
|
||||
*
|
||||
* @return array The tokenized connection string keys.
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
protected static function parseAndValidateKeys($connectionString)
|
||||
{
|
||||
// Initialize the static values if they are not initialized yet.
|
||||
if (!static::$isInitialized) {
|
||||
static::init();
|
||||
static::$isInitialized = true;
|
||||
}
|
||||
|
||||
$tokenizedSettings = ConnectionStringParser::parseConnectionString(
|
||||
'connectionString',
|
||||
$connectionString
|
||||
);
|
||||
|
||||
// Assure that all given keys are valid.
|
||||
foreach ($tokenizedSettings as $key => $value) {
|
||||
if (!Utilities::inArrayInsensitive($key, static::$validSettingKeys)) {
|
||||
throw new \RuntimeException(
|
||||
sprintf(
|
||||
Resources::INVALID_CONNECTION_STRING_SETTING_KEY,
|
||||
$key,
|
||||
implode("\n", static::$validSettingKeys)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $tokenizedSettings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an anonymous function that acts as predicate.
|
||||
*
|
||||
* @param array $requirements The array of conditions to satisfy.
|
||||
* @param boolean $isRequired Either these conditions are all required or all
|
||||
* optional.
|
||||
* @param boolean $atLeastOne Indicates that at least one requirement must
|
||||
* succeed.
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
protected static function getValidator(
|
||||
array $requirements,
|
||||
$isRequired,
|
||||
$atLeastOne
|
||||
) {
|
||||
// @codingStandardsIgnoreStart
|
||||
|
||||
return function ($userSettings) use ($requirements, $isRequired, $atLeastOne) {
|
||||
$oneFound = false;
|
||||
$result = array_change_key_case($userSettings);
|
||||
foreach ($requirements as $requirement) {
|
||||
$settingName = strtolower($requirement[Resources::SETTING_NAME]);
|
||||
|
||||
// Check if the setting name exists in the provided user settings.
|
||||
if (array_key_exists($settingName, $result)) {
|
||||
// Check if the provided user setting value is valid.
|
||||
$validationFunc = $requirement[Resources::SETTING_CONSTRAINT];
|
||||
$isValid = $validationFunc($result[$settingName]);
|
||||
|
||||
if ($isValid) {
|
||||
// Remove the setting as indicator for successful validation.
|
||||
unset($result[$settingName]);
|
||||
$oneFound = true;
|
||||
}
|
||||
} else {
|
||||
// If required then fail because the setting does not exist
|
||||
if ($isRequired) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($atLeastOne) {
|
||||
// At least one requirement must succeed, otherwise fail.
|
||||
return $oneFound ? $result : null;
|
||||
} else {
|
||||
return $result;
|
||||
}
|
||||
};
|
||||
|
||||
// @codingStandardsIgnoreEnd
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates at lease one succeed predicate for the provided list of requirements.
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
protected static function atLeastOne()
|
||||
{
|
||||
$allSettings = func_get_args();
|
||||
return self::getValidator($allSettings, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an optional predicate for the provided list of requirements.
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
protected static function optional()
|
||||
{
|
||||
$optionalSettings = func_get_args();
|
||||
return self::getValidator($optionalSettings, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an required predicate for the provided list of requirements.
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
protected static function allRequired()
|
||||
{
|
||||
$requiredSettings = func_get_args();
|
||||
return self::getValidator($requiredSettings, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a setting value condition using the passed predicate.
|
||||
*
|
||||
* @param string $name The setting key name.
|
||||
* @param callable $predicate The setting value predicate.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function settingWithFunc($name, $predicate)
|
||||
{
|
||||
$requirement = array();
|
||||
$requirement[Resources::SETTING_NAME] = $name;
|
||||
$requirement[Resources::SETTING_CONSTRAINT] = $predicate;
|
||||
|
||||
return $requirement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a setting value condition that validates it is one of the
|
||||
* passed valid values.
|
||||
*
|
||||
* @param string $name The setting key name.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function setting($name)
|
||||
{
|
||||
$validValues = func_get_args();
|
||||
|
||||
// Remove $name argument.
|
||||
unset($validValues[0]);
|
||||
|
||||
$validValuesCount = func_num_args();
|
||||
|
||||
$predicate = function ($settingValue) use ($validValuesCount, $validValues) {
|
||||
if (empty($validValues)) {
|
||||
// No restrictions, succeed,
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check to find if the $settingValue is valid or not. The index must
|
||||
// start from 1 as unset deletes the value but does not update the array
|
||||
// indecies.
|
||||
for ($index = 1; $index < $validValuesCount; $index++) {
|
||||
if ($settingValue == $validValues[$index]) {
|
||||
// $settingValue is found in valid values set, succeed.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
throw new \RuntimeException(
|
||||
sprintf(
|
||||
Resources::INVALID_CONFIG_VALUE,
|
||||
$settingValue,
|
||||
implode("\n", $validValues)
|
||||
)
|
||||
);
|
||||
|
||||
// $settingValue is missing in valid values set, fail.
|
||||
return false;
|
||||
};
|
||||
|
||||
return self::settingWithFunc($name, $predicate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests to see if a given list of settings matches a set of filters exactly.
|
||||
*
|
||||
* @param array $settings The settings to check.
|
||||
*
|
||||
* @return boolean If any filter returns null, false. If there are any settings
|
||||
* left over after all filters are processed, false. Otherwise true.
|
||||
*/
|
||||
protected static function matchedSpecification(array $settings)
|
||||
{
|
||||
$constraints = func_get_args();
|
||||
|
||||
// Remove first element which corresponds to $settings
|
||||
unset($constraints[0]);
|
||||
|
||||
foreach ($constraints as $constraint) {
|
||||
$remainingSettings = $constraint($settings);
|
||||
|
||||
if (is_null($remainingSettings)) {
|
||||
return false;
|
||||
} else {
|
||||
$settings = $remainingSettings;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($settings)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+713
@@ -0,0 +1,713 @@
|
||||
<?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\Internal
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal;
|
||||
|
||||
/**
|
||||
* Represents the settings used to sign and access a request against the storage
|
||||
* service. For more information about storage service connection strings check this
|
||||
* page: http://msdn.microsoft.com/en-us/library/ee758697
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
class StorageServiceSettings extends ServiceSettings
|
||||
{
|
||||
private $name;
|
||||
private $key;
|
||||
private $sas;
|
||||
private $blobEndpointUri;
|
||||
private $queueEndpointUri;
|
||||
private $tableEndpointUri;
|
||||
private $fileEndpointUri;
|
||||
private $blobSecondaryEndpointUri;
|
||||
private $queueSecondaryEndpointUri;
|
||||
private $tableSecondaryEndpointUri;
|
||||
private $fileSecondaryEndpointUri;
|
||||
|
||||
private static $devStoreAccount;
|
||||
private static $useDevelopmentStorageSetting;
|
||||
private static $developmentStorageProxyUriSetting;
|
||||
private static $defaultEndpointsProtocolSetting;
|
||||
private static $accountNameSetting;
|
||||
private static $accountKeySetting;
|
||||
private static $sasTokenSetting;
|
||||
private static $blobEndpointSetting;
|
||||
private static $queueEndpointSetting;
|
||||
private static $tableEndpointSetting;
|
||||
private static $fileEndpointSetting;
|
||||
private static $endpointSuffixSetting;
|
||||
|
||||
/**
|
||||
* If initialized or not
|
||||
* @internal
|
||||
*/
|
||||
protected static $isInitialized = false;
|
||||
|
||||
/**
|
||||
* Valid setting keys
|
||||
* @internal
|
||||
*/
|
||||
protected static $validSettingKeys = array();
|
||||
|
||||
/**
|
||||
* Initializes static members of the class.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function init()
|
||||
{
|
||||
self::$useDevelopmentStorageSetting = self::setting(
|
||||
Resources::USE_DEVELOPMENT_STORAGE_NAME,
|
||||
'true'
|
||||
);
|
||||
|
||||
self::$developmentStorageProxyUriSetting = self::settingWithFunc(
|
||||
Resources::DEVELOPMENT_STORAGE_PROXY_URI_NAME,
|
||||
Validate::getIsValidUri()
|
||||
);
|
||||
|
||||
self::$defaultEndpointsProtocolSetting = self::setting(
|
||||
Resources::DEFAULT_ENDPOINTS_PROTOCOL_NAME,
|
||||
'http',
|
||||
'https'
|
||||
);
|
||||
|
||||
self::$accountNameSetting = self::setting(Resources::ACCOUNT_NAME_NAME);
|
||||
|
||||
self::$accountKeySetting = self::settingWithFunc(
|
||||
Resources::ACCOUNT_KEY_NAME,
|
||||
// base64_decode will return false if the $key is not in base64 format.
|
||||
function ($key) {
|
||||
$isValidBase64String = base64_decode($key, true);
|
||||
if ($isValidBase64String) {
|
||||
return true;
|
||||
} else {
|
||||
throw new \RuntimeException(
|
||||
sprintf(Resources::INVALID_ACCOUNT_KEY_FORMAT, $key)
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
self::$sasTokenSetting = self::setting(Resources::SAS_TOKEN_NAME);
|
||||
|
||||
self::$blobEndpointSetting = self::settingWithFunc(
|
||||
Resources::BLOB_ENDPOINT_NAME,
|
||||
Validate::getIsValidUri()
|
||||
);
|
||||
|
||||
self::$queueEndpointSetting = self::settingWithFunc(
|
||||
Resources::QUEUE_ENDPOINT_NAME,
|
||||
Validate::getIsValidUri()
|
||||
);
|
||||
|
||||
self::$tableEndpointSetting = self::settingWithFunc(
|
||||
Resources::TABLE_ENDPOINT_NAME,
|
||||
Validate::getIsValidUri()
|
||||
);
|
||||
|
||||
self::$fileEndpointSetting = self::settingWithFunc(
|
||||
Resources::FILE_ENDPOINT_NAME,
|
||||
Validate::getIsValidUri()
|
||||
);
|
||||
|
||||
self::$endpointSuffixSetting = self::settingWithFunc(
|
||||
Resources::ENDPOINT_SUFFIX_NAME,
|
||||
Validate::getIsValidHostname()
|
||||
);
|
||||
|
||||
self::$validSettingKeys[] = Resources::USE_DEVELOPMENT_STORAGE_NAME;
|
||||
self::$validSettingKeys[] = Resources::DEVELOPMENT_STORAGE_PROXY_URI_NAME;
|
||||
self::$validSettingKeys[] = Resources::DEFAULT_ENDPOINTS_PROTOCOL_NAME;
|
||||
self::$validSettingKeys[] = Resources::ACCOUNT_NAME_NAME;
|
||||
self::$validSettingKeys[] = Resources::ACCOUNT_KEY_NAME;
|
||||
self::$validSettingKeys[] = Resources::SAS_TOKEN_NAME;
|
||||
self::$validSettingKeys[] = Resources::BLOB_ENDPOINT_NAME;
|
||||
self::$validSettingKeys[] = Resources::QUEUE_ENDPOINT_NAME;
|
||||
self::$validSettingKeys[] = Resources::TABLE_ENDPOINT_NAME;
|
||||
self::$validSettingKeys[] = Resources::FILE_ENDPOINT_NAME;
|
||||
self::$validSettingKeys[] = Resources::ENDPOINT_SUFFIX_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new storage service settings instance.
|
||||
*
|
||||
* @param string $name The storage service name.
|
||||
* @param string $key The storage service key.
|
||||
* @param string $blobEndpointUri The storage service blob
|
||||
* endpoint.
|
||||
* @param string $queueEndpointUri The storage service queue
|
||||
* endpoint.
|
||||
* @param string $tableEndpointUri The storage service table
|
||||
* endpoint.
|
||||
* @param string $fileEndpointUri The storage service file
|
||||
* endpoint.
|
||||
* @param string $blobSecondaryEndpointUri The storage service secondary
|
||||
* blob endpoint.
|
||||
* @param string $queueSecondaryEndpointUri The storage service secondary
|
||||
* queue endpoint.
|
||||
* @param string $tableSecondaryEndpointUri The storage service secondary
|
||||
* table endpoint.
|
||||
* @param string $fileSecondaryEndpointUri The storage service secondary
|
||||
* file endpoint.
|
||||
* @param string $sas The storage service SAS token.
|
||||
*/
|
||||
public function __construct(
|
||||
$name,
|
||||
$key,
|
||||
$blobEndpointUri,
|
||||
$queueEndpointUri,
|
||||
$tableEndpointUri,
|
||||
$fileEndpointUri,
|
||||
$blobSecondaryEndpointUri = null,
|
||||
$queueSecondaryEndpointUri = null,
|
||||
$tableSecondaryEndpointUri = null,
|
||||
$fileSecondaryEndpointUri = null,
|
||||
$sas = null
|
||||
) {
|
||||
$this->name = $name;
|
||||
$this->key = $key;
|
||||
$this->sas = $sas;
|
||||
$this->blobEndpointUri = $blobEndpointUri;
|
||||
$this->queueEndpointUri = $queueEndpointUri;
|
||||
$this->tableEndpointUri = $tableEndpointUri;
|
||||
$this->fileEndpointUri = $fileEndpointUri;
|
||||
$this->blobSecondaryEndpointUri = $blobSecondaryEndpointUri;
|
||||
$this->queueSecondaryEndpointUri = $queueSecondaryEndpointUri;
|
||||
$this->tableSecondaryEndpointUri = $tableSecondaryEndpointUri;
|
||||
$this->fileSecondaryEndpointUri = $fileSecondaryEndpointUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a StorageServiceSettings with development storage credentials using
|
||||
* the specified proxy Uri.
|
||||
*
|
||||
* @param string $proxyUri The proxy endpoint to use.
|
||||
*
|
||||
* @return StorageServiceSettings
|
||||
*/
|
||||
private static function getDevelopmentStorageAccount($proxyUri)
|
||||
{
|
||||
if (is_null($proxyUri)) {
|
||||
return self::developmentStorageAccount();
|
||||
}
|
||||
|
||||
$scheme = parse_url($proxyUri, PHP_URL_SCHEME);
|
||||
$host = parse_url($proxyUri, PHP_URL_HOST);
|
||||
$prefix = $scheme . "://" . $host;
|
||||
|
||||
return new StorageServiceSettings(
|
||||
Resources::DEV_STORE_NAME,
|
||||
Resources::DEV_STORE_KEY,
|
||||
$prefix . ':10000/devstoreaccount1/',
|
||||
$prefix . ':10001/devstoreaccount1/',
|
||||
$prefix . ':10002/devstoreaccount1/',
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a StorageServiceSettings object that references the development storage
|
||||
* account.
|
||||
*
|
||||
* @return StorageServiceSettings
|
||||
*/
|
||||
public static function developmentStorageAccount()
|
||||
{
|
||||
if (is_null(self::$devStoreAccount)) {
|
||||
self::$devStoreAccount = self::getDevelopmentStorageAccount(
|
||||
Resources::DEV_STORE_URI
|
||||
);
|
||||
}
|
||||
|
||||
return self::$devStoreAccount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default service endpoint using the specified protocol and account
|
||||
* name.
|
||||
*
|
||||
* @param string $scheme The scheme of the service end point.
|
||||
* @param string $accountName The account name of the service.
|
||||
* @param string $dnsPrefix The service DNS prefix.
|
||||
* @param string $dnsSuffix The service DNS suffix.
|
||||
* @param bool $isSecondary If generating secondary endpoint.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function getServiceEndpoint(
|
||||
$scheme,
|
||||
$accountName,
|
||||
$dnsPrefix,
|
||||
$dnsSuffix = null,
|
||||
$isSecondary = false
|
||||
) {
|
||||
if ($isSecondary) {
|
||||
$accountName .= Resources::SECONDARY_STRING;
|
||||
}
|
||||
if ($dnsSuffix === null) {
|
||||
$dnsSuffix = Resources::DEFAULT_ENDPOINT_SUFFIX;
|
||||
}
|
||||
return sprintf(
|
||||
Resources::SERVICE_URI_FORMAT,
|
||||
$scheme,
|
||||
$accountName,
|
||||
$dnsPrefix.$dnsSuffix
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates StorageServiceSettings object given endpoints uri.
|
||||
*
|
||||
* @param array $settings The service settings.
|
||||
* @param string $blobEndpointUri The blob endpoint uri.
|
||||
* @param string $queueEndpointUri The queue endpoint uri.
|
||||
* @param string $tableEndpointUri The table endpoint uri.
|
||||
* @param string $fileEndpointUri The file endpoint uri.
|
||||
* @param string $blobSecondaryEndpointUri The blob secondary endpoint uri.
|
||||
* @param string $queueSecondaryEndpointUri The queue secondary endpoint uri.
|
||||
* @param string $tableSecondaryEndpointUri The table secondary endpoint uri.
|
||||
* @param string $fileSecondaryEndpointUri The file secondary endpoint uri.
|
||||
*
|
||||
* @return StorageServiceSettings
|
||||
*/
|
||||
private static function createStorageServiceSettings(
|
||||
array $settings,
|
||||
$blobEndpointUri = null,
|
||||
$queueEndpointUri = null,
|
||||
$tableEndpointUri = null,
|
||||
$fileEndpointUri = null,
|
||||
$blobSecondaryEndpointUri = null,
|
||||
$queueSecondaryEndpointUri = null,
|
||||
$tableSecondaryEndpointUri = null,
|
||||
$fileSecondaryEndpointUri = null
|
||||
) {
|
||||
$blobEndpointUri = Utilities::tryGetValueInsensitive(
|
||||
Resources::BLOB_ENDPOINT_NAME,
|
||||
$settings,
|
||||
$blobEndpointUri
|
||||
);
|
||||
$queueEndpointUri = Utilities::tryGetValueInsensitive(
|
||||
Resources::QUEUE_ENDPOINT_NAME,
|
||||
$settings,
|
||||
$queueEndpointUri
|
||||
);
|
||||
$tableEndpointUri = Utilities::tryGetValueInsensitive(
|
||||
Resources::TABLE_ENDPOINT_NAME,
|
||||
$settings,
|
||||
$tableEndpointUri
|
||||
);
|
||||
$fileEndpointUri = Utilities::tryGetValueInsensitive(
|
||||
Resources::FILE_ENDPOINT_NAME,
|
||||
$settings,
|
||||
$fileEndpointUri
|
||||
);
|
||||
$accountName = Utilities::tryGetValueInsensitive(
|
||||
Resources::ACCOUNT_NAME_NAME,
|
||||
$settings
|
||||
);
|
||||
$accountKey = Utilities::tryGetValueInsensitive(
|
||||
Resources::ACCOUNT_KEY_NAME,
|
||||
$settings
|
||||
);
|
||||
$sasToken = Utilities::tryGetValueInsensitive(
|
||||
Resources::SAS_TOKEN_NAME,
|
||||
$settings
|
||||
);
|
||||
|
||||
return new StorageServiceSettings(
|
||||
$accountName,
|
||||
$accountKey,
|
||||
$blobEndpointUri,
|
||||
$queueEndpointUri,
|
||||
$tableEndpointUri,
|
||||
$fileEndpointUri,
|
||||
$blobSecondaryEndpointUri,
|
||||
$queueSecondaryEndpointUri,
|
||||
$tableSecondaryEndpointUri,
|
||||
$fileSecondaryEndpointUri,
|
||||
$sasToken
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a StorageServiceSettings object from the given connection string.
|
||||
*
|
||||
* @param string $connectionString The storage settings connection string.
|
||||
*
|
||||
* @return StorageServiceSettings
|
||||
*/
|
||||
public static function createFromConnectionString($connectionString)
|
||||
{
|
||||
$tokenizedSettings = self::parseAndValidateKeys($connectionString);
|
||||
|
||||
// Devstore case
|
||||
$matchedSpecs = self::matchedSpecification(
|
||||
$tokenizedSettings,
|
||||
self::allRequired(self::$useDevelopmentStorageSetting),
|
||||
self::optional(self::$developmentStorageProxyUriSetting)
|
||||
);
|
||||
if ($matchedSpecs) {
|
||||
$proxyUri = Utilities::tryGetValueInsensitive(
|
||||
Resources::DEVELOPMENT_STORAGE_PROXY_URI_NAME,
|
||||
$tokenizedSettings
|
||||
);
|
||||
|
||||
return self::getDevelopmentStorageAccount($proxyUri);
|
||||
}
|
||||
|
||||
// Automatic case
|
||||
$matchedSpecs = self::matchedSpecification(
|
||||
$tokenizedSettings,
|
||||
self::allRequired(
|
||||
self::$defaultEndpointsProtocolSetting,
|
||||
self::$accountNameSetting,
|
||||
self::$accountKeySetting
|
||||
),
|
||||
self::optional(
|
||||
self::$blobEndpointSetting,
|
||||
self::$queueEndpointSetting,
|
||||
self::$tableEndpointSetting,
|
||||
self::$fileEndpointSetting,
|
||||
self::$endpointSuffixSetting
|
||||
)
|
||||
);
|
||||
if ($matchedSpecs) {
|
||||
$scheme = Utilities::tryGetValueInsensitive(
|
||||
Resources::DEFAULT_ENDPOINTS_PROTOCOL_NAME,
|
||||
$tokenizedSettings
|
||||
);
|
||||
$accountName = Utilities::tryGetValueInsensitive(
|
||||
Resources::ACCOUNT_NAME_NAME,
|
||||
$tokenizedSettings
|
||||
);
|
||||
$endpointSuffix = Utilities::tryGetValueInsensitive(
|
||||
Resources::ENDPOINT_SUFFIX_NAME,
|
||||
$tokenizedSettings
|
||||
);
|
||||
return self::createStorageServiceSettings(
|
||||
$tokenizedSettings,
|
||||
self::getServiceEndpoint(
|
||||
$scheme,
|
||||
$accountName,
|
||||
Resources::BLOB_DNS_PREFIX,
|
||||
$endpointSuffix
|
||||
),
|
||||
self::getServiceEndpoint(
|
||||
$scheme,
|
||||
$accountName,
|
||||
Resources::QUEUE_DNS_PREFIX,
|
||||
$endpointSuffix
|
||||
),
|
||||
self::getServiceEndpoint(
|
||||
$scheme,
|
||||
$accountName,
|
||||
Resources::TABLE_DNS_PREFIX,
|
||||
$endpointSuffix
|
||||
),
|
||||
self::getServiceEndpoint(
|
||||
$scheme,
|
||||
$accountName,
|
||||
Resources::FILE_DNS_PREFIX,
|
||||
$endpointSuffix
|
||||
),
|
||||
self::getServiceEndpoint(
|
||||
$scheme,
|
||||
$accountName,
|
||||
Resources::BLOB_DNS_PREFIX,
|
||||
$endpointSuffix,
|
||||
true
|
||||
),
|
||||
self::getServiceEndpoint(
|
||||
$scheme,
|
||||
$accountName,
|
||||
Resources::QUEUE_DNS_PREFIX,
|
||||
$endpointSuffix,
|
||||
true
|
||||
),
|
||||
self::getServiceEndpoint(
|
||||
$scheme,
|
||||
$accountName,
|
||||
Resources::TABLE_DNS_PREFIX,
|
||||
$endpointSuffix,
|
||||
true
|
||||
),
|
||||
self::getServiceEndpoint(
|
||||
$scheme,
|
||||
$accountName,
|
||||
Resources::FILE_DNS_PREFIX,
|
||||
$endpointSuffix,
|
||||
true
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Explicit case for AccountName/AccountKey combination
|
||||
$matchedSpecs = self::matchedSpecification(
|
||||
$tokenizedSettings,
|
||||
self::atLeastOne(
|
||||
self::$blobEndpointSetting,
|
||||
self::$queueEndpointSetting,
|
||||
self::$tableEndpointSetting,
|
||||
self::$fileEndpointSetting
|
||||
),
|
||||
self::allRequired(
|
||||
self::$accountNameSetting,
|
||||
self::$accountKeySetting
|
||||
)
|
||||
);
|
||||
if ($matchedSpecs) {
|
||||
return self::createStorageServiceSettings($tokenizedSettings);
|
||||
}
|
||||
|
||||
// Explicit case for SAS token
|
||||
$matchedSpecs = self::matchedSpecification(
|
||||
$tokenizedSettings,
|
||||
self::atLeastOne(
|
||||
self::$blobEndpointSetting,
|
||||
self::$queueEndpointSetting,
|
||||
self::$tableEndpointSetting,
|
||||
self::$fileEndpointSetting
|
||||
),
|
||||
self::allRequired(
|
||||
self::$sasTokenSetting
|
||||
)
|
||||
);
|
||||
if ($matchedSpecs) {
|
||||
return self::createStorageServiceSettings($tokenizedSettings);
|
||||
}
|
||||
|
||||
self::noMatch($connectionString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a StorageServiceSettings object from the given connection string.
|
||||
* Note this is only for AAD connection string, it should at least contain
|
||||
* the account name.
|
||||
*
|
||||
* @param string $connectionString The storage settings connection string.
|
||||
*
|
||||
* @return StorageServiceSettings
|
||||
*/
|
||||
public static function createFromConnectionStringForTokenCredential($connectionString)
|
||||
{
|
||||
// Explicit case for AAD token, Connection string could only have account
|
||||
// name.
|
||||
$tokenizedSettings = self::parseAndValidateKeys($connectionString);
|
||||
|
||||
$scheme = Utilities::tryGetValueInsensitive(
|
||||
Resources::DEFAULT_ENDPOINTS_PROTOCOL_NAME,
|
||||
$tokenizedSettings
|
||||
);
|
||||
$accountName = Utilities::tryGetValueInsensitive(
|
||||
Resources::ACCOUNT_NAME_NAME,
|
||||
$tokenizedSettings
|
||||
);
|
||||
$endpointSuffix = Utilities::tryGetValueInsensitive(
|
||||
Resources::ENDPOINT_SUFFIX_NAME,
|
||||
$tokenizedSettings
|
||||
);
|
||||
return self::createStorageServiceSettings(
|
||||
$tokenizedSettings,
|
||||
self::getServiceEndpoint(
|
||||
$scheme,
|
||||
$accountName,
|
||||
Resources::BLOB_DNS_PREFIX,
|
||||
$endpointSuffix
|
||||
),
|
||||
self::getServiceEndpoint(
|
||||
$scheme,
|
||||
$accountName,
|
||||
Resources::QUEUE_DNS_PREFIX,
|
||||
$endpointSuffix
|
||||
),
|
||||
self::getServiceEndpoint(
|
||||
$scheme,
|
||||
$accountName,
|
||||
Resources::TABLE_DNS_PREFIX,
|
||||
$endpointSuffix
|
||||
),
|
||||
self::getServiceEndpoint(
|
||||
$scheme,
|
||||
$accountName,
|
||||
Resources::FILE_DNS_PREFIX,
|
||||
$endpointSuffix
|
||||
),
|
||||
self::getServiceEndpoint(
|
||||
$scheme,
|
||||
$accountName,
|
||||
Resources::BLOB_DNS_PREFIX,
|
||||
$endpointSuffix,
|
||||
true
|
||||
),
|
||||
self::getServiceEndpoint(
|
||||
$scheme,
|
||||
$accountName,
|
||||
Resources::QUEUE_DNS_PREFIX,
|
||||
$endpointSuffix,
|
||||
true
|
||||
),
|
||||
self::getServiceEndpoint(
|
||||
$scheme,
|
||||
$accountName,
|
||||
Resources::TABLE_DNS_PREFIX,
|
||||
$endpointSuffix,
|
||||
true
|
||||
),
|
||||
self::getServiceEndpoint(
|
||||
$scheme,
|
||||
$accountName,
|
||||
Resources::FILE_DNS_PREFIX,
|
||||
$endpointSuffix,
|
||||
true
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets storage service name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets storage service key.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getKey()
|
||||
{
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if there is a SAS token.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasSasToken()
|
||||
{
|
||||
return !empty($this->sas);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets storage service SAS token.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSasToken()
|
||||
{
|
||||
return $this->sas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets storage service blob endpoint uri.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBlobEndpointUri()
|
||||
{
|
||||
return $this->blobEndpointUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets storage service queue endpoint uri.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getQueueEndpointUri()
|
||||
{
|
||||
return $this->queueEndpointUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets storage service table endpoint uri.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTableEndpointUri()
|
||||
{
|
||||
return $this->tableEndpointUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets storage service file endpoint uri.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFileEndpointUri()
|
||||
{
|
||||
return $this->fileEndpointUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets storage service secondary blob endpoint uri.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBlobSecondaryEndpointUri()
|
||||
{
|
||||
return $this->blobSecondaryEndpointUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets storage service secondary queue endpoint uri.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getQueueSecondaryEndpointUri()
|
||||
{
|
||||
return $this->queueSecondaryEndpointUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets storage service secondary table endpoint uri.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTableSecondaryEndpointUri()
|
||||
{
|
||||
return $this->tableSecondaryEndpointUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets storage service secondary file endpoint uri.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFileSecondaryEndpointUri()
|
||||
{
|
||||
return $this->fileSecondaryEndpointUri;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,907 @@
|
||||
<?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
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal;
|
||||
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
|
||||
/**
|
||||
* Utilities for the project
|
||||
*
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
class Utilities
|
||||
{
|
||||
/**
|
||||
* Returns the specified value of the $key passed from $array and in case that
|
||||
* this $key doesn't exist, the default value is returned.
|
||||
*
|
||||
* @param array $array The array to be used.
|
||||
* @param mixed $key The array key.
|
||||
* @param mixed $default The value to return if $key is not found in $array.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function tryGetValue($array, $key, $default = null)
|
||||
{
|
||||
return (!is_null($array)) && is_array($array) && array_key_exists($key, $array)
|
||||
? $array[$key]
|
||||
: $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a url scheme if there is no scheme. Return null if input URL is null.
|
||||
*
|
||||
* @param string $url The URL.
|
||||
* @param string $scheme The scheme. By default HTTP
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function tryAddUrlScheme($url, $scheme = 'http')
|
||||
{
|
||||
if ($url == null) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
$urlScheme = parse_url($url, PHP_URL_SCHEME);
|
||||
|
||||
if (empty($urlScheme)) {
|
||||
$url = "$scheme://" . $url;
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse storage account name from an endpoint url.
|
||||
*
|
||||
* @param string $url The endpoint $url
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function tryParseAccountNameFromUrl($url)
|
||||
{
|
||||
$host = parse_url($url, PHP_URL_HOST);
|
||||
|
||||
// first token of the url host is account name
|
||||
return explode('.', $host)[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse secondary endpoint url string from a primary endpoint url.
|
||||
*
|
||||
* Return null if the primary endpoint url is invalid.
|
||||
*
|
||||
* @param string $uri The primary endpoint url string.
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public static function tryGetSecondaryEndpointFromPrimaryEndpoint($uri)
|
||||
{
|
||||
$splitTokens = explode('.', $uri);
|
||||
if (count($splitTokens) > 0 && $splitTokens[0] != '') {
|
||||
$schemaAccountToken = $splitTokens[0];
|
||||
$schemaAccountSplitTokens = explode('/', $schemaAccountToken);
|
||||
if (count($schemaAccountSplitTokens) > 0 &&
|
||||
$schemaAccountSplitTokens[0] != '') {
|
||||
$accountName = $schemaAccountSplitTokens[
|
||||
count($schemaAccountSplitTokens) - 1
|
||||
];
|
||||
$schemaAccountSplitTokens[count($schemaAccountSplitTokens) - 1] =
|
||||
$accountName . Resources::SECONDARY_STRING;
|
||||
|
||||
$splitTokens[0] = implode('/', $schemaAccountSplitTokens);
|
||||
$secondaryUri = implode('.', $splitTokens);
|
||||
return $secondaryUri;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* tries to get nested array with index name $key from $array.
|
||||
*
|
||||
* Returns empty array object if the value is NULL.
|
||||
*
|
||||
* @param string $key The index name.
|
||||
* @param array $array The array object.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function tryGetArray($key, array $array)
|
||||
{
|
||||
return Utilities::getArray(Utilities::tryGetValue($array, $key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given key/value pair into array if the value doesn't satisfy empty().
|
||||
*
|
||||
* This function just validates that the given $array is actually array. If it's
|
||||
* NULL the function treats it as array.
|
||||
*
|
||||
* @param string $key The key.
|
||||
* @param string $value The value.
|
||||
* @param array &$array The array. If NULL will be used as array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function addIfNotEmpty($key, $value, array &$array)
|
||||
{
|
||||
if (!is_null($array)) {
|
||||
Validate::isArray($array, 'array');
|
||||
}
|
||||
|
||||
if (!empty($value)) {
|
||||
$array[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specified value of the key chain passed from $array and in case
|
||||
* that key chain doesn't exist, null is returned.
|
||||
*
|
||||
* @param array $array Array to be used.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function tryGetKeysChainValue(array $array)
|
||||
{
|
||||
$arguments = func_get_args();
|
||||
$numArguments = func_num_args();
|
||||
|
||||
$currentArray = $array;
|
||||
for ($i = 1; $i < $numArguments; $i++) {
|
||||
if (is_array($currentArray)) {
|
||||
if (array_key_exists($arguments[$i], $currentArray)) {
|
||||
$currentArray = $currentArray[$arguments[$i]];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $currentArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the passed $string starts with $prefix
|
||||
*
|
||||
* @param string $string word to seaech in
|
||||
* @param string $prefix prefix to be matched
|
||||
* @param boolean $ignoreCase true to ignore case during the comparison;
|
||||
* otherwise, false
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function startsWith($string, $prefix, $ignoreCase = false)
|
||||
{
|
||||
if ($ignoreCase) {
|
||||
$string = strtolower($string);
|
||||
$prefix = strtolower($prefix);
|
||||
}
|
||||
return ($prefix == substr($string, 0, strlen($prefix)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns grouped items from passed $var
|
||||
*
|
||||
* @param array $var item to group
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getArray(array $var)
|
||||
{
|
||||
if (is_null($var) || empty($var)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
foreach ($var as $value) {
|
||||
if ((gettype($value) == 'object')
|
||||
&& (get_class($value) == 'SimpleXMLElement')
|
||||
) {
|
||||
return (array) $var;
|
||||
} elseif (!is_array($value)) {
|
||||
return array($var);
|
||||
}
|
||||
}
|
||||
|
||||
return $var;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unserializes the passed $xml into array.
|
||||
*
|
||||
* @param string $xml XML to be parsed.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function unserialize($xml)
|
||||
{
|
||||
$sxml = new \SimpleXMLElement($xml);
|
||||
|
||||
return self::_sxml2arr($sxml);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a SimpleXML object to an Array recursively
|
||||
* ensuring all sub-elements are arrays as well.
|
||||
*
|
||||
* @param string $sxml SimpleXML object
|
||||
* @param array $arr Array into which to store results
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function _sxml2arr($sxml, array $arr = null)
|
||||
{
|
||||
foreach ((array) $sxml as $key => $value) {
|
||||
if (is_object($value) || (is_array($value))) {
|
||||
$arr[$key] = self::_sxml2arr($value);
|
||||
} else {
|
||||
$arr[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes given array into xml. The array indices must be string to use
|
||||
* them as XML tags.
|
||||
*
|
||||
* @param array $array object to serialize represented in array.
|
||||
* @param string $rootName name of the XML root element.
|
||||
* @param string $defaultTag default tag for non-tagged elements.
|
||||
* @param string $standalone adds 'standalone' header tag, values 'yes'/'no'
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function serialize(
|
||||
array $array,
|
||||
$rootName,
|
||||
$defaultTag = null,
|
||||
$standalone = null
|
||||
) {
|
||||
$xmlVersion = '1.0';
|
||||
$xmlEncoding = 'UTF-8';
|
||||
|
||||
if (!is_array($array)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$xmlw = new \XmlWriter();
|
||||
$xmlw->openMemory();
|
||||
$xmlw->startDocument($xmlVersion, $xmlEncoding, $standalone);
|
||||
|
||||
$xmlw->startElement($rootName);
|
||||
|
||||
self::_arr2xml($xmlw, $array, $defaultTag);
|
||||
|
||||
$xmlw->endElement();
|
||||
|
||||
return $xmlw->outputMemory(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes an array and produces XML based on it.
|
||||
*
|
||||
* @param XMLWriter $xmlw XMLWriter object that was previously instanted
|
||||
* and is used for creating the XML.
|
||||
* @param array $data Array to be converted to XML
|
||||
* @param string $defaultTag Default XML tag to be used if none specified.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private static function _arr2xml(
|
||||
\XMLWriter $xmlw,
|
||||
array $data,
|
||||
$defaultTag = null
|
||||
) {
|
||||
foreach ($data as $key => $value) {
|
||||
if (strcmp($key, '@attributes') == 0) {
|
||||
foreach ($value as $attributeName => $attributeValue) {
|
||||
$xmlw->writeAttribute($attributeName, $attributeValue);
|
||||
}
|
||||
} elseif (is_array($value)) {
|
||||
if (!is_int($key)) {
|
||||
if ($key != Resources::EMPTY_STRING) {
|
||||
$xmlw->startElement($key);
|
||||
} else {
|
||||
$xmlw->startElement($defaultTag);
|
||||
}
|
||||
}
|
||||
|
||||
self::_arr2xml($xmlw, $value);
|
||||
|
||||
if (!is_int($key)) {
|
||||
$xmlw->endElement();
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
$xmlw->writeElement($key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts string into boolean value.
|
||||
*
|
||||
* @param string $obj boolean value in string format.
|
||||
* @param bool $skipNull If $skipNull is set, will return NULL directly
|
||||
* when $obj is NULL.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function toBoolean($obj, $skipNull = false)
|
||||
{
|
||||
if ($skipNull && is_null($obj)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return filter_var($obj, FILTER_VALIDATE_BOOLEAN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts string into boolean value.
|
||||
*
|
||||
* @param bool $obj boolean value to convert.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function booleanToString($obj)
|
||||
{
|
||||
return $obj ? 'true' : 'false';
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a given date string into \DateTime object
|
||||
*
|
||||
* @param string $date windows azure date ins string representation.
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public static function rfc1123ToDateTime($date)
|
||||
{
|
||||
$timeZone = new \DateTimeZone('GMT');
|
||||
$format = Resources::AZURE_DATE_FORMAT;
|
||||
|
||||
return \DateTime::createFromFormat($format, $date, $timeZone);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate ISO 8601 compliant date string in UTC time zone
|
||||
*
|
||||
* @param \DateTimeInterface $date The date value to convert
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function isoDate(\DateTimeInterface $date)
|
||||
{
|
||||
$date = clone $date;
|
||||
$date = $date->setTimezone(new \DateTimeZone('UTC'));
|
||||
|
||||
return str_replace('+00:00', 'Z', $date->format('c'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a DateTime object into an Edm.DaeTime value in UTC timezone,
|
||||
* represented as a string.
|
||||
*
|
||||
* @param mixed $value The datetime value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function convertToEdmDateTime($value)
|
||||
{
|
||||
if (empty($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (is_string($value)) {
|
||||
$value = self::convertToDateTime($value);
|
||||
}
|
||||
|
||||
Validate::isDate($value);
|
||||
|
||||
$cloned = clone $value;
|
||||
$cloned->setTimezone(new \DateTimeZone('UTC'));
|
||||
return str_replace('+00:00', 'Z', $cloned->format("Y-m-d\TH:i:s.u0P"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a string to a \DateTime object. Returns false on failure.
|
||||
*
|
||||
* @param string $value The string value to parse.
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public static function convertToDateTime($value)
|
||||
{
|
||||
if ($value instanceof \DateTime) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (substr($value, -1) == 'Z') {
|
||||
$value = substr($value, 0, strlen($value) - 1);
|
||||
}
|
||||
|
||||
return new \DateTime($value, new \DateTimeZone('UTC'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts string to stream handle.
|
||||
*
|
||||
* @param string $string The string contents.
|
||||
*
|
||||
* @return resource
|
||||
*/
|
||||
public static function stringToStream($string)
|
||||
{
|
||||
return fopen('data://text/plain,' . urlencode($string), 'rb');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts an array based on given keys order.
|
||||
*
|
||||
* @param array $array The array to sort.
|
||||
* @param array $order The keys order array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function orderArray(array $array, array $order)
|
||||
{
|
||||
$ordered = array();
|
||||
|
||||
foreach ($order as $key) {
|
||||
if (array_key_exists($key, $array)) {
|
||||
$ordered[$key] = $array[$key];
|
||||
}
|
||||
}
|
||||
|
||||
return $ordered;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a value exists in an array. The comparison is done in a case
|
||||
* insensitive manner.
|
||||
*
|
||||
* @param string $needle The searched value.
|
||||
* @param array $haystack The array.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function inArrayInsensitive($needle, array $haystack)
|
||||
{
|
||||
return in_array(strtolower($needle), array_map('strtolower', $haystack));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given key exists in the array. The comparison is done in a case
|
||||
* insensitive manner.
|
||||
*
|
||||
* @param string $key The value to check.
|
||||
* @param array $search The array with keys to check.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function arrayKeyExistsInsensitive($key, array $search)
|
||||
{
|
||||
return array_key_exists(strtolower($key), array_change_key_case($search));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specified value of the $key passed from $array and in case that
|
||||
* this $key doesn't exist, the default value is returned. The key matching is
|
||||
* done in a case insensitive manner.
|
||||
*
|
||||
* @param string $key The array key.
|
||||
* @param array $haystack The array to be used.
|
||||
* @param mixed $default The value to return if $key is not found in $array.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function tryGetValueInsensitive($key, $haystack, $default = null)
|
||||
{
|
||||
$array = array_change_key_case($haystack);
|
||||
return Utilities::tryGetValue($array, strtolower($key), $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of a version 4 GUID, which uses random
|
||||
* numbers.There are 6 reserved bits, and the GUIDs have this format:
|
||||
* xxxxxxxx-xxxx-4xxx-[8|9|a|b]xxx-xxxxxxxxxxxx
|
||||
* where 'x' is a hexadecimal digit, 0-9a-f.
|
||||
*
|
||||
* See http://tools.ietf.org/html/rfc4122 for more information.
|
||||
*
|
||||
* Note: This function is available on all platforms, while the
|
||||
* com_create_guid() is only available for Windows.
|
||||
*
|
||||
* @return string A new GUID.
|
||||
*/
|
||||
public static function getGuid()
|
||||
{
|
||||
// @codingStandardsIgnoreStart
|
||||
|
||||
return sprintf(
|
||||
'%04x%04x-%04x-%04x-%02x%02x-%04x%04x%04x',
|
||||
mt_rand(0, 65535),
|
||||
mt_rand(0, 65535), // 32 bits for "time_low"
|
||||
mt_rand(0, 65535), // 16 bits for "time_mid"
|
||||
mt_rand(0, 4096) + 16384, // 16 bits for "time_hi_and_version", with
|
||||
// the most significant 4 bits being 0100
|
||||
// to indicate randomly generated version
|
||||
mt_rand(0, 64) + 128, // 8 bits for "clock_seq_hi", with
|
||||
// the most significant 2 bits being 10,
|
||||
// required by version 4 GUIDs.
|
||||
mt_rand(0, 255), // 8 bits for "clock_seq_low"
|
||||
mt_rand(0, 65535), // 16 bits for "node 0" and "node 1"
|
||||
mt_rand(0, 65535), // 16 bits for "node 2" and "node 3"
|
||||
mt_rand(0, 65535) // 16 bits for "node 4" and "node 5"
|
||||
);
|
||||
|
||||
// @codingStandardsIgnoreEnd
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a list of objects of type $class from the provided array using static
|
||||
* create method.
|
||||
*
|
||||
* @param array $parsed The object in array representation
|
||||
* @param string $class The class name. Must have static method create.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function createInstanceList(array $parsed, $class)
|
||||
{
|
||||
$list = array();
|
||||
|
||||
foreach ($parsed as $value) {
|
||||
$list[] = $class::create($value);
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a string and return if it ends with the specified character/string.
|
||||
*
|
||||
* @param string $haystack The string to search in.
|
||||
* @param string $needle postfix to match.
|
||||
* @param boolean $ignoreCase Set true to ignore case during the comparison;
|
||||
* otherwise, false
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function endsWith($haystack, $needle, $ignoreCase = false)
|
||||
{
|
||||
if ($ignoreCase) {
|
||||
$haystack = strtolower($haystack);
|
||||
$needle = strtolower($needle);
|
||||
}
|
||||
$length = strlen($needle);
|
||||
if ($length == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (substr($haystack, -$length) === $needle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id from entity object or string.
|
||||
* If entity is object than validate type and return $entity->$method()
|
||||
* If entity is string than return this string
|
||||
*
|
||||
* @param object|string $entity Entity with id property
|
||||
* @param string $type Entity type to validate
|
||||
* @param string $method Methods that gets id (getId by default)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getEntityId($entity, $type, $method = 'getId')
|
||||
{
|
||||
if (is_string($entity)) {
|
||||
return $entity;
|
||||
} else {
|
||||
Validate::isA($entity, $type, 'entity');
|
||||
Validate::methodExists($entity, $method, $type);
|
||||
|
||||
return $entity->$method();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a pseudo-random string of bytes using a cryptographically strong
|
||||
* algorithm.
|
||||
*
|
||||
* @param int $length Length of the string in bytes
|
||||
*
|
||||
* @return string|boolean Generated string of bytes on success, or FALSE on
|
||||
* failure.
|
||||
*/
|
||||
public static function generateCryptoKey($length)
|
||||
{
|
||||
return openssl_random_pseudo_bytes($length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert base 256 number to decimal number.
|
||||
*
|
||||
* @param string $number Base 256 number
|
||||
*
|
||||
* @return string Decimal number
|
||||
*/
|
||||
public static function base256ToDec($number)
|
||||
{
|
||||
Validate::canCastAsString($number, 'number');
|
||||
|
||||
$result = 0;
|
||||
$base = 1;
|
||||
for ($i = strlen($number) - 1; $i >= 0; $i--) {
|
||||
$result = bcadd($result, bcmul(ord($number[$i]), $base));
|
||||
$base = bcmul($base, 256);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* To evaluate if the stream is larger than a certain size. To restore
|
||||
* the stream, it has to be seekable, so will return true if the stream
|
||||
* is not seekable.
|
||||
* @param StreamInterface $stream The stream to be evaluated.
|
||||
* @param int $size The size if the string is larger than.
|
||||
*
|
||||
* @return boolean true if the stream is larger than the given size.
|
||||
*/
|
||||
public static function isStreamLargerThanSizeOrNotSeekable(StreamInterface $stream, $size)
|
||||
{
|
||||
Validate::isInteger($size, 'size');
|
||||
Validate::isTrue(
|
||||
$stream instanceof StreamInterface,
|
||||
sprintf(Resources::INVALID_PARAM_MSG, 'stream', 'Psr\Http\Message\StreamInterface')
|
||||
);
|
||||
$result = true;
|
||||
if ($stream->isSeekable()) {
|
||||
$position = $stream->tell();
|
||||
try {
|
||||
$stream->seek($size);
|
||||
} catch (\RuntimeException $e) {
|
||||
$pos = strpos(
|
||||
$e->getMessage(),
|
||||
'to seek to stream position '
|
||||
);
|
||||
if ($pos == null) {
|
||||
throw $e;
|
||||
}
|
||||
$result = false;
|
||||
}
|
||||
if ($stream->eof()) {
|
||||
$result = false;
|
||||
} elseif ($stream->read(1) == '') {
|
||||
$result = false;
|
||||
}
|
||||
$stream->seek($position);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets metadata array by parsing them from given headers.
|
||||
*
|
||||
* @param array $headers HTTP headers containing metadata elements.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getMetadataArray(array $headers)
|
||||
{
|
||||
$metadata = array();
|
||||
foreach ($headers as $key => $value) {
|
||||
$isMetadataHeader = Utilities::startsWith(
|
||||
strtolower($key),
|
||||
Resources::X_MS_META_HEADER_PREFIX
|
||||
);
|
||||
|
||||
if ($isMetadataHeader) {
|
||||
// Metadata name is case-presrved and case insensitive
|
||||
$MetadataName = str_ireplace(
|
||||
Resources::X_MS_META_HEADER_PREFIX,
|
||||
Resources::EMPTY_STRING,
|
||||
$key
|
||||
);
|
||||
$metadata[$MetadataName] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the provided metadata array.
|
||||
*
|
||||
* @param array $metadata The metadata array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function validateMetadata(array $metadata = null)
|
||||
{
|
||||
if (!is_null($metadata)) {
|
||||
Validate::isArray($metadata, 'metadata');
|
||||
} else {
|
||||
$metadata = array();
|
||||
}
|
||||
|
||||
foreach ($metadata as $key => $value) {
|
||||
Validate::canCastAsString($key, 'metadata key');
|
||||
Validate::canCastAsString($value, 'metadata value');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append the content to file.
|
||||
* @param string $path The file to append to.
|
||||
* @param string $content The content to append.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function appendToFile($path, $content)
|
||||
{
|
||||
$resource = @fopen($path, 'a+');
|
||||
if ($resource != null) {
|
||||
fwrite($resource, $content);
|
||||
fclose($resource);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if all the bytes are zero.
|
||||
*
|
||||
* @param string $content The content.
|
||||
* @return bool
|
||||
*/
|
||||
public static function allZero($content)
|
||||
{
|
||||
$size = strlen($content);
|
||||
|
||||
// If all Zero, skip this range
|
||||
for ($i = 0; $i < $size; $i++) {
|
||||
if (ord($content[$i]) != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append the delimiter to the string. The delimiter will not be added if
|
||||
* the string already ends with this delimiter.
|
||||
*
|
||||
* @param string $string The string to add delimiter to.
|
||||
* @param string $delimiter The delimiter to be added.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function appendDelimiter($string, $delimiter)
|
||||
{
|
||||
if (!self::endsWith($string, $delimiter)) {
|
||||
$string .= $delimiter;
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Static function used to determine if the request is performed against
|
||||
* secondary endpoint.
|
||||
*
|
||||
* @param Psr\Http\Message\RequestInterface $request The request performed.
|
||||
* @param array $options The options of the
|
||||
* request. Must contain
|
||||
* Resources::ROS_SECONDARY_URI
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function requestSentToSecondary(
|
||||
\Psr\Http\Message\RequestInterface $request,
|
||||
array $options
|
||||
) {
|
||||
$uri = $request->getUri();
|
||||
$secondaryUri = $options[Resources::ROS_SECONDARY_URI];
|
||||
$isSecondary = false;
|
||||
if (strpos((string)$uri, (string)$secondaryUri) !== false) {
|
||||
$isSecondary = true;
|
||||
}
|
||||
return $isSecondary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the location value from the headers.
|
||||
*
|
||||
* @param array $headers request/response headers.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getLocationFromHeaders(array $headers)
|
||||
{
|
||||
$value = Utilities::tryGetValue(
|
||||
$headers,
|
||||
Resources::X_MS_CONTINUATION_LOCATION_MODE
|
||||
);
|
||||
|
||||
$result = '';
|
||||
if (\is_string($value)) {
|
||||
$result = $value;
|
||||
} elseif (!empty($value)) {
|
||||
$result = $value[0];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if the value is a double value or string representation of a double
|
||||
* value
|
||||
*
|
||||
* @param mixed $value The value to be verified.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isDouble($value)
|
||||
{
|
||||
return is_numeric($value) && is_double($value + 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the content MD5 which is base64 encoded. This should be align
|
||||
* with the server calculated MD5.
|
||||
*
|
||||
* @param string $content the content to be calculated.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function calculateContentMD5($content)
|
||||
{
|
||||
Validate::notNull($content, 'content');
|
||||
Validate::canCastAsString($content, 'content');
|
||||
|
||||
return base64_encode(md5($content, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if the environment is in 64 bit PHP.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is64BitPHP()
|
||||
{
|
||||
return PHP_INT_SIZE == 8;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,461 @@
|
||||
<?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
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal;
|
||||
|
||||
use MicrosoftAzure\Storage\Common\Exceptions\InvalidArgumentTypeException;
|
||||
|
||||
/**
|
||||
* Validates against a condition and throws an exception in case of failure.
|
||||
*
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
class Validate
|
||||
{
|
||||
/**
|
||||
* Throws exception if the provided variable type is not array.
|
||||
*
|
||||
* @param mixed $var The variable to check.
|
||||
* @param string $name The parameter name.
|
||||
*
|
||||
* @throws InvalidArgumentTypeException.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function isArray($var, $name)
|
||||
{
|
||||
if (!is_array($var)) {
|
||||
throw new InvalidArgumentTypeException(gettype(array()), $name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws exception if the provided variable can not convert to a string.
|
||||
*
|
||||
* @param mixed $var The variable to check.
|
||||
* @param string $name The parameter name.
|
||||
*
|
||||
* @throws InvalidArgumentTypeException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function canCastAsString($var, $name)
|
||||
{
|
||||
try {
|
||||
(string)$var;
|
||||
} catch (\Exception $e) {
|
||||
throw new InvalidArgumentTypeException(gettype(''), $name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws exception if the provided variable type is not boolean.
|
||||
*
|
||||
* @param mixed $var variable to check against.
|
||||
*
|
||||
* @throws InvalidArgumentTypeException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function isBoolean($var)
|
||||
{
|
||||
(bool)$var;
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws exception if the provided variable is set to null.
|
||||
*
|
||||
* @param mixed $var The variable to check.
|
||||
* @param string $name The parameter name.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function notNullOrEmpty($var, $name)
|
||||
{
|
||||
if (is_null($var) || (empty($var) && $var != '0')) {
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf(Resources::NULL_OR_EMPTY_MSG, $name)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws exception if the provided variable is not double.
|
||||
*
|
||||
* @param mixed $var The variable to check.
|
||||
* @param string $name The parameter name.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function isDouble($var, $name)
|
||||
{
|
||||
if (!is_numeric($var)) {
|
||||
throw new InvalidArgumentTypeException('double', $name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws exception if the provided variable type is not integer.
|
||||
*
|
||||
* @param mixed $var The variable to check.
|
||||
* @param string $name The parameter name.
|
||||
*
|
||||
* @throws InvalidArgumentTypeException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function isInteger($var, $name)
|
||||
{
|
||||
try {
|
||||
(int)$var;
|
||||
} catch (\Exception $e) {
|
||||
throw new InvalidArgumentTypeException(gettype(123), $name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the variable is an empty or null string.
|
||||
*
|
||||
* @param string $var value.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isNullOrEmptyString($var)
|
||||
{
|
||||
try {
|
||||
(string)$var;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (!isset($var) || trim($var)==='');
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws exception if the provided condition is not satisfied.
|
||||
*
|
||||
* @param bool $isSatisfied condition result.
|
||||
* @param string $failureMessage the exception message
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function isTrue($isSatisfied, $failureMessage)
|
||||
{
|
||||
if (!$isSatisfied) {
|
||||
throw new \InvalidArgumentException($failureMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws exception if the provided $date doesn't implement \DateTimeInterface
|
||||
*
|
||||
* @param mixed $date variable to check against.
|
||||
*
|
||||
* @throws InvalidArgumentTypeException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function isDate($date)
|
||||
{
|
||||
if (gettype($date) != 'object' || !($date instanceof \DateTimeInterface)) {
|
||||
throw new InvalidArgumentTypeException('DateTimeInterface');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws exception if the provided variable is set to null.
|
||||
*
|
||||
* @param mixed $var The variable to check.
|
||||
* @param string $name The parameter name.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function notNull($var, $name)
|
||||
{
|
||||
if (is_null($var)) {
|
||||
throw new \InvalidArgumentException(sprintf(Resources::NULL_MSG, $name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws exception if the object is not of the specified class type.
|
||||
*
|
||||
* @param mixed $objectInstance An object that requires class type validation.
|
||||
* @param mixed $classInstance The instance of the class the the
|
||||
* object instance should be.
|
||||
* @param string $name The name of the object.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function isInstanceOf($objectInstance, $classInstance, $name)
|
||||
{
|
||||
Validate::notNull($classInstance, 'classInstance');
|
||||
if (is_null($objectInstance)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$objectType = gettype($objectInstance);
|
||||
$classType = gettype($classInstance);
|
||||
|
||||
if ($objectType === $classType) {
|
||||
return true;
|
||||
} else {
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf(
|
||||
Resources::INSTANCE_TYPE_VALIDATION_MSG,
|
||||
$name,
|
||||
$objectType,
|
||||
$classType
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an anonymous function that checks if the given hostname is valid or not.
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
public static function getIsValidHostname()
|
||||
{
|
||||
return function ($hostname) {
|
||||
return Validate::isValidHostname($hostname);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an exception if the string is not of a valid hostname.
|
||||
*
|
||||
* @param string $hostname String to check.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isValidHostname($hostname)
|
||||
{
|
||||
if (defined('FILTER_VALIDATE_DOMAIN')) {
|
||||
$isValid = filter_var($hostname, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME);
|
||||
} else {
|
||||
// (less accurate) fallback for PHP < 7.0
|
||||
$isValid = preg_match('/^[a-z0-9_-]+(\.[a-z0-9_-]+)*$/i', $hostname);
|
||||
}
|
||||
|
||||
if ($isValid) {
|
||||
return true;
|
||||
} else {
|
||||
throw new \RuntimeException(
|
||||
sprintf(Resources::INVALID_CONFIG_HOSTNAME, $hostname)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a anonymous function that check if the given uri is valid or not.
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
public static function getIsValidUri()
|
||||
{
|
||||
return function ($uri) {
|
||||
return Validate::isValidUri($uri);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws exception if the string is not of a valid uri.
|
||||
*
|
||||
* @param string $uri String to check.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isValidUri($uri)
|
||||
{
|
||||
$isValid = filter_var($uri, FILTER_VALIDATE_URL);
|
||||
|
||||
if ($isValid) {
|
||||
return true;
|
||||
} else {
|
||||
throw new \RuntimeException(
|
||||
sprintf(Resources::INVALID_CONFIG_URI, $uri)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws exception if the provided variable type is not object.
|
||||
*
|
||||
* @param mixed $var The variable to check.
|
||||
* @param string $name The parameter name.
|
||||
*
|
||||
* @throws InvalidArgumentTypeException.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isObject($var, $name)
|
||||
{
|
||||
if (!is_object($var)) {
|
||||
throw new InvalidArgumentTypeException('object', $name);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws exception if the object is not of the specified class type.
|
||||
*
|
||||
* @param mixed $objectInstance An object that requires class type validation.
|
||||
* @param string $class The class the object instance should be.
|
||||
* @param string $name The parameter name.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isA($objectInstance, $class, $name)
|
||||
{
|
||||
Validate::canCastAsString($class, 'class');
|
||||
Validate::notNull($objectInstance, 'objectInstance');
|
||||
Validate::isObject($objectInstance, 'objectInstance');
|
||||
|
||||
$objectType = get_class($objectInstance);
|
||||
|
||||
if (is_a($objectInstance, $class)) {
|
||||
return true;
|
||||
} else {
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf(
|
||||
Resources::INSTANCE_TYPE_VALIDATION_MSG,
|
||||
$name,
|
||||
$objectType,
|
||||
$class
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate if method exists in object
|
||||
*
|
||||
* @param object $objectInstance An object that requires method existing
|
||||
* validation
|
||||
* @param string $method Method name
|
||||
* @param string $name The parameter name
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function methodExists($objectInstance, $method, $name)
|
||||
{
|
||||
Validate::canCastAsString($method, 'method');
|
||||
Validate::notNull($objectInstance, 'objectInstance');
|
||||
Validate::isObject($objectInstance, 'objectInstance');
|
||||
|
||||
if (method_exists($objectInstance, $method)) {
|
||||
return true;
|
||||
} else {
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf(
|
||||
Resources::ERROR_METHOD_NOT_FOUND,
|
||||
$method,
|
||||
$name
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate if string is date formatted
|
||||
*
|
||||
* @param string $value Value to validate
|
||||
* @param string $name Name of parameter to insert in erro message
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isDateString($value, $name)
|
||||
{
|
||||
Validate::canCastAsString($value, 'value');
|
||||
|
||||
try {
|
||||
new \DateTime($value);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf(
|
||||
Resources::ERROR_INVALID_DATE_STRING,
|
||||
$name,
|
||||
$value
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate if the provided array has key, throw exception otherwise.
|
||||
*
|
||||
* @param string $key The key to be searched.
|
||||
* @param string $name The name of the array.
|
||||
* @param array $array The array to be validated.
|
||||
*
|
||||
* @throws \UnexpectedValueException
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function hasKey($key, $name, array $array)
|
||||
{
|
||||
Validate::isArray($array, $name);
|
||||
|
||||
if (!array_key_exists($key, $array)) {
|
||||
throw new \UnexpectedValueException(
|
||||
sprintf(
|
||||
Resources::INVALID_VALUE_MSG,
|
||||
$name,
|
||||
sprintf(Resources::ERROR_KEY_NOT_EXIST, $key)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user