PageRenderTime 27ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/storage-2009-04-14/library/Microsoft/WindowsAzure/Storage/DynamicTableEntity.php

#
PHP | 213 lines | 87 code | 19 blank | 107 comment | 26 complexity | 89f5a365433dd1e95c776091a908460f MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * Copyright (c) 2009, RealDolmen
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * * Neither the name of RealDolmen nor the
  14. * names of its contributors may be used to endorse or promote products
  15. * derived from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY RealDolmen ''AS IS'' AND ANY
  18. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. * DISCLAIMED. IN NO EVENT SHALL RealDolmen BE LIABLE FOR ANY
  21. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *
  28. * @category Microsoft
  29. * @package Microsoft_WindowsAzure
  30. * @subpackage Storage
  31. * @copyright Copyright (c) 2009, RealDolmen (http://www.realdolmen.com)
  32. * @license http://phpazure.codeplex.com/license
  33. * @version $Id: BlobInstance.php 14561 2009-05-07 08:05:12Z unknown $
  34. */
  35. /**
  36. * @see Microsoft_WindowsAzure_Exception
  37. */
  38. require_once 'Microsoft/WindowsAzure/Exception.php';
  39. /**
  40. * @see Microsoft_WindowsAzure_Storage_TableEntity
  41. */
  42. require_once 'Microsoft/WindowsAzure/Storage/TableEntity.php';
  43. /**
  44. * @category Microsoft
  45. * @package Microsoft_WindowsAzure
  46. * @subpackage Storage
  47. * @copyright Copyright (c) 2009, RealDolmen (http://www.realdolmen.com)
  48. * @license http://phpazure.codeplex.com/license
  49. */
  50. class Microsoft_WindowsAzure_Storage_DynamicTableEntity extends Microsoft_WindowsAzure_Storage_TableEntity
  51. {
  52. /**
  53. * Dynamic properties
  54. *
  55. * @var array
  56. */
  57. protected $_dynamicProperties = array();
  58. /**
  59. * Magic overload for setting properties
  60. *
  61. * @param string $name Name of the property
  62. * @param string $value Value to set
  63. */
  64. public function __set($name, $value) {
  65. $this->setAzureProperty($name, $value, null);
  66. }
  67. /**
  68. * Magic overload for getting properties
  69. *
  70. * @param string $name Name of the property
  71. */
  72. public function __get($name) {
  73. return $this->getAzureProperty($name);
  74. }
  75. /**
  76. * Set an Azure property
  77. *
  78. * @param string $name Property name
  79. * @param mixed $value Property value
  80. * @param string $type Property type (Edm.xxxx)
  81. * @return Microsoft_WindowsAzure_Storage_DynamicTableEntity
  82. */
  83. public function setAzureProperty($name, $value = '', $type = null)
  84. {
  85. if (strtolower($name) == 'partitionkey') {
  86. $this->setPartitionKey($value);
  87. } else if (strtolower($name) == 'rowkey') {
  88. $this->setRowKey($value);
  89. } else if (strtolower($name) == 'etag') {
  90. $this->setEtag($value);
  91. } else {
  92. if (!array_key_exists(strtolower($name), $this->_dynamicProperties)) {
  93. // Determine type?
  94. if (is_null($type)) {
  95. $type = 'Edm.String';
  96. if (is_int($value)) {
  97. $type = 'Edm.Int32';
  98. } else if (is_float($value)) {
  99. $type = 'Edm.Double';
  100. } else if (is_bool($value)) {
  101. $type = 'Edm.Boolean';
  102. }
  103. }
  104. // Set dynamic property
  105. $this->_dynamicProperties[strtolower($name)] = (object)array(
  106. 'Name' => $name,
  107. 'Type' => $type,
  108. 'Value' => $value,
  109. );
  110. }
  111. $this->_dynamicProperties[strtolower($name)]->Value = $value;
  112. }
  113. return $this;
  114. }
  115. /**
  116. * Set an Azure property type
  117. *
  118. * @param string $name Property name
  119. * @param string $type Property type (Edm.xxxx)
  120. * @return Microsoft_WindowsAzure_Storage_DynamicTableEntity
  121. */
  122. public function setAzurePropertyType($name, $type = 'Edm.String')
  123. {
  124. if (!array_key_exists(strtolower($name), $this->_dynamicProperties)) {
  125. $this->setAzureProperty($name, '', $type);
  126. } else {
  127. $this->_dynamicProperties[strtolower($name)]->Type = $type;
  128. }
  129. return $this;
  130. }
  131. /**
  132. * Get an Azure property
  133. *
  134. * @param string $name Property name
  135. * @param mixed $value Property value
  136. * @param string $type Property type (Edm.xxxx)
  137. * @return Microsoft_WindowsAzure_Storage_DynamicTableEntity
  138. */
  139. public function getAzureProperty($name)
  140. {
  141. if (strtolower($name) == 'partitionkey') {
  142. return $this->getPartitionKey();
  143. }
  144. if (strtolower($name) == 'rowkey') {
  145. return $this->getRowKey();
  146. }
  147. if (strtolower($name) == 'etag') {
  148. return $this->getEtag();
  149. }
  150. if (!array_key_exists(strtolower($name), $this->_dynamicProperties)) {
  151. $this->setAzureProperty($name);
  152. }
  153. return $this->_dynamicProperties[strtolower($name)]->Value;
  154. }
  155. /**
  156. * Get an Azure property type
  157. *
  158. * @param string $name Property name
  159. * @return string Property type (Edm.xxxx)
  160. */
  161. public function getAzurePropertyType($name)
  162. {
  163. if (!array_key_exists(strtolower($name), $this->_dynamicProperties)) {
  164. $this->setAzureProperty($name, '', $type);
  165. }
  166. return $this->_dynamicProperties[strtolower($name)]->Type;
  167. }
  168. /**
  169. * Get Azure values
  170. *
  171. * @return array
  172. */
  173. public function getAzureValues()
  174. {
  175. return array_merge(array_values($this->_dynamicProperties), parent::getAzureValues());
  176. }
  177. /**
  178. * Set Azure values
  179. *
  180. * @param array $values
  181. * @param boolean $throwOnError Throw Microsoft_WindowsAzure_Exception when a property is not specified in $values?
  182. * @throws Microsoft_WindowsAzure_Exception
  183. */
  184. public function setAzureValues($values = array(), $throwOnError = false)
  185. {
  186. // Set parent values
  187. parent::setAzureValues($values, false);
  188. // Set current values
  189. foreach ($values as $key => $value)
  190. {
  191. $this->$key = $value;
  192. }
  193. }
  194. }