[ 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 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 18 * @license http://framework.zend.com/license/new-bsd New BSD License 19 * @version $Id$ 20 */ 21 22 /** 23 * @see Zend_Http_Client 24 */ 25 require_once 'Zend/Http/Client.php'; 26 27 /** 28 * @category Zend 29 * @package Zend_Service_WindowsAzure 30 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 31 * @license http://framework.zend.com/license/new-bsd New BSD License 32 */ 33 abstract class Zend_Service_WindowsAzure_Credentials_CredentialsAbstract 34 { 35 /** 36 * Development storage account and key 37 */ 38 const DEVSTORE_ACCOUNT = "devstoreaccount1"; 39 const DEVSTORE_KEY = "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="; 40 41 /** 42 * HTTP header prefixes 43 */ 44 const PREFIX_PROPERTIES = "x-ms-prop-"; 45 const PREFIX_METADATA = "x-ms-meta-"; 46 const PREFIX_STORAGE_HEADER = "x-ms-"; 47 48 /** 49 * Permissions 50 */ 51 const PERMISSION_READ = "r"; 52 const PERMISSION_WRITE = "w"; 53 const PERMISSION_DELETE = "d"; 54 const PERMISSION_LIST = "l"; 55 56 /** 57 * Account name for Windows Azure 58 * 59 * @var string 60 */ 61 protected $_accountName = ''; 62 63 /** 64 * Account key for Windows Azure 65 * 66 * @var string 67 */ 68 protected $_accountKey = ''; 69 70 /** 71 * Use path-style URI's 72 * 73 * @var boolean 74 */ 75 protected $_usePathStyleUri = false; 76 77 /** 78 * Creates a new Zend_Service_WindowsAzure_Credentials_CredentialsAbstract instance 79 * 80 * @param string $accountName Account name for Windows Azure 81 * @param string $accountKey Account key for Windows Azure 82 * @param boolean $usePathStyleUri Use path-style URI's 83 */ 84 public function __construct( 85 $accountName = Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::DEVSTORE_ACCOUNT, 86 $accountKey = Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::DEVSTORE_KEY, 87 $usePathStyleUri = false 88 ) { 89 $this->_accountName = $accountName; 90 $this->_accountKey = base64_decode($accountKey); 91 $this->_usePathStyleUri = $usePathStyleUri; 92 } 93 94 /** 95 * Set account name for Windows Azure 96 * 97 * @param string $value 98 * @return Zend_Service_WindowsAzure_Credentials_CredentialsAbstract 99 */ 100 public function setAccountName($value = Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::DEVSTORE_ACCOUNT) 101 { 102 $this->_accountName = $value; 103 return $this; 104 } 105 106 /** 107 * Set account key for Windows Azure 108 * 109 * @param string $value 110 * @return Zend_Service_WindowsAzure_Credentials_CredentialsAbstract 111 */ 112 public function setAccountkey($value = Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::DEVSTORE_KEY) 113 { 114 $this->_accountKey = base64_decode($value); 115 return $this; 116 } 117 118 /** 119 * Set use path-style URI's 120 * 121 * @param boolean $value 122 * @return Zend_Service_WindowsAzure_Credentials_CredentialsAbstract 123 */ 124 public function setUsePathStyleUri($value = false) 125 { 126 $this->_usePathStyleUri = $value; 127 return $this; 128 } 129 130 /** 131 * Sign request URL with credentials 132 * 133 * @param string $requestUrl Request URL 134 * @param string $resourceType Resource type 135 * @param string $requiredPermission Required permission 136 * @return string Signed request URL 137 */ 138 abstract public function signRequestUrl( 139 $requestUrl = '', 140 $resourceType = Zend_Service_WindowsAzure_Storage::RESOURCE_UNKNOWN, 141 $requiredPermission = Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PERMISSION_READ 142 ); 143 144 /** 145 * Sign request headers with credentials 146 * 147 * @param string $httpVerb HTTP verb the request will use 148 * @param string $path Path for the request 149 * @param string $queryString Query string for the request 150 * @param array $headers x-ms headers to add 151 * @param boolean $forTableStorage Is the request for table storage? 152 * @param string $resourceType Resource type 153 * @param string $requiredPermission Required permission 154 * @return array Array of headers 155 */ 156 abstract public function signRequestHeaders( 157 $httpVerb = Zend_Http_Client::GET, 158 $path = '/', 159 $queryString = '', 160 $headers = null, 161 $forTableStorage = false, 162 $resourceType = Zend_Service_WindowsAzure_Storage::RESOURCE_UNKNOWN, 163 $requiredPermission = Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PERMISSION_READ 164 ); 165 166 167 /** 168 * Prepare query string for signing 169 * 170 * @param string $value Original query string 171 * @return string Query string for signing 172 */ 173 protected function _prepareQueryStringForSigning($value) 174 { 175 // Check for 'comp=' 176 if (strpos($value, 'comp=') === false) { 177 // If not found, no query string needed 178 return ''; 179 } else { 180 // If found, make sure it is the only parameter being used 181 if (strlen($value) > 0 && strpos($value, '?') === 0) { 182 $value = substr($value, 1); 183 } 184 185 // Split parts 186 $queryParts = explode('&', $value); 187 foreach ($queryParts as $queryPart) { 188 if (strpos($queryPart, 'comp=') !== false) { 189 return '?' . $queryPart; 190 } 191 } 192 193 // Should never happen... 194 return ''; 195 } 196 } 197 }
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 |