PageRenderTime 394ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/w3-total-cache/lib/Microsoft/WindowsAzure/Storage/DynamicTableEntity.php

https://github.com/yondri/newyorkando
PHP | 215 lines | 90 code | 18 blank | 107 comment | 27 complexity | f63f60ef5ae3e8dc40cbceda97334987 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, GPL-3.0, BSD-3-Clause, AGPL-1.0, AGPL-3.0
  1. <?php
  2. /**
  3. * Copyright (c) 2009 - 2010, 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 - 2010, 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. if (!defined('W3TC')) {
  36. die();
  37. }
  38. /**
  39. * @see Microsoft_WindowsAzure_Exception
  40. */
  41. require_once 'Microsoft/WindowsAzure/Exception.php';
  42. /**
  43. * @see Microsoft_WindowsAzure_Storage_TableEntity
  44. */
  45. require_once 'Microsoft/WindowsAzure/Storage/TableEntity.php';
  46. /**
  47. * @category Microsoft
  48. * @package Microsoft_WindowsAzure
  49. * @subpackage Storage
  50. * @copyright Copyright (c) 2009 - 2010, RealDolmen (http://www.realdolmen.com)
  51. * @license http://phpazure.codeplex.com/license
  52. */
  53. class Microsoft_WindowsAzure_Storage_DynamicTableEntity extends Microsoft_WindowsAzure_Storage_TableEntity
  54. {
  55. /**
  56. * Dynamic properties
  57. *
  58. * @var array
  59. */
  60. protected $_dynamicProperties = array();
  61. /**
  62. * Magic overload for setting properties
  63. *
  64. * @param string $name Name of the property
  65. * @param string $value Value to set
  66. */
  67. public function __set($name, $value) {
  68. $this->setAzureProperty($name, $value, null);
  69. }
  70. /**
  71. * Magic overload for getting properties
  72. *
  73. * @param string $name Name of the property
  74. */
  75. public function __get($name) {
  76. return $this->getAzureProperty($name);
  77. }
  78. /**
  79. * Set an Azure property
  80. *
  81. * @param string $name Property name
  82. * @param mixed $value Property value
  83. * @param string $type Property type (Edm.xxxx)
  84. * @return Microsoft_WindowsAzure_Storage_DynamicTableEntity
  85. */
  86. public function setAzureProperty($name, $value = '', $type = null)
  87. {
  88. if (strtolower($name) == 'partitionkey') {
  89. $this->setPartitionKey($value);
  90. } else if (strtolower($name) == 'rowkey') {
  91. $this->setRowKey($value);
  92. } else if (strtolower($name) == 'etag') {
  93. $this->setEtag($value);
  94. } else {
  95. if (!array_key_exists(strtolower($name), $this->_dynamicProperties)) {
  96. // Determine type?
  97. if (is_null($type)) {
  98. $type = 'Edm.String';
  99. if (is_int($value)) {
  100. $type = 'Edm.Int32';
  101. } else if (is_float($value)) {
  102. $type = 'Edm.Double';
  103. } else if (is_bool($value)) {
  104. $type = 'Edm.Boolean';
  105. }
  106. }
  107. // Set dynamic property
  108. $this->_dynamicProperties[strtolower($name)] = (object)array(
  109. 'Name' => $name,
  110. 'Type' => $type,
  111. 'Value' => $value,
  112. );
  113. }
  114. $this->_dynamicProperties[strtolower($name)]->Value = $value;
  115. }
  116. return $this;
  117. }
  118. /**
  119. * Set an Azure property type
  120. *
  121. * @param string $name Property name
  122. * @param string $type Property type (Edm.xxxx)
  123. * @return Microsoft_WindowsAzure_Storage_DynamicTableEntity
  124. */
  125. public function setAzurePropertyType($name, $type = 'Edm.String')
  126. {
  127. if (!array_key_exists(strtolower($name), $this->_dynamicProperties)) {
  128. $this->setAzureProperty($name, '', $type);
  129. } else {
  130. $this->_dynamicProperties[strtolower($name)]->Type = $type;
  131. }
  132. return $this;
  133. }
  134. /**
  135. * Get an Azure property
  136. *
  137. * @param string $name Property name
  138. * @param mixed $value Property value
  139. * @param string $type Property type (Edm.xxxx)
  140. * @return Microsoft_WindowsAzure_Storage_DynamicTableEntity
  141. */
  142. public function getAzureProperty($name)
  143. {
  144. if (strtolower($name) == 'partitionkey') {
  145. return $this->getPartitionKey();
  146. }
  147. if (strtolower($name) == 'rowkey') {
  148. return $this->getRowKey();
  149. }
  150. if (strtolower($name) == 'etag') {
  151. return $this->getEtag();
  152. }
  153. if (!array_key_exists(strtolower($name), $this->_dynamicProperties)) {
  154. $this->setAzureProperty($name);
  155. }
  156. return $this->_dynamicProperties[strtolower($name)]->Value;
  157. }
  158. /**
  159. * Get an Azure property type
  160. *
  161. * @param string $name Property name
  162. * @return string Property type (Edm.xxxx)
  163. */
  164. public function getAzurePropertyType($name)
  165. {
  166. if (!array_key_exists(strtolower($name), $this->_dynamicProperties)) {
  167. $this->setAzureProperty($name, '', $type);
  168. }
  169. return $this->_dynamicProperties[strtolower($name)]->Type;
  170. }
  171. /**
  172. * Get Azure values
  173. *
  174. * @return array
  175. */
  176. public function getAzureValues()
  177. {
  178. return array_merge(array_values($this->_dynamicProperties), parent::getAzureValues());
  179. }
  180. /**
  181. * Set Azure values
  182. *
  183. * @param array $values
  184. * @param boolean $throwOnError Throw Microsoft_WindowsAzure_Exception when a property is not specified in $values?
  185. * @throws Microsoft_WindowsAzure_Exception
  186. */
  187. public function setAzureValues($values = array(), $throwOnError = false)
  188. {
  189. // Set parent values
  190. parent::setAzureValues($values, false);
  191. // Set current values
  192. foreach ($values as $key => $value)
  193. {
  194. $this->$key = $value;
  195. }
  196. }
  197. }