[ 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_Exception 25 */ 26 require_once 'Zend/Service/WindowsAzure/Exception.php'; 27 28 29 /** 30 * @category Zend 31 * @package Zend_Service_WindowsAzure 32 * @subpackage Storage 33 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 34 * @license http://framework.zend.com/license/new-bsd New BSD License 35 */ 36 class Zend_Service_WindowsAzure_Storage_TableEntity 37 { 38 /** 39 * Partition key 40 * 41 * @var string 42 */ 43 protected $_partitionKey; 44 45 /** 46 * Row key 47 * 48 * @var string 49 */ 50 protected $_rowKey; 51 52 /** 53 * Timestamp 54 * 55 * @var string 56 */ 57 protected $_timestamp = '1900-01-01T00:00:00'; 58 59 /** 60 * Etag 61 * 62 * @var string 63 */ 64 protected $_etag = ''; 65 66 /** 67 * Constructor 68 * 69 * @param string $partitionKey Partition key 70 * @param string $rowKey Row key 71 */ 72 public function __construct($partitionKey = '', $rowKey = '') 73 { 74 $this->_partitionKey = $partitionKey; 75 $this->_rowKey = $rowKey; 76 } 77 78 /** 79 * Get partition key 80 * 81 * @azure PartitionKey 82 * @return string 83 */ 84 public function getPartitionKey() 85 { 86 return $this->_partitionKey; 87 } 88 89 /** 90 * Set partition key 91 * 92 * @azure PartitionKey 93 * @param string $value 94 */ 95 public function setPartitionKey($value) 96 { 97 $this->_partitionKey = $value; 98 } 99 100 /** 101 * Get row key 102 * 103 * @azure RowKey 104 * @return string 105 */ 106 public function getRowKey() 107 { 108 return $this->_rowKey; 109 } 110 111 /** 112 * Set row key 113 * 114 * @azure RowKey 115 * @param string $value 116 */ 117 public function setRowKey($value) 118 { 119 $this->_rowKey = $value; 120 } 121 122 /** 123 * Get timestamp 124 * 125 * @azure Timestamp Edm.DateTime 126 * @return string 127 */ 128 public function getTimestamp() 129 { 130 return $this->_timestamp; 131 } 132 133 /** 134 * Set timestamp 135 * 136 * @azure Timestamp Edm.DateTime 137 * @param string $value 138 */ 139 public function setTimestamp($value = '1900-01-01T00:00:00') 140 { 141 $this->_timestamp = $value; 142 } 143 144 /** 145 * Get etag 146 * 147 * @return string 148 */ 149 public function getEtag() 150 { 151 return $this->_etag; 152 } 153 154 /** 155 * Set etag 156 * 157 * @param string $value 158 */ 159 public function setEtag($value = '') 160 { 161 $this->_etag = $value; 162 } 163 164 /** 165 * Get Azure values 166 * 167 * @return array 168 */ 169 public function getAzureValues() 170 { 171 // Get accessors 172 $accessors = self::getAzureAccessors(get_class($this)); 173 174 // Loop accessors and retrieve values 175 $returnValue = array(); 176 foreach ($accessors as $accessor) { 177 if ($accessor->EntityType == 'ReflectionProperty') { 178 $property = $accessor->EntityAccessor; 179 $returnValue[] = (object)array( 180 'Name' => $accessor->AzurePropertyName, 181 'Type' => $accessor->AzurePropertyType, 182 'Value' => $this->$property, 183 ); 184 } else if ($accessor->EntityType == 'ReflectionMethod' && substr(strtolower($accessor->EntityAccessor), 0, 3) == 'get') { 185 $method = $accessor->EntityAccessor; 186 $returnValue[] = (object)array( 187 'Name' => $accessor->AzurePropertyName, 188 'Type' => $accessor->AzurePropertyType, 189 'Value' => $this->$method(), 190 ); 191 } 192 } 193 194 // Return 195 return $returnValue; 196 } 197 198 /** 199 * Set Azure values 200 * 201 * @param array $values 202 * @param boolean $throwOnError Throw Zend_Service_WindowsAzure_Exception when a property is not specified in $values? 203 * @throws Zend_Service_WindowsAzure_Exception 204 */ 205 public function setAzureValues($values = array(), $throwOnError = false) 206 { 207 // Get accessors 208 $accessors = self::getAzureAccessors(get_class($this)); 209 210 // Loop accessors and set values 211 $returnValue = array(); 212 foreach ($accessors as $accessor) { 213 if (isset($values[$accessor->AzurePropertyName])) { 214 // Cast to correct type 215 if ($accessor->AzurePropertyType != '') { 216 switch (strtolower($accessor->AzurePropertyType)) { 217 case 'edm.int32': 218 case 'edm.int64': 219 $values[$accessor->AzurePropertyName] = intval($values[$accessor->AzurePropertyName]); break; 220 case 'edm.boolean': 221 if ($values[$accessor->AzurePropertyName] == 'true' || $values[$accessor->AzurePropertyName] == '1') 222 $values[$accessor->AzurePropertyName] = true; 223 else 224 $values[$accessor->AzurePropertyName] = false; 225 break; 226 case 'edm.double': 227 $values[$accessor->AzurePropertyName] = floatval($values[$accessor->AzurePropertyName]); break; 228 } 229 } 230 231 // Assign value 232 if ($accessor->EntityType == 'ReflectionProperty') { 233 $property = $accessor->EntityAccessor; 234 $this->$property = $values[$accessor->AzurePropertyName]; 235 } else if ($accessor->EntityType == 'ReflectionMethod' && substr(strtolower($accessor->EntityAccessor), 0, 3) == 'set') { 236 $method = $accessor->EntityAccessor; 237 $this->$method($values[$accessor->AzurePropertyName]); 238 } 239 } else if ($throwOnError) { 240 throw new Zend_Service_WindowsAzure_Exception("Property '" . $accessor->AzurePropertyName . "' was not found in \$values array"); 241 } 242 } 243 244 // Return 245 return $returnValue; 246 } 247 248 /** 249 * Get Azure accessors from class 250 * 251 * @param string $className Class to get accessors for 252 * @return array 253 */ 254 public static function getAzureAccessors($className = '') 255 { 256 // List of accessors 257 $azureAccessors = array(); 258 259 // Get all types 260 $type = new ReflectionClass($className); 261 262 // Loop all properties 263 $properties = $type->getProperties(); 264 foreach ($properties as $property) { 265 $accessor = self::getAzureAccessor($property); 266 if (!is_null($accessor)) { 267 $azureAccessors[] = $accessor; 268 } 269 } 270 271 // Loop all methods 272 $methods = $type->getMethods(); 273 foreach ($methods as $method) { 274 $accessor = self::getAzureAccessor($method); 275 if (!is_null($accessor)) { 276 $azureAccessors[] = $accessor; 277 } 278 } 279 280 // Return 281 return $azureAccessors; 282 } 283 284 /** 285 * Get Azure accessor from reflection member 286 * 287 * @param ReflectionProperty|ReflectionMethod $member 288 * @return object 289 */ 290 public static function getAzureAccessor($member) 291 { 292 // Get comment 293 $docComment = $member->getDocComment(); 294 295 // Check for Azure comment 296 if (strpos($docComment, '@azure') === false) 297 { 298 return null; 299 } 300 301 // Search for @azure contents 302 $azureComment = ''; 303 $commentLines = explode("\n", $docComment); 304 foreach ($commentLines as $commentLine) { 305 if (strpos($commentLine, '@azure') !== false) { 306 $azureComment = trim(substr($commentLine, strpos($commentLine, '@azure') + 6)); 307 while (strpos($azureComment, ' ') !== false) { 308 $azureComment = str_replace(' ', ' ', $azureComment); 309 } 310 break; 311 } 312 } 313 314 // Fetch @azure properties 315 $azureProperties = explode(' ', $azureComment); 316 return (object)array( 317 'EntityAccessor' => $member->getName(), 318 'EntityType' => get_class($member), 319 'AzurePropertyName' => $azureProperties[0], 320 'AzurePropertyType' => isset($azureProperties[1]) ? $azureProperties[1] : '' 321 ); 322 } 323 }
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 |