/**
  * @covers WindowsAzure\Blob\Models\AcquireLeaseResult::setLeaseId
  * @covers WindowsAzure\Blob\Models\AcquireLeaseResult::getLeaseId
  */
 public function testSetLeaseId()
 {
     // Setup
     $expected = '0x8CAFB82EFF70C46';
     $result = new AcquireLeaseResult();
     $result->setLeaseId($expected);
     // Test
     $result->setLeaseId($expected);
     // Assert
     $this->assertEquals($expected, $result->getLeaseId());
 }
Exemplo n.º 2
0
 /**
  * Creates AcquireLeaseResult from response headers
  * 
  * @param array $headers response headers
  * 
  * @return AcquireLeaseResult
  */
 public static function create($headers)
 {
     $result = new AcquireLeaseResult();
     $result->setLeaseId(Utilities::tryGetValue($headers, Resources::X_MS_LEASE_ID));
     return $result;
 }
Exemplo n.º 3
0
 /**
  * Renews an existing lease
  * 
  * @param string                    $container name of the container
  * @param string                    $blob      name of the blob
  * @param string                    $leaseId   lease id when acquiring
  * @param Models\BlobServiceOptions $options   optional parameters
  * 
  * @return Models\AcquireLeaseResult
  * 
  * @see http://msdn.microsoft.com/en-us/library/windowsazure/ee691972.aspx
  */
 public function renewLease($container, $blob, $leaseId, $options = null)
 {
     $headers = $this->_putLeaseImpl(LeaseMode::RENEW_ACTION, $container, $blob, $leaseId, is_null($options) ? new BlobServiceOptions() : $options);
     return AcquireLeaseResult::create($headers);
 }
Exemplo n.º 4
0
 /**
  * Does the actual work for leasing a blob.
  * 
  * @param string             $leaseAction     The lease action string.
  * @param string             $container       The container name.
  * @param string             $blob            The blob to lease name.
  * @param string             $leaseId         The existing lease id.
  * @param BlobServiceOptions $options         The optional parameters.
  * @param AccessCondition    $accessCondition The access conditions.
  * 
  * @return AcquireLeaseResult
  */
 private function _putLeaseImpl($leaseAction, $container, $blob, $leaseId, $options, $accessCondition = null)
 {
     Validate::isString($blob, 'blob');
     Validate::notNullOrEmpty($blob, 'blob');
     Validate::isString($container, 'container');
     $method = Resources::HTTP_PUT;
     $headers = array();
     $queryParams = array();
     $postParams = array();
     $path = $this->_createPath($container, $blob);
     $statusCode = Resources::EMPTY_STRING;
     switch ($leaseAction) {
         case LeaseMode::ACQUIRE_ACTION:
             $statusCode = Resources::STATUS_CREATED;
             break;
         case LeaseMode::RENEW_ACTION:
             $statusCode = Resources::STATUS_OK;
             break;
         case LeaseMode::RELEASE_ACTION:
             $statusCode = Resources::STATUS_OK;
             break;
         case LeaseMode::BREAK_ACTION:
             $statusCode = Resources::STATUS_ACCEPTED;
             break;
         default:
             throw new \Exception(Resources::NOT_IMPLEMENTED_MSG);
     }
     if (!is_null($options)) {
         $options = new BlobServiceOptions();
     }
     $headers = $this->addOptionalAccessConditionHeader($headers, $accessCondition);
     $this->addOptionalHeader($headers, Resources::X_MS_LEASE_ID, $leaseId);
     $this->addOptionalHeader($headers, Resources::X_MS_LEASE_ACTION, $leaseAction);
     $this->addOptionalQueryParam($queryParams, Resources::QP_COMP, 'lease');
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $response = $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode);
     return AcquireLeaseResult::create($response->getHeader());
 }