Beispiel #1
0
 /**
  * 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 none
  */
 public function addEntry($blockId, $type)
 {
     Validate::isString($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;
 }
 /**
  * Unserializes given serialized string to array.
  *
  * @param string $serialized The serialized object in string representation.
  *
  * @return array
  */
 public function unserialize($serialized)
 {
     Validate::isString($serialized, 'serialized');
     $json = json_decode($serialized);
     if ($json && !is_array($json)) {
         return get_object_vars($json);
     } else {
         return $json;
     }
 }
Beispiel #3
0
 /**
  * Creates BatchError object.
  * 
  * @param MicrosoftAzure\Storage\Common\ServiceException $error   The error object.
  * @param array                                $headers The response headers.
  * 
  * @return \MicrosoftAzure\Storage\Table\Models\BatchError 
  */
 public static function create($error, $headers)
 {
     Validate::isTrue($error instanceof ServiceException, Resources::INVALID_EXC_OBJ_MSG);
     Validate::isArray($headers, 'headers');
     $result = new BatchError();
     $clean = array_change_key_case($headers);
     $result->setError($error);
     $contentId = Utilities::tryGetValue($clean, Resources::CONTENT_ID);
     $result->setContentId(is_null($contentId) ? null : intval($contentId));
     return $result;
 }
Beispiel #4
0
 /**
  * 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::isString($value, 'value');
     try {
         new \DateTime($value);
         return true;
     } catch (\Exception $e) {
         throw new \InvalidArgumentException(sprintf(Resources::ERROR_INVALID_DATE_STRING, $name, $value));
     }
 }
 /**
  * Sets the include uncommittedBlobs flag.
  *
  * @param bool $includeUncommittedBlobs value.
  * 
  * @return none.
  */
 public function setIncludeUncommittedBlobs($includeUncommittedBlobs)
 {
     Validate::isBoolean($includeUncommittedBlobs);
     $this->_includeUncommittedBlobs = $includeUncommittedBlobs;
 }
 /**
  * Sets rangeEnd
  * 
  * @param integer $rangeEnd range end value in bytes
  * 
  * @return none
  */
 public function setRangeEnd($rangeEnd)
 {
     Validate::isInteger($rangeEnd, 'rangeEnd');
     $this->_rangeEnd = $rangeEnd;
 }
 /**
  * Creates a snapshot of a blob.
  * 
  * @param string                           $container The name of the container.
  * @param string                           $blob      The name of the blob.
  * @param Models\CreateBlobSnapshotOptions $options   The optional parameters.
  * 
  * @return Models\CreateBlobSnapshotResult
  * 
  * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691971.aspx
  */
 public function createBlobSnapshot($container, $blob, $options = null)
 {
     Validate::isString($container, 'container');
     Validate::isString($blob, 'blob');
     Validate::notNullOrEmpty($blob, 'blob');
     $method = Resources::HTTP_PUT;
     $headers = array();
     $postParams = array();
     $queryParams = array();
     $path = $this->_createPath($container, $blob);
     $expectedStatusCode = Resources::STATUS_CREATED;
     if (is_null($options)) {
         $options = new CreateBlobSnapshotOptions();
     }
     $queryParams[Resources::QP_COMP] = 'snapshot';
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $headers = $this->addOptionalAccessConditionHeader($headers, $options->getAccessCondition());
     $headers = $this->addMetadataHeaders($headers, $options->getMetadata());
     $this->addOptionalHeader($headers, Resources::X_MS_LEASE_ID, $options->getLeaseId());
     $response = $this->send($method, $headers, $queryParams, $postParams, $path, $expectedStatusCode);
     return CreateBlobSnapshotResult::create(HttpFormatter::formatHeaders($response->getHeaders()));
 }
 /**
  * Initializes static members of the class.
  * 
  * @return none
  */
 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, function ($key) {
         $isValidBase64String = base64_decode($key, true);
         if ($isValidBase64String) {
             return true;
         } else {
             throw new \RuntimeException(sprintf(Resources::INVALID_ACCOUNT_KEY_FORMAT, $key));
         }
     });
     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::$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::BLOB_ENDPOINT_NAME;
     self::$validSettingKeys[] = Resources::QUEUE_ENDPOINT_NAME;
     self::$validSettingKeys[] = Resources::TABLE_ENDPOINT_NAME;
 }
 /**
  * Adds deleteEntity operation.
  * 
  * @param string $table        The table name.
  * @param string $partitionKey The entity partition key.
  * @param string $rowKey       The entity row key.
  * @param string $etag         The entity etag.
  * 
  * @return none
  */
 public function addDeleteEntity($table, $partitionKey, $rowKey, $etag = null)
 {
     Validate::isString($table, 'table');
     Validate::isTrue(!is_null($partitionKey), Resources::NULL_TABLE_KEY_MSG);
     Validate::isTrue(!is_null($rowKey), Resources::NULL_TABLE_KEY_MSG);
     $operation = new BatchOperation();
     $type = BatchOperationType::DELETE_ENTITY_OPERATION;
     $operation->setType($type);
     $operation->addParameter(BatchOperationParameterName::BP_TABLE, $table);
     $operation->addParameter(BatchOperationParameterName::BP_ROW_KEY, $rowKey);
     $operation->addParameter(BatchOperationParameterName::BP_ETAG, $etag);
     $operation->addParameter(BatchOperationParameterName::BP_PARTITION_KEY, $partitionKey);
     $this->addOperation($operation);
 }
 /**
  * Adds or sets parameter for the operation.
  * 
  * @param string $name  The param name. Must be valid name.
  * @param mix    $value The param value.
  * 
  * @return none
  */
 public function addParameter($name, $value)
 {
     Validate::isTrue(BatchOperationParameterName::isValid($name), Resources::INVALID_BO_PN_MSG);
     $this->_params[$name] = $value;
 }
 /**
  * Sets blob etag.
  *
  * @param string $etag value.
  *
  * @return none.
  */
 public function setETag($etag)
 {
     Validate::isString($etag, 'etag');
     $this->_etag = $etag;
 }
 /**
  * Sets blob contentLength.
  *
  * @param integer $contentLength value.
  *
  * @return none.
  */
 public function setContentLength($contentLength)
 {
     Validate::isInteger($contentLength, 'contentLength');
     $this->_contentLength = $contentLength;
 }
 /**
  * Sets the include metadata flag.
  *
  * @param bool $includeMetadata value.
  * 
  * @return none.
  */
 public function setIncludeMetadata($includeMetadata)
 {
     Validate::isBoolean($includeMetadata);
     $this->_includeMetadata = $includeMetadata;
 }
 /**
  * Does batch of operations on the table service.
  *
  * @param Models\BatchOperations     $batchOperations The operations to apply.
  * @param Models\TableServiceOptions $options         The optional parameters.
  *
  * @return Models\BatchResult
  */
 public function batch($batchOperations, $options = null)
 {
     Validate::notNullOrEmpty($batchOperations, 'batchOperations');
     $method = Resources::HTTP_POST;
     $operations = $batchOperations->getOperations();
     $contexts = $this->_createOperationsContexts($operations);
     $mime = $this->_createBatchRequestBody($operations, $contexts);
     $body = $mime['body'];
     $headers = $mime['headers'];
     $postParams = array();
     $queryParams = array();
     $statusCode = Resources::STATUS_ACCEPTED;
     $path = '$batch';
     if (is_null($options)) {
         $options = new TableServiceOptions();
     }
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $response = $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode, $body);
     return BatchResult::create($response->getBody(), $operations, $contexts, $this->_atomSerializer, $this->_mimeSerializer);
 }
 /**
  * Sets computeRangeMD5
  * 
  * @param boolean $computeRangeMD5 value
  * 
  * @return none
  */
 public function setComputeRangeMD5($computeRangeMD5)
 {
     Validate::isBoolean($computeRangeMD5);
     $this->_computeRangeMD5 = $computeRangeMD5;
 }
 /**
  * Updates the visibility timeout of a message and/or the message contents.
  * 
  * @param string              $queueName                  The queue name.
  * @param string              $messageId                  The id of the message.
  * @param string              $popReceipt                 The valid pop receipt 
  * value returned from an earlier call to the Get Messages or Update Message
  * operation.
  * @param string              $messageText                The message contents.
  * @param int                 $visibilityTimeoutInSeconds Specifies the new 
  * visibility timeout value, in seconds, relative to server time. 
  * The new value must be larger than or equal to 0, and cannot be larger 
  * than 7 days. The visibility timeout of a message cannot be set to a value 
  * later than the expiry time. A message can be updated until it has been 
  * deleted or has expired.
  * @param QueueServiceOptions $options                    The optional 
  * parameters.
  * 
  * @return MicrosoftAzure\Storage\Common\Models\UpdateMessageResult
  */
 public function updateMessage($queueName, $messageId, $popReceipt, $messageText, $visibilityTimeoutInSeconds, $options = null)
 {
     Validate::isString($queueName, 'queueName');
     Validate::notNullOrEmpty($queueName, 'queueName');
     Validate::isString($messageId, 'messageId');
     Validate::notNullOrEmpty($messageId, 'messageId');
     Validate::isString($popReceipt, 'popReceipt');
     Validate::notNullOrEmpty($popReceipt, 'popReceipt');
     Validate::isString($messageText, 'messageText');
     Validate::isInteger($visibilityTimeoutInSeconds, 'visibilityTimeoutInSeconds');
     Validate::notNull($visibilityTimeoutInSeconds, 'visibilityTimeoutInSeconds');
     $method = Resources::HTTP_PUT;
     $headers = array();
     $postParams = array();
     $queryParams = array();
     $path = $queueName . '/messages' . '/' . $messageId;
     $body = Resources::EMPTY_STRING;
     $statusCode = Resources::STATUS_NO_CONTENT;
     if (is_null($options)) {
         $options = new QueueServiceOptions();
     }
     $this->addOptionalQueryParam($queryParams, Resources::QP_VISIBILITY_TIMEOUT, $visibilityTimeoutInSeconds);
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $this->addOptionalQueryParam($queryParams, Resources::QP_POPRECEIPT, $popReceipt);
     if (!empty($messageText)) {
         $this->addOptionalHeader($headers, Resources::CONTENT_TYPE, Resources::URL_ENCODED_CONTENT_TYPE);
         $message = new QueueMessage();
         $message->setMessageText($messageText);
         $body = $message->toXml($this->dataSerializer);
     }
     $response = $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode, $body);
     $responseHeaders = HttpFormatter::formatHeaders($response->getHeaders());
     $popReceipt = Utilities::tryGetValue($responseHeaders, Resources::X_MS_POPRECEIPT);
     $timeNextVisible = Utilities::tryGetValue($responseHeaders, Resources::X_MS_TIME_NEXT_VISIBLE);
     $date = Utilities::rfc1123ToDateTime($timeNextVisible);
     $result = new UpdateMessageResult();
     $result->setPopReceipt($popReceipt);
     $result->setTimeNextVisible($date);
     return $result;
 }
 /**
  * Sets header type
  * 
  * @param string $headerType can be one of Resources
  * 
  * @return none.
  */
 public function setHeader($headerType)
 {
     $valid = AccessCondition::isValid($headerType);
     Validate::isTrue($valid, Resources::INVALID_HT_MSG);
     $this->_header = $headerType;
 }
 /** 
  * 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::isString($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);
 }
 /**
  * Sets blob sequenceNumber.
  *
  * @param int $sequenceNumber value.
  *
  * @return none.
  */
 public function setSequenceNumber($sequenceNumber)
 {
     Validate::isInteger($sequenceNumber, 'sequenceNumber');
     $this->_sequenceNumber = $sequenceNumber;
 }
 /**
  * Validates the provided metadata array.
  *
  * @param mix $metadata The metadata array.
  *
  * @return none
  */
 public function validateMetadata($metadata)
 {
     if (!is_null($metadata)) {
         Validate::isArray($metadata, 'metadata');
     } else {
         $metadata = array();
     }
     foreach ($metadata as $key => $value) {
         Validate::isString($key, 'metadata key');
         Validate::isString($value, 'metadata value');
     }
 }
 /**
  * Sets popReceipt field.
  * 
  * @param string $popReceipt The pop receipt of the queue message.
  * 
  * @return none.
  */
 public function setPopReceipt($popReceipt)
 {
     Validate::isString($popReceipt, 'popReceipt');
     $this->_popReceipt = $popReceipt;
 }
 /**
  * Adds new signed modifier
  * 
  * @param string    $id         a unique id for this modifier
  * @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 Blob service receives the request.
  * @param \DateTime $expiry     The time at which the Shared Access Signature
  * becomes invalid. This field may be omitted if it has been specified as
  * part of a container-level access policy.
  * @param string    $permission The permissions associated with the Shared
  * Access Signature. The user is restricted to operations allowed by the
  * permissions. Valid permissions values are read (r), write (w), delete (d) and
  * list (l).
  * 
  * @return none.
  * 
  * @see http://msdn.microsoft.com/en-us/library/windowsazure/hh508996.aspx
  */
 public function addSignedIdentifier($id, $start, $expiry, $permission)
 {
     Validate::isString($id, 'id');
     Validate::isDate($start);
     Validate::isDate($expiry);
     Validate::isString($permission, 'permission');
     $accessPolicy = new AccessPolicy();
     $accessPolicy->setStart($start);
     $accessPolicy->setExpiry($expiry);
     $accessPolicy->setPermission($permission);
     $signedIdentifier = new SignedIdentifier();
     $signedIdentifier->setId($id);
     $signedIdentifier->setAccessPolicy($accessPolicy);
     $this->_signedIdentifiers[] = $signedIdentifier;
 }
Beispiel #23
0
 /**
  * Sets entity property.
  * 
  * @param string   $name     The property name.
  * @param Property $property The property object.
  * 
  * @return none
  */
 public function setProperty($name, $property)
 {
     Validate::isTrue($property instanceof Property, Resources::INVALID_PROP_MSG);
     $this->_properties[$name] = $property;
 }
 /**
  * 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 none.
  */
 public function setPublicAccess($publicAccess)
 {
     Validate::isString($publicAccess, 'publicAccess');
     $this->_publicAccess = $publicAccess;
 }
Beispiel #25
0
 /**
  * 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 none
  */
 protected function addOptionalHeader(&$headers, $key, $value)
 {
     Validate::isArray($headers, 'headers');
     Validate::isString($key, 'key');
     Validate::isString($value, 'value');
     if (!is_null($value) && Resources::EMPTY_STRING !== $value) {
         $headers[$key] = $value;
     }
 }
Beispiel #26
0
 /**
  * Converts the type to string if it's empty and validates the type.
  * 
  * @param string $type The Edm type
  * 
  * @return string
  */
 public static function processType($type)
 {
     $type = empty($type) ? self::STRING : $type;
     Validate::isTrue(self::isValid($type), Resources::INVALID_EDM_MSG);
     return $type;
 }
 /**
  * @covers MicrosoftAzure\Storage\Common\Internal\Validate::isDateString
  */
 public function testIsDateStringNotValid()
 {
     // Setup
     $this->setExpectedException('\\InvalidArgumentException');
     $value = 'not a date';
     // Test
     $result = Validate::isDateString($value, 'name');
     // Assert
 }
 /**
  * Sets expiry.
  *
  * @param \DateTime $expiry value.
  * 
  * @return none.
  */
 public function setExpiry($expiry)
 {
     Validate::isDate($expiry);
     $this->_expiry = $expiry;
 }
 /**
  * Unregisters a connection string source.
  * 
  * @param string $name The source name.
  * 
  * @return callable
  */
 public static function unregisterSource($name)
 {
     Validate::isString($name, 'name');
     Validate::notNullOrEmpty($name, 'name');
     self::_init();
     $sourceCallback = Utilities::tryGetValue(self::$_sources, $name);
     if (!is_null($sourceCallback)) {
         unset(self::$_sources[$name]);
     }
     return $sourceCallback;
 }
 /**
  * Sets blob deleteSnaphotsOnly.
  *
  * @param string $deleteSnaphotsOnly value.
  * 
  * @return boolean.
  */
 public function setDeleteSnaphotsOnly($deleteSnaphotsOnly)
 {
     Validate::isBoolean($deleteSnaphotsOnly);
     $this->_deleteSnaphotsOnly = $deleteSnaphotsOnly;
 }