web/lib/Zend/Service/WindowsAzure/Storage/Blob.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
--- a/web/lib/Zend/Service/WindowsAzure/Storage/Blob.php	Thu Mar 21 17:31:31 2013 +0100
+++ b/web/lib/Zend/Service/WindowsAzure/Storage/Blob.php	Thu Mar 21 19:50:53 2013 +0100
@@ -15,35 +15,10 @@
  * @category   Zend
  * @package    Zend_Service_WindowsAzure
  * @subpackage Storage
- * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://todo     name_todo
- * @version    $Id: Blob.php 23167 2010-10-19 17:53:31Z mabe $
- */
-
-/**
- * @see Zend_Service_WindowsAzure_Credentials_CredentialsAbstract_SharedKey
- */
-require_once 'Zend/Service/WindowsAzure/Credentials/SharedKey.php';
-
-/**
- * @see Zend_Service_WindowsAzure_Credentials_SharedAccessSignature
+ * @version    $Id: Blob.php 24697 2012-03-23 13:11:04Z ezimuel $
  */
-require_once 'Zend/Service/WindowsAzure/Credentials/SharedAccessSignature.php';
-
-/**
- * @see Zend_Service_WindowsAzure_RetryPolicy_RetryPolicyAbstract
- */
-require_once 'Zend/Service/WindowsAzure/RetryPolicy/RetryPolicyAbstract.php';
-
-/**
- * @see Zend_Http_Client
- */
-require_once 'Zend/Http/Client.php';
-
-/**
- * @see Zend_Http_Response
- */
-require_once 'Zend/Http/Response.php';
 
 /**
  * @see Zend_Service_WindowsAzure_Storage
@@ -51,16 +26,16 @@
 require_once 'Zend/Service/WindowsAzure/Storage.php';
 
 /**
+ * @see Zend_Service_WindowsAzure_Storage_BlobInstance
+ */
+require_once 'Zend/Service/WindowsAzure/Storage/BlobInstance.php';
+
+/**
  * @see Zend_Service_WindowsAzure_Storage_BlobContainer
  */
 require_once 'Zend/Service/WindowsAzure/Storage/BlobContainer.php';
 
 /**
- * @see Zend_Service_WindowsAzure_Storage_BlobInstance
- */
-require_once 'Zend/Service/WindowsAzure/Storage/BlobInstance.php';
-
-/**
  * @see Zend_Service_WindowsAzure_Storage_PageRegionInstance
  */
 require_once 'Zend/Service/WindowsAzure/Storage/PageRegionInstance.php';
@@ -71,21 +46,19 @@
 require_once 'Zend/Service/WindowsAzure/Storage/LeaseInstance.php';
 
 /**
- * @see Zend_Service_WindowsAzure_Storage_SignedIdentifier
+ * @see Zend_Service_WindowsAzure_Storage_Blob_Stream
  */
-require_once 'Zend/Service/WindowsAzure/Storage/SignedIdentifier.php';
+require_once 'Zend/Service/WindowsAzure/Storage/Blob/Stream.php';
 
 /**
- * @see Zend_Service_WindowsAzure_Exception
+ * @see Zend_Service_WindowsAzure_Credentials_SharedAccessSignature
  */
-require_once 'Zend/Service/WindowsAzure/Exception.php';
-
-
+require_once 'Zend/Service/WindowsAzure/Credentials/SharedAccessSignature.php';
 /**
  * @category   Zend
  * @package    Zend_Service_WindowsAzure
  * @subpackage Storage
- * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  */
 class Zend_Service_WindowsAzure_Storage_Blob extends Zend_Service_WindowsAzure_Storage
@@ -154,7 +127,7 @@
 	 *
 	 * @var Zend_Service_WindowsAzure_Credentials_SharedAccessSignature
 	 */
-	private $_sharedAccessSignatureCredentials = null;
+	protected $_sharedAccessSignatureCredentials = null;
 
 	/**
 	 * Creates a new Zend_Service_WindowsAzure_Storage_Blob instance
@@ -187,12 +160,15 @@
 	public function blobExists($containerName = '', $blobName = '', $snapshotId = null)
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 		if ($blobName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blob name is not specified.');
 		}
 
@@ -215,9 +191,11 @@
 	public function containerExists($containerName = '')
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 			
@@ -243,12 +221,15 @@
 	public function createContainer($containerName = '', $metadata = array())
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 		if (!is_array($metadata)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Meta data should be an array of key and value pairs.');
 		}
 			
@@ -259,6 +240,7 @@
 		// Perform request
 		$response = $this->_performRequest($containerName, '?restype=container', Zend_Http_Client::PUT, $headers, false, null, Zend_Service_WindowsAzure_Storage::RESOURCE_CONTAINER, Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PERMISSION_WRITE);
 		if ($response->isSuccessful()) {
+			
 			return new Zend_Service_WindowsAzure_Storage_BlobContainer(
 			$containerName,
 			$response->getHeader('Etag'),
@@ -266,9 +248,24 @@
 			$metadata
 			);
 		} else {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 		}
 	}
+	
+	/**
+	 * Create container if it does not exist
+	 *
+	 * @param string $containerName Container name
+	 * @param array  $metadata      Key/value pairs of meta data
+	 * @throws Zend_Service_WindowsAzure_Exception
+	 */
+	public function createContainerIfNotExists($containerName = '', $metadata = array())
+	{
+		if (!$this->containerExists($containerName)) {
+			$this->createContainer($containerName, $metadata);
+		}
+	}
 
 	/**
 	 * Get container ACL
@@ -281,9 +278,11 @@
 	public function getContainerAcl($containerName = '', $signedIdentifiers = false)
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 
@@ -313,6 +312,7 @@
 					}
 				}
 
+				require_once 'Zend/Service/WindowsAzure/Storage/SignedIdentifier.php';
 				// Return value
 				$returnValue = array();
 				foreach ($entries as $entry) {
@@ -328,6 +328,7 @@
 				return $returnValue;
 			}
 		} else {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 		}
 	}
@@ -343,9 +344,11 @@
 	public function setContainerAcl($containerName = '', $acl = self::ACL_PRIVATE, $signedIdentifiers = array())
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 
@@ -353,7 +356,7 @@
 		$headers = array();
 
 		// Acl specified?
-		if ($acl != self::ACL_PRIVATE && $acl !== null && $acl != '') {
+		if ($acl != self::ACL_PRIVATE && !is_null($acl) && $acl != '') {
 			$headers[Zend_Service_WindowsAzure_Storage::PREFIX_STORAGE_HEADER . 'blob-public-access'] = $acl;
 		}
 
@@ -382,6 +385,7 @@
 		// Perform request
 		$response = $this->_performRequest($containerName, '?restype=container&comp=acl', Zend_Http_Client::PUT, $headers, false, $policies, Zend_Service_WindowsAzure_Storage::RESOURCE_CONTAINER, Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PERMISSION_WRITE);
 		if (!$response->isSuccessful()) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 		}
 	}
@@ -396,9 +400,11 @@
 	public function getContainer($containerName = '')
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 
@@ -416,6 +422,7 @@
 			$metadata
 			);
 		} else {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 		}
 	}
@@ -430,9 +437,11 @@
 	public function getContainerMetadata($containerName = '')
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 
@@ -452,12 +461,15 @@
 	public function setContainerMetadata($containerName = '', $metadata = array(), $additionalHeaders = array())
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 		if (!is_array($metadata)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Meta data should be an array of key and value pairs.');
 		}
 		if (count($metadata) == 0) {
@@ -476,6 +488,7 @@
 		// Perform request
 		$response = $this->_performRequest($containerName, '?restype=container&comp=metadata', Zend_Http_Client::PUT, $headers, false, null, Zend_Service_WindowsAzure_Storage::RESOURCE_CONTAINER, Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PERMISSION_WRITE);
 		if (!$response->isSuccessful()) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 		}
 	}
@@ -490,9 +503,11 @@
 	public function deleteContainer($containerName = '', $additionalHeaders = array())
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 			
@@ -505,6 +520,7 @@
 		// Perform request
 		$response = $this->_performRequest($containerName, '?restype=container', Zend_Http_Client::DELETE, $headers, false, null, Zend_Service_WindowsAzure_Storage::RESOURCE_CONTAINER, Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PERMISSION_WRITE);
 		if (!$response->isSuccessful()) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 		}
 	}
@@ -524,16 +540,16 @@
 	{
 		// Build query string
 		$queryString = array('comp=list');
-		if ($prefix !== null) {
+		if (!is_null($prefix)) {
 			$queryString[] = 'prefix=' . $prefix;
 		}
-		if ($maxResults !== null) {
+		if (!is_null($maxResults)) {
 			$queryString[] = 'maxresults=' . $maxResults;
 		}
-		if ($marker !== null) {
+		if (!is_null($marker)) {
 			$queryString[] = 'marker=' . $marker;
 		}
-		if ($include !== null) {
+		if (!is_null($include)) {
 			$queryString[] = 'include=' . $include;
 		}
 		$queryString = self::createQueryStringFromArray($queryString);
@@ -545,8 +561,9 @@
 			$xmlMarker = (string)$this->_parseResponse($response)->NextMarker;
 
 			$containers = array();
-			if ($xmlContainers !== null) {
+			if (!is_null($xmlContainers)) {
 				for ($i = 0; $i < count($xmlContainers); $i++) {
+					
 					$containers[] = new Zend_Service_WindowsAzure_Storage_BlobContainer(
 					(string)$xmlContainers[$i]->Name,
 					(string)$xmlContainers[$i]->Etag,
@@ -556,17 +573,18 @@
 				}
 			}
 			$currentResultCount = $currentResultCount + count($containers);
-			if ($maxResults !== null && $currentResultCount < $maxResults) {
-				if ($xmlMarker !== null && $xmlMarker != '') {
+			if (!is_null($maxResults) && $currentResultCount < $maxResults) {
+				if (!is_null($xmlMarker) && $xmlMarker != '') {
 					$containers = array_merge($containers, $this->listContainers($prefix, $maxResults, $xmlMarker, $include, $currentResultCount));
 				}
 			}
-			if ($maxResults !== null && count($containers) > $maxResults) {
+			if (!is_null($maxResults) && count($containers) > $maxResults) {
 				$containers = array_slice($containers, 0, $maxResults);
 			}
 			 
 			return $containers;
 		} else {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 		}
 	}
@@ -586,27 +604,33 @@
 	public function putBlob($containerName = '', $blobName = '', $localFileName = '', $metadata = array(), $leaseId = null, $additionalHeaders = array())
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 		if ($blobName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blob name is not specified.');
 		}
 		if ($localFileName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Local file name is not specified.');
 		}
 		if (!file_exists($localFileName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Local file not found.');
 		}
 		if ($containerName === '$root' && strpos($blobName, '/') !== false) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blobs stored in the root container can not have a name containing a forward slash (/).');
 		}
 			
 		// Check file size
 		if (filesize($localFileName) >= self::MAX_BLOB_SIZE) {
-			return $this->putLargeBlob($containerName, $blobName, $localFileName, $metadata, $leaseId);
+			return $this->putLargeBlob($containerName, $blobName, $localFileName, $metadata, $leaseId, $additionalHeaders);
 		}
 
 		// Put the data to Windows Azure Storage
@@ -628,21 +652,25 @@
 	public function putBlobData($containerName = '', $blobName = '', $data = '', $metadata = array(), $leaseId = null, $additionalHeaders = array())
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 		if ($blobName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blob name is not specified.');
 		}
 		if ($containerName === '$root' && strpos($blobName, '/') !== false) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blobs stored in the root container can not have a name containing a forward slash (/).');
 		}
 
 		// Create metadata headers
 		$headers = array();
-		if ($leaseId !== null) {
+		if (!is_null($leaseId)) {
 			$headers['x-ms-lease-id'] = $leaseId;
 		}
 		$headers = array_merge($headers, $this->_generateMetadataHeaders($metadata));
@@ -661,6 +689,7 @@
 		// Perform request
 		$response = $this->_performRequest($resourceName, '', Zend_Http_Client::PUT, $headers, false, $data, Zend_Service_WindowsAzure_Storage::RESOURCE_BLOB, Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PERMISSION_WRITE);
 		if ($response->isSuccessful()) {
+			
 			return new Zend_Service_WindowsAzure_Storage_BlobInstance(
 			$containerName,
 			$blobName,
@@ -676,6 +705,7 @@
 			$metadata
 			);
 		} else {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 		}
 	}
@@ -688,33 +718,40 @@
 	 * @param string $localFileName Local file name to be uploaded
 	 * @param array  $metadata      Key/value pairs of meta data
 	 * @param string $leaseId       Lease identifier
+	 * @param array  $additionalHeaders  Additional headers. See http://msdn.microsoft.com/en-us/library/dd179371.aspx for more information.
 	 * @return object Partial blob properties
 	 * @throws Zend_Service_WindowsAzure_Exception
 	 */
-	public function putLargeBlob($containerName = '', $blobName = '', $localFileName = '', $metadata = array(), $leaseId = null)
+	public function putLargeBlob($containerName = '', $blobName = '', $localFileName = '', $metadata = array(), $leaseId = null, $additionalHeaders = array())
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 		if ($blobName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blob name is not specified.');
 		}
 		if ($localFileName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Local file name is not specified.');
 		}
 		if (!file_exists($localFileName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Local file not found.');
 		}
 		if ($containerName === '$root' && strpos($blobName, '/') !== false) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blobs stored in the root container can not have a name containing a forward slash (/).');
 		}
 			
 		// Check file size
 		if (filesize($localFileName) < self::MAX_BLOB_SIZE) {
-			return $this->putBlob($containerName, $blobName, $localFileName, $metadata);
+			return $this->putBlob($containerName, $blobName, $localFileName, $metadata, $leaseId, $additionalHeaders);
 		}
 			
 		// Determine number of parts
@@ -729,6 +766,7 @@
 		// Open file
 		$fp = fopen($localFileName, 'r');
 		if ($fp === false) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Could not open local file.');
 		}
 			
@@ -752,7 +790,7 @@
 		fclose($fp);
 
 		// Put block list
-		$this->putBlockList($containerName, $blobName, $blockIdentifiers, $metadata, $leaseId);
+		$this->putBlockList($containerName, $blobName, $blockIdentifiers, $metadata, $leaseId, $additionalHeaders);
 
 		// Return information of the blob
 		return $this->getBlobInstance($containerName, $blobName, null, $leaseId);
@@ -771,24 +809,29 @@
 	public function putBlock($containerName = '', $blobName = '', $identifier = '', $contents = '', $leaseId = null)
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 		if ($identifier === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Block identifier is not specified.');
 		}
 		if (strlen($contents) > self::MAX_BLOB_TRANSFER_SIZE) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Block size is too big.');
 		}
 		if ($containerName === '$root' && strpos($blobName, '/') !== false) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blobs stored in the root container can not have a name containing a forward slash (/).');
 		}
 
 		// Headers
 		$headers = array();
-		if ($leaseId !== null) {
+		if (!is_null($leaseId)) {
 			$headers['x-ms-lease-id'] = $leaseId;
 		}
 			
@@ -798,6 +841,7 @@
 		// Upload
 		$response = $this->_performRequest($resourceName, '?comp=block&blockid=' . base64_encode($identifier), Zend_Http_Client::PUT, $headers, false, $contents, Zend_Service_WindowsAzure_Storage::RESOURCE_BLOB, Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PERMISSION_WRITE);
 		if (!$response->isSuccessful()) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 		}
 	}
@@ -816,18 +860,23 @@
 	public function putBlockList($containerName = '', $blobName = '', $blockList = array(), $metadata = array(), $leaseId = null, $additionalHeaders = array())
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 		if ($blobName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blob name is not specified.');
 		}
 		if (count($blockList) == 0) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Block list does not contain any elements.');
 		}
 		if ($containerName === '$root' && strpos($blobName, '/') !== false) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blobs stored in the root container can not have a name containing a forward slash (/).');
 		}
 
@@ -839,15 +888,15 @@
 
 		// Generate block list request
 		$fileContents = utf8_encode(implode("\n", array(
-			'<?xml version="1.0" encoding="utf-8"?>',
-			'<BlockList>',
-		$blocks,
-			'</BlockList>'
+				'<?xml version="1.0" encoding="utf-8"?>',
+				'<BlockList>',
+				$blocks,
+				'</BlockList>'
 			)));
 
 			// Create metadata headers
 			$headers = array();
-			if ($leaseId !== null) {
+			if (!is_null($leaseId)) {
 				$headers['x-ms-lease-id'] = $leaseId;
 			}
 			$headers = array_merge($headers, $this->_generateMetadataHeaders($metadata));
@@ -863,6 +912,7 @@
 			// Perform request
 			$response = $this->_performRequest($resourceName, '?comp=blocklist', Zend_Http_Client::PUT, $headers, false, $fileContents, Zend_Service_WindowsAzure_Storage::RESOURCE_BLOB, Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PERMISSION_WRITE);
 			if (!$response->isSuccessful()) {
+				require_once 'Zend/Service/WindowsAzure/Exception.php';
 				throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 			}
 	}
@@ -881,15 +931,19 @@
 	public function getBlockList($containerName = '', $blobName = '', $snapshotId = null, $leaseId = null, $type = 0)
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 		if ($blobName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blob name is not specified.');
 		}
 		if ($type < 0 || $type > 2) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Invalid type of block list to retrieve.');
 		}
 
@@ -904,13 +958,13 @@
 
 		// Headers
 		$headers = array();
-		if ($leaseId !== null) {
+		if (!is_null($leaseId)) {
 			$headers['x-ms-lease-id'] = $leaseId;
 		}
 
 		// Build query string
 		$queryString = array('comp=blocklist', 'blocklisttype=' . $blockListType);
-		if ($snapshotId !== null) {
+		if (!is_null($snapshotId)) {
 			$queryString[] = 'snapshot=' . $snapshotId;
 		}
 		$queryString = self::createQueryStringFromArray($queryString);
@@ -945,6 +999,7 @@
 
 			return $returnValue;
 		} else {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 		}
 	}
@@ -964,24 +1019,29 @@
 	public function createPageBlob($containerName = '', $blobName = '', $size = 0, $metadata = array(), $leaseId = null, $additionalHeaders = array())
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 		if ($blobName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blob name is not specified.');
 		}
 		if ($containerName === '$root' && strpos($blobName, '/') !== false) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blobs stored in the root container can not have a name containing a forward slash (/).');
 		}
 		if ($size <= 0) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Page blob size must be specified.');
 		}
 
 		// Create metadata headers
 		$headers = array();
-		if ($leaseId !== null) {
+		if (!is_null($leaseId)) {
 			$headers['x-ms-lease-id'] = $leaseId;
 		}
 		$headers = array_merge($headers, $this->_generateMetadataHeaders($metadata));
@@ -1002,6 +1062,7 @@
 		// Perform request
 		$response = $this->_performRequest($resourceName, '', Zend_Http_Client::PUT, $headers, false, '', Zend_Service_WindowsAzure_Storage::RESOURCE_BLOB, Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PERMISSION_WRITE);
 		if ($response->isSuccessful()) {
+			
 			return new Zend_Service_WindowsAzure_Storage_BlobInstance(
 			$containerName,
 			$blobName,
@@ -1017,6 +1078,7 @@
 			$metadata
 			);
 		} else {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 		}
 	}
@@ -1037,33 +1099,40 @@
 	public function putPage($containerName = '', $blobName = '', $startByteOffset = 0, $endByteOffset = 0, $contents = '', $writeMethod = self::PAGE_WRITE_UPDATE, $leaseId = null, $additionalHeaders = array())
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 		if ($blobName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blob name is not specified.');
 		}
 		if ($containerName === '$root' && strpos($blobName, '/') !== false) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blobs stored in the root container can not have a name containing a forward slash (/).');
 		}
 		if ($startByteOffset % 512 != 0) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Start byte offset must be a modulus of 512.');
 		}
 		if (($endByteOffset + 1) % 512 != 0) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('End byte offset must be a modulus of 512 minus 1.');
 		}
 
 		// Determine size
 		$size = strlen($contents);
 		if ($size >= self::MAX_BLOB_TRANSFER_SIZE) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Page blob size must not be larger than ' + self::MAX_BLOB_TRANSFER_SIZE . ' bytes.');
 		}
 
 		// Create metadata headers
 		$headers = array();
-		if ($leaseId !== null) {
+		if (!is_null($leaseId)) {
 			$headers['x-ms-lease-id'] = $leaseId;
 		}
 
@@ -1084,6 +1153,7 @@
 		// Perform request
 		$response = $this->_performRequest($resourceName, '?comp=page', Zend_Http_Client::PUT, $headers, false, $contents, Zend_Service_WindowsAzure_Storage::RESOURCE_BLOB, Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PERMISSION_WRITE);
 		if (!$response->isSuccessful()) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 		}
 	}
@@ -1102,27 +1172,33 @@
 	public function getPageRegions($containerName = '', $blobName = '', $startByteOffset = 0, $endByteOffset = 0, $leaseId = null)
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 		if ($blobName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blob name is not specified.');
 		}
 		if ($containerName === '$root' && strpos($blobName, '/') !== false) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blobs stored in the root container can not have a name containing a forward slash (/).');
 		}
 		if ($startByteOffset % 512 != 0) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Start byte offset must be a modulus of 512.');
 		}
 		if ($endByteOffset > 0 && ($endByteOffset + 1) % 512 != 0) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('End byte offset must be a modulus of 512 minus 1.');
 		}
 
 		// Create metadata headers
 		$headers = array();
-		if ($leaseId !== null) {
+		if (!is_null($leaseId)) {
 			$headers['x-ms-lease-id'] = $leaseId;
 		}
 
@@ -1144,8 +1220,10 @@
 			} else {
 				$xmlRanges = array($result->PageRange);
 			}
-
+			
+			
 			$ranges = array();
+			
 			for ($i = 0; $i < count($xmlRanges); $i++) {
 				$ranges[] = new Zend_Service_WindowsAzure_Storage_PageRegionInstance(
 				(int)$xmlRanges[$i]->Start,
@@ -1155,6 +1233,7 @@
 			 
 			return $ranges;
 		} else {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 		}
 	}
@@ -1176,33 +1255,41 @@
 	public function copyBlob($sourceContainerName = '', $sourceBlobName = '', $destinationContainerName = '', $destinationBlobName = '', $metadata = array(), $sourceSnapshotId = null, $destinationLeaseId = null, $additionalHeaders = array())
 	{
 		if ($sourceContainerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Source container name is not specified.');
 		}
 		if (!self::isValidContainerName($sourceContainerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Source container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 		if ($sourceBlobName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Source blob name is not specified.');
 		}
 		if ($destinationContainerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Destination container name is not specified.');
 		}
 		if (!self::isValidContainerName($destinationContainerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Destination container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 		if ($destinationBlobName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Destination blob name is not specified.');
 		}
 		if ($sourceContainerName === '$root' && strpos($sourceBlobName, '/') !== false) {
+		require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blobs stored in the root container can not have a name containing a forward slash (/).');
 		}
 		if ($destinationContainerName === '$root' && strpos($destinationBlobName, '/') !== false) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blobs stored in the root container can not have a name containing a forward slash (/).');
 		}
 
 		// Create metadata headers
 		$headers = array();
-		if ($destinationLeaseId !== null) {
+		if (!is_null($destinationLeaseId)) {
 			$headers['x-ms-lease-id'] = $destinationLeaseId;
 		}
 		$headers = array_merge($headers, $this->_generateMetadataHeaders($metadata));
@@ -1214,7 +1301,7 @@
 
 		// Resource names
 		$sourceResourceName = self::createResourceName($sourceContainerName, $sourceBlobName);
-		if ($sourceSnapshotId !== null) {
+		if (!is_null($sourceSnapshotId)) {
 			$sourceResourceName .= '?snapshot=' . $sourceSnapshotId;
 		}
 		$destinationResourceName = self::createResourceName($destinationContainerName, $destinationBlobName);
@@ -1225,6 +1312,7 @@
 		// Perform request
 		$response = $this->_performRequest($destinationResourceName, '', Zend_Http_Client::PUT, $headers, false, null, Zend_Service_WindowsAzure_Storage::RESOURCE_BLOB, Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PERMISSION_WRITE);
 		if ($response->isSuccessful()) {
+			
 			return new Zend_Service_WindowsAzure_Storage_BlobInstance(
 			$destinationContainerName,
 			$destinationBlobName,
@@ -1240,6 +1328,7 @@
 			$metadata
 			);
 		} else {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 		}
 	}
@@ -1258,15 +1347,19 @@
 	public function getBlob($containerName = '', $blobName = '', $localFileName = '', $snapshotId = null, $leaseId = null, $additionalHeaders = array())
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 		if ($blobName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blob name is not specified.');
 		}
 		if ($localFileName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Local file name is not specified.');
 		}
 
@@ -1288,25 +1381,28 @@
 	public function getBlobData($containerName = '', $blobName = '', $snapshotId = null, $leaseId = null, $additionalHeaders = array())
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 		if ($blobName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blob name is not specified.');
 		}
 
 		// Build query string
 		$queryString = array();
-		if ($snapshotId !== null) {
+		if (!is_null($snapshotId)) {
 			$queryString[] = 'snapshot=' . $snapshotId;
 		}
 		$queryString = self::createQueryStringFromArray($queryString);
 
 		// Additional headers?
 		$headers = array();
-		if ($leaseId !== null) {
+		if (!is_null($leaseId)) {
 			$headers['x-ms-lease-id'] = $leaseId;
 		}
 		foreach ($additionalHeaders as $key => $value) {
@@ -1321,6 +1417,7 @@
 		if ($response->isSuccessful()) {
 			return $response->getBody();
 		} else {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 		}
 	}
@@ -1339,28 +1436,32 @@
 	public function getBlobInstance($containerName = '', $blobName = '', $snapshotId = null, $leaseId = null, $additionalHeaders = array())
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 		if ($blobName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blob name is not specified.');
 		}
 		if ($containerName === '$root' && strpos($blobName, '/') !== false) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blobs stored in the root container can not have a name containing a forward slash (/).');
 		}
 
 		// Build query string
 		$queryString = array();
-		if ($snapshotId !== null) {
+		if (!is_null($snapshotId)) {
 			$queryString[] = 'snapshot=' . $snapshotId;
 		}
 		$queryString = self::createQueryStringFromArray($queryString);
 		 
 		// Additional headers?
 		$headers = array();
-		if ($leaseId !== null) {
+		if (!is_null($leaseId)) {
 			$headers['x-ms-lease-id'] = $leaseId;
 		}
 		foreach ($additionalHeaders as $key => $value) {
@@ -1375,26 +1476,27 @@
 		if ($response->isSuccessful()) {
 			// Parse metadata
 			$metadata = $this->_parseMetadataHeaders($response->getHeaders());
-
+			
 			// Return blob
 			return new Zend_Service_WindowsAzure_Storage_BlobInstance(
-			$containerName,
-			$blobName,
-			$snapshotId,
-			$response->getHeader('Etag'),
-			$response->getHeader('Last-modified'),
-			$this->getBaseUrl() . '/' . $containerName . '/' . $blobName,
-			$response->getHeader('Content-Length'),
-			$response->getHeader('Content-Type'),
-			$response->getHeader('Content-Encoding'),
-			$response->getHeader('Content-Language'),
-			$response->getHeader('Cache-Control'),
-			$response->getHeader('x-ms-blob-type'),
-			$response->getHeader('x-ms-lease-status'),
-			false,
-			$metadata
+				$containerName,
+				$blobName,
+				$snapshotId,
+				$response->getHeader('Etag'),
+				$response->getHeader('Last-modified'),
+				$this->getBaseUrl() . '/' . $containerName . '/' . $blobName,
+				$response->getHeader('Content-Length'),
+				$response->getHeader('Content-Type'),
+				$response->getHeader('Content-Encoding'),
+				$response->getHeader('Content-Language'),
+				$response->getHeader('Cache-Control'),
+				$response->getHeader('x-ms-blob-type'),
+				$response->getHeader('x-ms-lease-status'),
+				false,
+				$metadata
 			);
 		} else {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 		}
 	}
@@ -1412,15 +1514,19 @@
 	public function getBlobMetadata($containerName = '', $blobName = '', $snapshotId = null, $leaseId = null)
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 		if ($blobName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blob name is not specified.');
 		}
 		if ($containerName === '$root' && strpos($blobName, '/') !== false) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blobs stored in the root container can not have a name containing a forward slash (/).');
 		}
 
@@ -1442,15 +1548,19 @@
 	public function setBlobMetadata($containerName = '', $blobName = '', $metadata = array(), $leaseId = null, $additionalHeaders = array())
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 		if ($blobName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blob name is not specified.');
 		}
 		if ($containerName === '$root' && strpos($blobName, '/') !== false) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blobs stored in the root container can not have a name containing a forward slash (/).');
 		}
 		if (count($metadata) == 0) {
@@ -1459,7 +1569,7 @@
 
 		// Create metadata headers
 		$headers = array();
-		if ($leaseId !== null) {
+		if (!is_null($leaseId)) {
 			$headers['x-ms-lease-id'] = $leaseId;
 		}
 		$headers = array_merge($headers, $this->_generateMetadataHeaders($metadata));
@@ -1472,6 +1582,7 @@
 		// Perform request
 		$response = $this->_performRequest($containerName . '/' . $blobName, '?comp=metadata', Zend_Http_Client::PUT, $headers, false, null, Zend_Service_WindowsAzure_Storage::RESOURCE_BLOB, Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PERMISSION_WRITE);
 		if (!$response->isSuccessful()) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 		}
 	}
@@ -1490,18 +1601,23 @@
 	public function setBlobProperties($containerName = '', $blobName = '', $leaseId = null, $additionalHeaders = array())
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 		if ($blobName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blob name is not specified.');
 		}
 		if ($containerName === '$root' && strpos($blobName, '/') !== false) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blobs stored in the root container can not have a name containing a forward slash (/).');
 		}
 		if (count($additionalHeaders) == 0) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('No additional headers are specified.');
 		}
 
@@ -1509,7 +1625,7 @@
 		$headers = array();
 
 		// Lease set?
-		if ($leaseId !== null) {
+		if (!is_null($leaseId)) {
 			$headers['x-ms-lease-id'] = $leaseId;
 		}
 
@@ -1521,6 +1637,7 @@
 		// Perform request
 		$response = $this->_performRequest($containerName . '/' . $blobName, '?comp=properties', Zend_Http_Client::PUT, $headers, false, null, Zend_Service_WindowsAzure_Storage::RESOURCE_BLOB, Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PERMISSION_WRITE);
 		if (!$response->isSuccessful()) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 		}
 	}
@@ -1538,15 +1655,19 @@
 	public function getBlobProperties($containerName = '', $blobName = '', $snapshotId = null, $leaseId = null)
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 		if ($blobName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blob name is not specified.');
 		}
 		if ($containerName === '$root' && strpos($blobName, '/') !== false) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blobs stored in the root container can not have a name containing a forward slash (/).');
 		}
 
@@ -1566,28 +1687,32 @@
 	public function deleteBlob($containerName = '', $blobName = '', $snapshotId = null, $leaseId = null, $additionalHeaders = array())
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 		if ($blobName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blob name is not specified.');
 		}
 		if ($containerName === '$root' && strpos($blobName, '/') !== false) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blobs stored in the root container can not have a name containing a forward slash (/).');
 		}
 
 		// Build query string
 		$queryString = array();
-		if ($snapshotId !== null) {
+		if (!is_null($snapshotId)) {
 			$queryString[] = 'snapshot=' . $snapshotId;
 		}
 		$queryString = self::createQueryStringFromArray($queryString);
 			
 		// Additional headers?
 		$headers = array();
-		if ($leaseId !== null) {
+		if (!is_null($leaseId)) {
 			$headers['x-ms-lease-id'] = $leaseId;
 		}
 		foreach ($additionalHeaders as $key => $value) {
@@ -1600,6 +1725,7 @@
 		// Perform request
 		$response = $this->_performRequest($resourceName, $queryString, Zend_Http_Client::DELETE, $headers, false, null, Zend_Service_WindowsAzure_Storage::RESOURCE_BLOB, Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PERMISSION_WRITE);
 		if (!$response->isSuccessful()) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 		}
 	}
@@ -1617,15 +1743,19 @@
 	public function snapshotBlob($containerName = '', $blobName = '', $metadata = array(), $additionalHeaders = array())
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 		if ($blobName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blob name is not specified.');
 		}
 		if ($containerName === '$root' && strpos($blobName, '/') !== false) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blobs stored in the root container can not have a name containing a forward slash (/).');
 		}
 
@@ -1643,6 +1773,7 @@
 		if ($response->isSuccessful()) {
 			return $response->getHeader('x-ms-snapshot');
 		} else {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 		}
 	}
@@ -1660,22 +1791,26 @@
 	public function leaseBlob($containerName = '', $blobName = '', $leaseAction = self::LEASE_ACQUIRE, $leaseId = null)
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 		if ($blobName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blob name is not specified.');
 		}
 		if ($containerName === '$root' && strpos($blobName, '/') !== false) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Blobs stored in the root container can not have a name containing a forward slash (/).');
 		}
 
 		// Additional headers?
 		$headers = array();
 		$headers['x-ms-lease-action'] = strtolower($leaseAction);
-		if ($leaseId !== null) {
+		if (!is_null($leaseId)) {
 			$headers['x-ms-lease-id'] = $leaseId;
 		}
 
@@ -1684,6 +1819,9 @@
 
 		// Perform request
 		$response = $this->_performRequest($resourceName, '?comp=lease', Zend_Http_Client::PUT, $headers, false, null, Zend_Service_WindowsAzure_Storage::RESOURCE_BLOB, Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PERMISSION_WRITE);
+		
+		
+		
 		if ($response->isSuccessful()) {
 			return new Zend_Service_WindowsAzure_Storage_LeaseInstance(
 			$containerName,
@@ -1691,6 +1829,7 @@
 			$response->getHeader('x-ms-lease-id'),
 			$response->getHeader('x-ms-lease-time'));
 		} else {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 		}
 	}
@@ -1711,27 +1850,29 @@
 	public function listBlobs($containerName = '', $prefix = '', $delimiter = '', $maxResults = null, $marker = null, $include = null, $currentResultCount = 0)
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 			
 		// Build query string
 		$queryString = array('restype=container', 'comp=list');
-		if ($prefix !== null) {
+		if (!is_null($prefix)) {
 			$queryString[] = 'prefix=' . $prefix;
 		}
 		if ($delimiter !== '') {
 			$queryString[] = 'delimiter=' . $delimiter;
 		}
-		if ($maxResults !== null) {
+		if (!is_null($maxResults)) {
 			$queryString[] = 'maxresults=' . $maxResults;
 		}
-		if ($marker !== null) {
+		if (!is_null($marker)) {
 			$queryString[] = 'marker=' . $marker;
 		}
-		if ($include !== null) {
+		if (!is_null($include)) {
 			$queryString[] = 'include=' . $include;
 		}
 		$queryString = self::createQueryStringFromArray($queryString);
@@ -1741,10 +1882,11 @@
 		if ($response->isSuccessful()) {
 			// Return value
 			$blobs = array();
-
+	
 			// Blobs
 			$xmlBlobs = $this->_parseResponse($response)->Blobs->Blob;
-			if ($xmlBlobs !== null) {
+			if (!is_null($xmlBlobs)) {
+				
 				for ($i = 0; $i < count($xmlBlobs); $i++) {
 					$properties = (array)$xmlBlobs[$i]->Properties;
 						
@@ -1771,7 +1913,8 @@
 			// Blob prefixes (folders)
 			$xmlBlobs = $this->_parseResponse($response)->Blobs->BlobPrefix;
 				
-			if ($xmlBlobs !== null) {
+			if (!is_null($xmlBlobs)) {
+				
 				for ($i = 0; $i < count($xmlBlobs); $i++) {
 					$blobs[] = new Zend_Service_WindowsAzure_Storage_BlobInstance(
 					$containerName,
@@ -1796,17 +1939,18 @@
 			// More blobs?
 			$xmlMarker = (string)$this->_parseResponse($response)->NextMarker;
 			$currentResultCount = $currentResultCount + count($blobs);
-			if ($maxResults !== null && $currentResultCount < $maxResults) {
-				if ($xmlMarker !== null && $xmlMarker != '') {
+			if (!is_null($maxResults) && $currentResultCount < $maxResults) {
+				if (!is_null($xmlMarker) && $xmlMarker != '') {
 					$blobs = array_merge($blobs, $this->listBlobs($containerName, $prefix, $delimiter, $maxResults, $marker, $include, $currentResultCount));
 				}
 			}
-			if ($maxResults !== null && count($blobs) > $maxResults) {
+			if (!is_null($maxResults) && count($blobs) > $maxResults) {
 				$blobs = array_slice($blobs, 0, $maxResults);
 			}
 				
 			return $blobs;
 		} else {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
 		}
 	}
@@ -1826,9 +1970,11 @@
 	public function generateSharedAccessUrl($containerName = '', $blobName = '', $resource = 'b', $permissions = 'r', $start = '', $expiry = '', $identifier = '')
 	{
 		if ($containerName === '') {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name is not specified.');
 		}
 		if (!self::isValidContainerName($containerName)) {
+			require_once 'Zend/Service/WindowsAzure/Exception.php';
 			throw new Zend_Service_WindowsAzure_Exception('Container name does not adhere to container naming conventions. See http://msdn.microsoft.com/en-us/library/dd135715.aspx for more information.');
 		}
 
@@ -1889,11 +2035,6 @@
 	 */
 	public function registerStreamWrapper($name = 'azure')
 	{
-		/**
-		 * @see Zend_Service_WindowsAzure_Storage_Blob_Stream
-		 */
-		require_once 'Zend/Service/WindowsAzure/Storage/Blob/Stream.php';
-
 		stream_register_wrapper($name, 'Zend_Service_WindowsAzure_Storage_Blob_Stream');
 		$this->registerAsClient($name);
 	}