/** * Constructor. * * @param string $url the url to set. * * @return WindowsAzure\Common\Internal\Http\Url */ public function __construct($url) { $errorMessage = Resources::INVALID_URL_MSG; Validate::isTrue(filter_var($url, FILTER_VALIDATE_URL), $errorMessage); $this->_url = new \Net_URL2($url); $this->_setPathIfEmpty($url); }
/** * Sets the deployment slot. * * @param string $slot The deployment slot name. * * @return none */ public function setSlot($slot) { Validate::isString($slot, 'slot'); Validate::notNullOrEmpty($slot, 'slot'); Validate::isTrue(DeploymentSlot::isValid($slot), sprintf(Resources::INVALID_SLOT, $slot)); $this->_slot = $slot; }
/** * Creates new object based on the builder type in the $config. * * @param WindowsAzure\Common\Configuration $config The config * object. * @param WindowsAzure\Common\Internal\IServicesBuilder $builder The builder * object. * * @return WindowsAzure\Blob\BlobRestProxy */ public static function create($config, $builder = null) { Validate::isTrue($config instanceof Configuration, Resources::INVALID_CONFIG_MSG); if (!is_null($builder)) { Validate::isTrue($builder instanceof IServiceBuilder, Resources::INVALID_BUILDER_MSG); } return $config->create(Resources::BLOB_TYPE_NAME, $builder); }
/** * 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; }
/** * Creates BatchError object. * * @param WindowsAzure\Common\ServiceException $error The error object. * @param array $headers The response headers. * * @return \WindowsAzure\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; }
/** * 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; }
/** * Updates the label and/or the description for a storage account in Windows * Azure. * * @param string $name The storage account name. * @param Models\UpdateStorageServiceOptions $options The optional parameters. * * @return none * * @see http://msdn.microsoft.com/en-us/library/windowsazure/hh264516.aspx */ public function updateStorageService($name, $options) { Validate::isString($name, 'name'); Validate::notNullOrEmpty($name, 'name'); $label = $options->getLabel(); $description = $options->getDescription(); Validate::isTrue(!empty($label) || !empty($description), Resources::INVALID_USA_OPT_MSG); $storageService = new StorageService(); $storageService->setLabel($options->getLabel()); $storageService->setDescription($options->getDescription()); $storageService->addSerializationProperty(XmlSerializer::ROOT_NAME, 'UpdateStorageServiceInput'); $context = new HttpCallContext(); $context->setMethod(Resources::HTTP_PUT); $context->setPath($this->_getStorageServicePath($name)); $context->addStatusCode(Resources::STATUS_OK); $context->setBody($storageService->serialize($this->dataSerializer)); $context->addHeader(Resources::CONTENT_TYPE, Resources::XML_ATOM_CONTENT_TYPE); $this->sendContext($context); }
/** * This method writes a blob by specifying the list of block IDs that make up the * blob. In order to be written as part of a blob, a block must have been * successfully written to the server in a prior createBlobBlock method. * * You can call Put Block List to update a blob by uploading only those blocks * that have changed, then committing the new and existing blocks together. * You can do this by specifying whether to commit a block from the committed * block list or from the uncommitted block list, or to commit the most recently * uploaded version of the block, whichever list it may belong to. * * @param string $container The container name. * @param string $blob The blob name. * @param Models\BlockList|array $blockList The block entries. * @param Models\CommitBlobBlocksOptions $options The optional parameters. * * @return CopyBlobResult * * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179467.aspx */ public function commitBlobBlocks($container, $blob, $blockList, $options = null) { Validate::isString($container, 'container'); Validate::isString($blob, 'blob'); Validate::notNullOrEmpty($blob, 'blob'); Validate::isTrue($blockList instanceof BlockList || is_array($blockList), sprintf(Resources::INVALID_PARAM_MSG, 'blockList', get_class(new BlockList()))); $method = Resources::HTTP_PUT; $headers = array(); $postParams = array(); $queryParams = array(); $path = $this->_createPath($container, $blob); $statusCode = Resources::STATUS_CREATED; $isArray = is_array($blockList); $blockList = $isArray ? BlockList::create($blockList) : $blockList; $body = $blockList->toXml($this->dataSerializer); if (is_null($options)) { $options = new CommitBlobBlocksOptions(); } $blobContentType = $options->getBlobContentType(); $blobContentEncoding = $options->getBlobContentEncoding(); $blobContentLanguage = $options->getBlobContentLanguage(); $blobContentMD5 = $options->getBlobContentMD5(); $blobCacheControl = $options->getBlobCacheControl(); $leaseId = $options->getLeaseId(); $contentType = Resources::URL_ENCODED_CONTENT_TYPE; $metadata = $options->getMetadata(); $headers = $this->generateMetadataHeaders($metadata); $headers = $this->addOptionalAccessConditionHeader($headers, $options->getAccessCondition()); $this->addOptionalHeader($headers, Resources::X_MS_LEASE_ID, $leaseId); $this->addOptionalHeader($headers, Resources::X_MS_BLOB_CACHE_CONTROL, $blobCacheControl); $this->addOptionalHeader($headers, Resources::X_MS_BLOB_CONTENT_TYPE, $blobContentType); $this->addOptionalHeader($headers, Resources::X_MS_BLOB_CONTENT_ENCODING, $blobContentEncoding); $this->addOptionalHeader($headers, Resources::X_MS_BLOB_CONTENT_LANGUAGE, $blobContentLanguage); $this->addOptionalHeader($headers, Resources::X_MS_BLOB_CONTENT_MD5, $blobContentMD5); $this->addOptionalHeader($headers, Resources::CONTENT_TYPE, $contentType); $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout()); $this->addOptionalQueryParam($queryParams, Resources::QP_COMP, 'blocklist'); return $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode, $body); }
/** * 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; }
/** * Sets the properties of the Queue service. * * It's recommended to use getServiceProperties, alter the returned object and * then use setServiceProperties with this altered object. * * @param array $serviceProperties The new service properties. * @param QueueServiceOptions $options The optional parameters. * * @return none */ public function setServiceProperties($serviceProperties, $options = null) { Validate::isTrue($serviceProperties instanceof ServiceProperties, Resources::INVALID_SVC_PROP_MSG); $method = Resources::HTTP_PUT; $headers = array(); $postParams = array(); $queryParams = array(); $statusCode = Resources::STATUS_ACCEPTED; $path = Resources::EMPTY_STRING; $body = $serviceProperties->toXml($this->dataSerializer); if (is_null($options)) { $options = new QueueServiceOptions(); } $this->addOptionalQueryParam($queryParams, Resources::QP_REST_TYPE, 'service'); $this->addOptionalQueryParam($queryParams, Resources::QP_COMP, 'properties'); $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout()); $this->addOptionalHeader($headers, Resources::CONTENT_TYPE, Resources::URL_ENCODED_CONTENT_TYPE); $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode, $body); }
/** * 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 container publicAccess. * * @param string $publicAccess value. * * @return none. */ public function setPublicAccess($publicAccess) { Validate::isTrue(PublicAccessType::isValid($publicAccess), Resources::INVALID_BLOB_PAT_MSG); $this->_publicAccess = $publicAccess; }
/** * Sets mode. * * @param string $mode The change mode. * * @return none */ public function setMode($mode) { Validate::isString($mode, 'mode'); Validate::isTrue(Mode::isValid($mode), Resources::INVALID_CHANGE_MODE_MSG); $this->_mode = $mode; }
/** * Creates or updates the content of an existing file. * * Note that the default content type is application/octet-stream. * * @param string $share The name of the share. * @param string $directoryPath The path of the directory. * @param string $file The name of the file. * @param string|resource $content The content of the file. * @param Models\CreateFileOptions $options The optional parameters. * * @return Models\CreateFileRangeResult|null * */ public function createFileContents($share, $directoryPath, $file, $content, $options = null) { Validate::isString($share, 'share'); Validate::isString($directoryPath, 'directoryPath'); Validate::notNullOrEmpty($directoryPath, 'directoryPath'); Validate::isString($file, 'file'); Validate::isTrue(is_string($content) || is_resource($content), sprintf(Resources::INVALID_PARAM_MSG, 'content', 'string|resource')); $response = null; if (is_null($options)) { $options = new CreateFileOptions(); } // This is for large or failsafe upload $end = 0; $offset = 0; // if threshold is lower than 4mb, honor threshold, else use 4mb $blockSize = 4194304; while (!$end) { if (is_resource($content)) { $body = fread($content, $blockSize); if (feof($content)) { $end = 1; } } else { if (strlen($content) <= $blockSize) { $body = $content; $end = 1; } else { $body = substr($content, 0, $blockSize); $content = substr_replace($content, '', 0, $blockSize); } } $range = new FileRange($offset, $offset + strlen($body) - 1); $offset += $range->getLength(); $response = $this->createFileRange($share, $directoryPath, $file, $range, $body, $options); } return $response; }
/** * 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; }
/** * Cancels an in progress configuration change (update) or upgrade and returns * the deployment to its state before the upgrade or configuration change was * started. * * Note that you can rollback update or upgrade either by specifying the * deployment environment (staging or production), or by specifying the * deployment's unique name. * * @param string $name The hosted service name. * @param string $mode Specifies whether the rollback * should proceed automatically or not. Auto, The rollback proceeds without * further user input. Manual, You must call the walkUpgradeDomain API to apply * the rollback to each upgrade domain. * @param boolean $force Specifies whether the rollback * should proceed even when it will cause local data to be lost from some role * instances. True if the rollback should proceed; otherwise false if the * rollback should fail. * @param GetDeploymentOptions $options The optional parameters. * * @return none * * @see http://msdn.microsoft.com/en-us/library/windowsazure/hh403977.aspx */ public function rollbackUpdateOrUpgrade($name, $mode, $force, $options) { Validate::isString($name, 'name'); Validate::notNullOrEmpty($name, 'name'); Validate::isString($mode, 'mode'); Validate::isTrue(Mode::isValid($mode), Resources::INVALID_CHANGE_MODE_MSG); Validate::isBoolean($force, 'force'); Validate::notNullOrEmpty($force, 'force'); Validate::notNullOrEmpty($options, 'options'); $xmlElements = array(Resources::XTAG_MODE => $mode, Resources::XTAG_FORCE => Utilities::booleanToString($force)); $body = $this->_createRequestXml($xmlElements, Resources::XTAG_ROLLBACK_UPDATE_OR_UPGRADE); $context = new HttpCallContext(); $context->setMethod(Resources::HTTP_POST); $context->setPath($this->_getDeploymentPath($name, $options) . '/'); $context->addStatusCode(Resources::STATUS_ACCEPTED); $context->addQueryParameter(Resources::QP_COMP, Resources::QPV_ROLLBACK); $context->setBody($body); $context->addHeader(Resources::CONTENT_TYPE, Resources::XML_CONTENT_TYPE); assert(Utilities::endsWith($context->getPath(), '/')); $response = $this->sendContext($context); return AsynchronousOperationResult::create($response->getHeader()); }
/** * 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; }
/** * 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); }
/** * @covers WindowsAzure\Common\Internal\Validate::isTrue */ public function testIsTrueWithFalse() { $this->setExpectedException('\\InvalidArgumentException'); Validate::isTrue(false, Resources::EMPTY_STRING); }
/** * Validates that the given config setting exists in the $config and it's value * is doesn't satisfy empty(). * * @param string $setting The config setting name. * @param WindowsAzure\Common\Configuration $config The configuration object. * @param string $name The setting code name. * @param string $restType The REST type name. * * @return none */ private function _validateConfigSetting($setting, $config, $name, $restType) { $missingKeyMsg = sprintf(Resources::MISSING_CONFIG_SETTING_KEY_MSG, $name, $restType); $missingValueMsg = sprintf(Resources::MISSING_CONFIG_SETTING_VALUE_MSG, $name); $properties = $config->getProperties(); Validate::isTrue(array_key_exists($setting, $properties), $missingKeyMsg); $value = $config->getProperty($setting); $isNullEmpty = empty($value); Validate::isTrue(!$isNullEmpty, $missingValueMsg); }