[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Zend Framework 4 * 5 * LICENSE 6 * 7 * This source file is subject to the new BSD license that is bundled 8 * with this package in the file LICENSE.txt. 9 * It is also available through the world-wide-web at this URL: 10 * http://framework.zend.com/license/new-bsd 11 * If you did not receive a copy of the license and are unable to 12 * obtain it through the world-wide-web, please send an email 13 * to [email protected] so we can send you a copy immediately. 14 * 15 * @category Zend 16 * @package Zend_Service_WindowsAzure 17 * @subpackage Storage 18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 19 * @license http://framework.zend.com/license/new-bsd New BSD License 20 * @version $Id$ 21 */ 22 23 /** 24 * @see Zend_Service_WindowsAzure_Storage 25 */ 26 require_once 'Zend/Service/WindowsAzure/Storage.php'; 27 28 /** 29 * @see Zend_Service_WindowsAzure_Credentials_CredentialsAbstract 30 */ 31 require_once 'Zend/Service/WindowsAzure/Credentials/CredentialsAbstract.php'; 32 33 /** 34 * @see Zend_Service_WindowsAzure_Exception 35 */ 36 require_once 'Zend/Service/WindowsAzure/Exception.php'; 37 38 /** 39 * @see Zend_Service_WindowsAzure_Storage_Batch 40 */ 41 require_once 'Zend/Service/WindowsAzure/Storage/Batch.php'; 42 43 /** 44 * @see Zend_Http_Client 45 */ 46 require_once 'Zend/Http/Client.php'; 47 48 /** 49 * @see Zend_Http_Response 50 */ 51 require_once 'Zend/Http/Response.php'; 52 53 /** 54 * @category Zend 55 * @package Zend_Service_WindowsAzure 56 * @subpackage Storage 57 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 58 * @license http://framework.zend.com/license/new-bsd New BSD License 59 */ 60 abstract class Zend_Service_WindowsAzure_Storage_BatchStorageAbstract 61 extends Zend_Service_WindowsAzure_Storage 62 { 63 /** 64 * Current batch 65 * 66 * @var Zend_Service_WindowsAzure_Storage_Batch 67 */ 68 protected $_currentBatch = null; 69 70 /** 71 * Set current batch 72 * 73 * @param Zend_Service_WindowsAzure_Storage_Batch $batch Current batch 74 * @throws Zend_Service_WindowsAzure_Exception 75 */ 76 public function setCurrentBatch(Zend_Service_WindowsAzure_Storage_Batch $batch = null) 77 { 78 if (!is_null($batch) && $this->isInBatch()) { 79 throw new Zend_Service_WindowsAzure_Exception('Only one batch can be active at a time.'); 80 } 81 $this->_currentBatch = $batch; 82 } 83 84 /** 85 * Get current batch 86 * 87 * @return Zend_Service_WindowsAzure_Storage_Batch 88 */ 89 public function getCurrentBatch() 90 { 91 return $this->_currentBatch; 92 } 93 94 /** 95 * Is there a current batch? 96 * 97 * @return boolean 98 */ 99 public function isInBatch() 100 { 101 return !is_null($this->_currentBatch); 102 } 103 104 /** 105 * Starts a new batch operation set 106 * 107 * @return Zend_Service_WindowsAzure_Storage_Batch 108 * @throws Zend_Service_WindowsAzure_Exception 109 */ 110 public function startBatch() 111 { 112 return new Zend_Service_WindowsAzure_Storage_Batch($this, $this->getBaseUrl()); 113 } 114 115 /** 116 * Perform batch using Zend_Http_Client channel, combining all batch operations into one request 117 * 118 * @param array $operations Operations in batch 119 * @param boolean $forTableStorage Is the request for table storage? 120 * @param boolean $isSingleSelect Is the request a single select statement? 121 * @param string $resourceType Resource type 122 * @param string $requiredPermission Required permission 123 * @return Zend_Http_Response 124 */ 125 public function performBatch($operations = array(), $forTableStorage = false, $isSingleSelect = false, $resourceType = Zend_Service_WindowsAzure_Storage::RESOURCE_UNKNOWN, $requiredPermission = Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PERMISSION_READ) 126 { 127 // Generate boundaries 128 $batchBoundary = 'batch_' . md5(time() . microtime()); 129 $changesetBoundary = 'changeset_' . md5(time() . microtime()); 130 131 // Set headers 132 $headers = array(); 133 134 // Add version header 135 $headers['x-ms-version'] = $this->_apiVersion; 136 137 // Add content-type header 138 $headers['Content-Type'] = 'multipart/mixed; boundary=' . $batchBoundary; 139 140 // Set path and query string 141 $path = '/$batch'; 142 $queryString = ''; 143 144 // Set verb 145 $httpVerb = Zend_Http_Client::POST; 146 147 // Generate raw data 148 $rawData = ''; 149 150 // Single select? 151 if ($isSingleSelect) { 152 $operation = $operations[0]; 153 $rawData .= '--' . $batchBoundary . "\n"; 154 $rawData .= 'Content-Type: application/http' . "\n"; 155 $rawData .= 'Content-Transfer-Encoding: binary' . "\n\n"; 156 $rawData .= $operation; 157 $rawData .= '--' . $batchBoundary . '--'; 158 } else { 159 $rawData .= '--' . $batchBoundary . "\n"; 160 $rawData .= 'Content-Type: multipart/mixed; boundary=' . $changesetBoundary . "\n\n"; 161 162 // Add operations 163 foreach ($operations as $operation) 164 { 165 $rawData .= '--' . $changesetBoundary . "\n"; 166 $rawData .= 'Content-Type: application/http' . "\n"; 167 $rawData .= 'Content-Transfer-Encoding: binary' . "\n\n"; 168 $rawData .= $operation; 169 } 170 $rawData .= '--' . $changesetBoundary . '--' . "\n"; 171 172 $rawData .= '--' . $batchBoundary . '--'; 173 } 174 175 // Generate URL and sign request 176 $requestUrl = $this->_credentials->signRequestUrl($this->getBaseUrl() . $path . $queryString, $resourceType, $requiredPermission); 177 $requestHeaders = $this->_credentials->signRequestHeaders($httpVerb, $path, $queryString, $headers, $forTableStorage, $resourceType, $requiredPermission); 178 179 // Prepare request 180 $this->_httpClientChannel->resetParameters(true); 181 $this->_httpClientChannel->setUri($requestUrl); 182 $this->_httpClientChannel->setHeaders($requestHeaders); 183 $this->_httpClientChannel->setRawData($rawData); 184 185 // Execute request 186 $response = $this->_retryPolicy->execute( 187 array($this->_httpClientChannel, 'request'), 188 array($httpVerb) 189 ); 190 191 return $response; 192 } 193 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |