예제 #1
0
 /**
  * @covers MicrosoftAzure\Storage\Common\Internal\Validate::notNull
  */
 public function testNotNullWithNull()
 {
     $this->setExpectedException('\\InvalidArgumentException');
     Validate::notNullOrEmpty(null, 'variable');
 }
 /**
  * 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;
 }
예제 #3
0
 /**
  * Adds insertOrMergeEntity operation.
  * 
  * @param string $table  The table name.
  * @param Entity $entity The entity instance.
  * 
  * @return none
  */
 public function addInsertOrMergeEntity($table, $entity)
 {
     Validate::isString($table, 'table');
     Validate::notNullOrEmpty($entity, 'entity');
     $operation = new BatchOperation();
     $type = BatchOperationType::INSERT_MERGE_ENTITY_OPERATION;
     $operation->setType($type);
     $operation->addParameter(BatchOperationParameterName::BP_TABLE, $table);
     $operation->addParameter(BatchOperationParameterName::BP_ENTITY, $entity);
     $this->addOperation($operation);
 }
예제 #4
0
 /**
  * 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);
 }
예제 #5
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;
 }
예제 #6
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()));
 }
예제 #7
0
 /**
  * Removes header from the HTTP request headers.
  * 
  * @param string $name The HTTP header name.
  * 
  * @return none
  */
 public function removeHeader($name)
 {
     Validate::isString($name, 'name');
     Validate::notNullOrEmpty($name, 'name');
     unset($this->_headers[$name]);
 }