Exemplo n.º 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;
 }
Exemplo n.º 2
0
 /**
  * Validates if properties is valid or not.
  * 
  * @param mix $properties The properties array.
  * 
  * @return none
  */
 private function _validateProperties($properties)
 {
     Validate::isArray($properties, 'entity properties');
     foreach ($properties as $key => $value) {
         Validate::isString($key, 'key');
         Validate::isTrue($value instanceof Property, Resources::INVALID_PROP_MSG);
         Validate::isTrue(EdmType::validateEdmValue($value->getEdmType(), $value->getValue(), $condition), sprintf(Resources::INVALID_PROP_VAL_MSG, $key, $condition));
     }
 }
Exemplo n.º 3
0
 /**
  * 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;
     }
 }
Exemplo n.º 4
0
 /**
  * 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');
     }
 }
Exemplo n.º 5
0
 /** 
  * 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 etag.
  *
  * @param string $etag value.
  *
  * @return none.
  */
 public function setETag($etag)
 {
     Validate::isString($etag, 'etag');
     $this->_etag = $etag;
 }
Exemplo n.º 7
0
 /**
  * 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()));
 }
Exemplo n.º 8
0
 /**
  * @covers MicrosoftAzure\Storage\Common\Internal\Validate::isString
  */
 public function testIsStringWithNonString()
 {
     $this->setExpectedException(get_class(new InvalidArgumentTypeException('')));
     Validate::isString(new \DateTime(), 'string');
 }
 /**
  * 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;
 }
Exemplo n.º 10
0
 /**
  * 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;
 }
 /**
  * Sets max results.
  *
  * @param string $maxResults value.
  * 
  * @return none.
  */
 public function setMaxResults($maxResults)
 {
     Validate::isString($maxResults, 'maxResults');
     $this->_maxResults = $maxResults;
 }
Exemplo n.º 12
0
 /**
  * Gets table entity.
  *
  * @param string                     $table        The name of the table.
  * @param string                     $partitionKey The entity partition key.
  * @param string                     $rowKey       The entity row key.
  * @param Models\TableServiceOptions $options      The optional parameters.
  *
  * @return Models\GetEntityResult
  *
  * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179421.aspx
  */
 public function getEntity($table, $partitionKey, $rowKey, $options = null)
 {
     Validate::isString($table, 'table');
     Validate::notNullOrEmpty($table, 'table');
     Validate::isTrue(!is_null($partitionKey), Resources::NULL_TABLE_KEY_MSG);
     Validate::isTrue(!is_null($rowKey), Resources::NULL_TABLE_KEY_MSG);
     $method = Resources::HTTP_GET;
     $headers = array();
     $queryParams = array();
     $statusCode = Resources::STATUS_OK;
     $path = $this->_getEntityPath($table, $partitionKey, $rowKey);
     if (is_null($options)) {
         $options = new TableServiceOptions();
     }
     $this->addOptionalHeader($headers, Resources::CONTENT_TYPE, Resources::XML_ATOM_CONTENT_TYPE);
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $context = new HttpCallContext();
     $context->setHeaders($headers);
     $context->setMethod($method);
     $context->setPath($path);
     $context->setQueryParameters($queryParams);
     $context->addStatusCode($statusCode);
     $response = $this->sendContext($context);
     $entity = $this->_atomSerializer->parseEntity($response->getBody());
     $result = new GetEntityResult();
     $result->setEntity($entity);
     return $result;
 }
Exemplo n.º 13
0
 /**
  * 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;
 }
Exemplo n.º 14
0
 /**
  * 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;
 }
Exemplo n.º 15
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;
     }
 }
Exemplo n.º 16
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));
     }
 }
Exemplo n.º 17
0
 /**
  * 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);
 }
Exemplo n.º 18
0
 /**
  * Sets marker.
  *
  * @param string $marker value.
  * 
  * @return none.
  */
 public function setMarker($marker)
 {
     Validate::isString($marker, 'marker');
     $this->_marker = $marker;
 }
 /**
  * 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;
 }
Exemplo n.º 20
0
 /**
  * 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 none
  */
 public function addOptionalQueryParameter($name, $value)
 {
     Validate::isString($name, 'name');
     Validate::isString($value, 'value');
     if (!empty($value)) {
         $this->_queryParams[$name] = $value;
     }
 }