|
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 license@zend.com 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: DynamicTableEntity.php 23167 2010-10-19 17:53:31Z mabe $ |
|
21 */ |
|
22 |
|
23 |
|
24 /** |
|
25 * @see Zend_Service_WindowsAzure_Exception |
|
26 */ |
|
27 require_once 'Zend/Service/WindowsAzure/Exception.php'; |
|
28 |
|
29 /** |
|
30 * @see Zend_Service_WindowsAzure_Storage_TableEntity |
|
31 */ |
|
32 require_once 'Zend/Service/WindowsAzure/Storage/TableEntity.php'; |
|
33 |
|
34 |
|
35 /** |
|
36 * @category Zend |
|
37 * @package Zend_Service_WindowsAzure |
|
38 * @subpackage Storage |
|
39 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
40 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
41 */ |
|
42 class Zend_Service_WindowsAzure_Storage_DynamicTableEntity extends Zend_Service_WindowsAzure_Storage_TableEntity |
|
43 { |
|
44 /** |
|
45 * Dynamic properties |
|
46 * |
|
47 * @var array |
|
48 */ |
|
49 protected $_dynamicProperties = array(); |
|
50 |
|
51 /** |
|
52 * Magic overload for setting properties |
|
53 * |
|
54 * @param string $name Name of the property |
|
55 * @param string $value Value to set |
|
56 */ |
|
57 public function __set($name, $value) { |
|
58 $this->setAzureProperty($name, $value, null); |
|
59 } |
|
60 |
|
61 /** |
|
62 * Magic overload for getting properties |
|
63 * |
|
64 * @param string $name Name of the property |
|
65 */ |
|
66 public function __get($name) { |
|
67 return $this->getAzureProperty($name); |
|
68 } |
|
69 |
|
70 /** |
|
71 * Set an Azure property |
|
72 * |
|
73 * @param string $name Property name |
|
74 * @param mixed $value Property value |
|
75 * @param string $type Property type (Edm.xxxx) |
|
76 * @return Zend_Service_WindowsAzure_Storage_DynamicTableEntity |
|
77 */ |
|
78 public function setAzureProperty($name, $value = '', $type = null) |
|
79 { |
|
80 if (strtolower($name) == 'partitionkey') { |
|
81 $this->setPartitionKey($value); |
|
82 } else if (strtolower($name) == 'rowkey') { |
|
83 $this->setRowKey($value); |
|
84 } else if (strtolower($name) == 'etag') { |
|
85 $this->setEtag($value); |
|
86 } else { |
|
87 if (!array_key_exists(strtolower($name), $this->_dynamicProperties)) { |
|
88 // Determine type? |
|
89 if ($type === null) { |
|
90 $type = 'Edm.String'; |
|
91 if (is_int($value)) { |
|
92 $type = 'Edm.Int32'; |
|
93 } else if (is_float($value)) { |
|
94 $type = 'Edm.Double'; |
|
95 } else if (is_bool($value)) { |
|
96 $type = 'Edm.Boolean'; |
|
97 } |
|
98 } |
|
99 |
|
100 // Set dynamic property |
|
101 $this->_dynamicProperties[strtolower($name)] = (object)array( |
|
102 'Name' => $name, |
|
103 'Type' => $type, |
|
104 'Value' => $value, |
|
105 ); |
|
106 } |
|
107 |
|
108 $this->_dynamicProperties[strtolower($name)]->Value = $value; |
|
109 } |
|
110 return $this; |
|
111 } |
|
112 |
|
113 /** |
|
114 * Set an Azure property type |
|
115 * |
|
116 * @param string $name Property name |
|
117 * @param string $type Property type (Edm.xxxx) |
|
118 * @return Zend_Service_WindowsAzure_Storage_DynamicTableEntity |
|
119 */ |
|
120 public function setAzurePropertyType($name, $type = 'Edm.String') |
|
121 { |
|
122 if (!array_key_exists(strtolower($name), $this->_dynamicProperties)) { |
|
123 $this->setAzureProperty($name, '', $type); |
|
124 } else { |
|
125 $this->_dynamicProperties[strtolower($name)]->Type = $type; |
|
126 } |
|
127 return $this; |
|
128 } |
|
129 |
|
130 /** |
|
131 * Get an Azure property |
|
132 * |
|
133 * @param string $name Property name |
|
134 * @param mixed $value Property value |
|
135 * @param string $type Property type (Edm.xxxx) |
|
136 * @return Zend_Service_WindowsAzure_Storage_DynamicTableEntity |
|
137 */ |
|
138 public function getAzureProperty($name) |
|
139 { |
|
140 if (strtolower($name) == 'partitionkey') { |
|
141 return $this->getPartitionKey(); |
|
142 } |
|
143 if (strtolower($name) == 'rowkey') { |
|
144 return $this->getRowKey(); |
|
145 } |
|
146 if (strtolower($name) == 'etag') { |
|
147 return $this->getEtag(); |
|
148 } |
|
149 |
|
150 if (!array_key_exists(strtolower($name), $this->_dynamicProperties)) { |
|
151 $this->setAzureProperty($name); |
|
152 } |
|
153 |
|
154 return $this->_dynamicProperties[strtolower($name)]->Value; |
|
155 } |
|
156 |
|
157 /** |
|
158 * Get an Azure property type |
|
159 * |
|
160 * @param string $name Property name |
|
161 * @return string Property type (Edm.xxxx) |
|
162 */ |
|
163 public function getAzurePropertyType($name) |
|
164 { |
|
165 if (!array_key_exists(strtolower($name), $this->_dynamicProperties)) { |
|
166 $this->setAzureProperty($name, '', $type); |
|
167 } |
|
168 |
|
169 return $this->_dynamicProperties[strtolower($name)]->Type; |
|
170 } |
|
171 |
|
172 /** |
|
173 * Get Azure values |
|
174 * |
|
175 * @return array |
|
176 */ |
|
177 public function getAzureValues() |
|
178 { |
|
179 return array_merge(array_values($this->_dynamicProperties), parent::getAzureValues()); |
|
180 } |
|
181 |
|
182 /** |
|
183 * Set Azure values |
|
184 * |
|
185 * @param array $values |
|
186 * @param boolean $throwOnError Throw Zend_Service_WindowsAzure_Exception when a property is not specified in $values? |
|
187 * @throws Zend_Service_WindowsAzure_Exception |
|
188 */ |
|
189 public function setAzureValues($values = array(), $throwOnError = false) |
|
190 { |
|
191 // Set parent values |
|
192 parent::setAzureValues($values, false); |
|
193 |
|
194 // Set current values |
|
195 foreach ($values as $key => $value) |
|
196 { |
|
197 $this->$key = $value; |
|
198 } |
|
199 } |
|
200 } |