equal
deleted
inserted
replaced
13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Service_WindowsAzure |
16 * @package Zend_Service_WindowsAzure |
17 * @subpackage Storage |
17 * @subpackage Storage |
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
20 * @version $Id: TableEntity.php 23167 2010-10-19 17:53:31Z mabe $ |
20 * @version $Id: TableEntity.php 24593 2012-01-05 20:35:02Z matthew $ |
21 */ |
21 */ |
22 |
|
23 /** |
|
24 * @see Zend_Service_WindowsAzure_Exception |
|
25 */ |
|
26 require_once 'Zend/Service/WindowsAzure/Exception.php'; |
|
27 |
|
28 |
22 |
29 /** |
23 /** |
30 * @category Zend |
24 * @category Zend |
31 * @package Zend_Service_WindowsAzure |
25 * @package Zend_Service_WindowsAzure |
32 * @subpackage Storage |
26 * @subpackage Storage |
33 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
27 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
34 * @license http://framework.zend.com/license/new-bsd New BSD License |
28 * @license http://framework.zend.com/license/new-bsd New BSD License |
35 */ |
29 */ |
36 class Zend_Service_WindowsAzure_Storage_TableEntity |
30 class Zend_Service_WindowsAzure_Storage_TableEntity |
37 { |
31 { |
38 const DEFAULT_TIMESTAMP = '1900-01-01T00:00:00'; |
|
39 |
|
40 /** |
32 /** |
41 * Partition key |
33 * Partition key |
42 * |
34 * |
43 * @var string |
35 * @var string |
44 */ |
36 */ |
127 * @azure Timestamp Edm.DateTime |
119 * @azure Timestamp Edm.DateTime |
128 * @return string |
120 * @return string |
129 */ |
121 */ |
130 public function getTimestamp() |
122 public function getTimestamp() |
131 { |
123 { |
132 if (null === $this->_timestamp) { |
124 if (null === $this->_timestamp) { |
133 $this->setTimestamp(self::DEFAULT_TIMESTAMP); |
125 $this->setTimestamp(new DateTime()); |
134 } |
126 } |
135 return $this->_timestamp; |
127 return $this->_timestamp; |
136 } |
128 } |
137 |
129 |
138 /** |
130 /** |
139 * Set timestamp |
131 * Set timestamp |
140 * |
132 * |
141 * @azure Timestamp Edm.DateTime |
133 * @azure Timestamp Edm.DateTime |
142 * @param string $value |
134 * @param DateTime $value |
143 */ |
135 */ |
144 public function setTimestamp($value = '1900-01-01T00:00:00') |
136 public function setTimestamp(DateTime $value) |
145 { |
137 { |
146 $this->_timestamp = $value; |
138 $this->_timestamp = $value; |
147 } |
139 } |
148 |
140 |
149 /** |
141 /** |
228 else |
220 else |
229 $values[$accessor->AzurePropertyName] = false; |
221 $values[$accessor->AzurePropertyName] = false; |
230 break; |
222 break; |
231 case 'edm.double': |
223 case 'edm.double': |
232 $values[$accessor->AzurePropertyName] = floatval($values[$accessor->AzurePropertyName]); break; |
224 $values[$accessor->AzurePropertyName] = floatval($values[$accessor->AzurePropertyName]); break; |
|
225 case 'edm.datetime': |
|
226 $values[$accessor->AzurePropertyName] = $this->_convertToDateTime($values[$accessor->AzurePropertyName]); break; |
233 } |
227 } |
234 } |
228 } |
235 |
229 |
236 // Assign value |
230 // Assign value |
237 if ($accessor->EntityType == 'ReflectionProperty') { |
231 if ($accessor->EntityType == 'ReflectionProperty') { |
240 } else if ($accessor->EntityType == 'ReflectionMethod' && substr(strtolower($accessor->EntityAccessor), 0, 3) == 'set') { |
234 } else if ($accessor->EntityType == 'ReflectionMethod' && substr(strtolower($accessor->EntityAccessor), 0, 3) == 'set') { |
241 $method = $accessor->EntityAccessor; |
235 $method = $accessor->EntityAccessor; |
242 $this->$method($values[$accessor->AzurePropertyName]); |
236 $this->$method($values[$accessor->AzurePropertyName]); |
243 } |
237 } |
244 } else if ($throwOnError) { |
238 } else if ($throwOnError) { |
|
239 require_once 'Zend/Service/WindowsAzure/Exception.php'; |
245 throw new Zend_Service_WindowsAzure_Exception("Property '" . $accessor->AzurePropertyName . "' was not found in \$values array"); |
240 throw new Zend_Service_WindowsAzure_Exception("Property '" . $accessor->AzurePropertyName . "' was not found in \$values array"); |
246 } |
241 } |
247 } |
242 } |
248 |
243 |
249 // Return |
244 // Return |
266 |
261 |
267 // Loop all properties |
262 // Loop all properties |
268 $properties = $type->getProperties(); |
263 $properties = $type->getProperties(); |
269 foreach ($properties as $property) { |
264 foreach ($properties as $property) { |
270 $accessor = self::getAzureAccessor($property); |
265 $accessor = self::getAzureAccessor($property); |
271 if ($accessor !== null) { |
266 if (!is_null($accessor)) { |
272 $azureAccessors[] = $accessor; |
267 $azureAccessors[] = $accessor; |
273 } |
268 } |
274 } |
269 } |
275 |
270 |
276 // Loop all methods |
271 // Loop all methods |
277 $methods = $type->getMethods(); |
272 $methods = $type->getMethods(); |
278 foreach ($methods as $method) { |
273 foreach ($methods as $method) { |
279 $accessor = self::getAzureAccessor($method); |
274 $accessor = self::getAzureAccessor($method); |
280 if ($accessor !== null) { |
275 if (!is_null($accessor)) { |
281 $azureAccessors[] = $accessor; |
276 $azureAccessors[] = $accessor; |
282 } |
277 } |
283 } |
278 } |
284 |
279 |
285 // Return |
280 // Return |
323 'EntityType' => get_class($member), |
318 'EntityType' => get_class($member), |
324 'AzurePropertyName' => $azureProperties[0], |
319 'AzurePropertyName' => $azureProperties[0], |
325 'AzurePropertyType' => isset($azureProperties[1]) ? $azureProperties[1] : '' |
320 'AzurePropertyType' => isset($azureProperties[1]) ? $azureProperties[1] : '' |
326 ); |
321 ); |
327 } |
322 } |
|
323 |
|
324 /** |
|
325 * Converts a string to a DateTime object. Returns false on failure. |
|
326 * |
|
327 * @param string $value The string value to parse |
|
328 * @return DateTime|boolean |
|
329 */ |
|
330 protected function _convertToDateTime($value = '') |
|
331 { |
|
332 if ($value === '') { |
|
333 return false; |
|
334 } |
|
335 |
|
336 if ($value instanceof DateTime) { |
|
337 return $value; |
|
338 } |
|
339 |
|
340 if (@strtotime($value) !== false) { |
|
341 try { |
|
342 if (substr($value, -1) == 'Z') { |
|
343 $value = substr($value, 0, strlen($value) - 1); |
|
344 } |
|
345 return new DateTime($value, new DateTimeZone('UTC')); |
|
346 } |
|
347 catch (Exception $ex) { |
|
348 return false; |
|
349 } |
|
350 } |
|
351 |
|
352 return false; |
|
353 } |
328 } |
354 } |