24 * TODO Can fields be large enough to warrant support for streams? |
24 * TODO Can fields be large enough to warrant support for streams? |
25 * |
25 * |
26 * @category Zend |
26 * @category Zend |
27 * @package Zend_Cloud |
27 * @package Zend_Cloud |
28 * @subpackage DocumentService |
28 * @subpackage DocumentService |
29 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
29 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
30 * @license http://framework.zend.com/license/new-bsd New BSD License |
30 * @license http://framework.zend.com/license/new-bsd New BSD License |
31 */ |
31 */ |
32 class Zend_Cloud_DocumentService_Document |
32 class Zend_Cloud_DocumentService_Document |
33 implements ArrayAccess, IteratorAggregate, Countable |
33 implements ArrayAccess, IteratorAggregate, Countable |
34 { |
34 { |
35 /** key in document denoting identifier */ |
35 /** key in document denoting identifier */ |
36 const KEY_FIELD = '_id'; |
36 const KEY_FIELD = '_id'; |
37 |
37 |
116 if (isset($this->_fields[$name])) { |
116 if (isset($this->_fields[$name])) { |
117 return $this->_fields[$name]; |
117 return $this->_fields[$name]; |
118 } |
118 } |
119 return null; |
119 return null; |
120 } |
120 } |
121 |
121 |
122 /** |
122 /** |
123 * Set field by name. |
123 * Set field by name. |
124 * |
124 * |
125 * @param string $name |
125 * @param string $name |
126 * @param mixed $value |
126 * @param mixed $value |
127 * @return Zend_Cloud_DocumentService_Document |
127 * @return Zend_Cloud_DocumentService_Document |
128 */ |
128 */ |
129 public function setField($name, $value) |
129 public function setField($name, $value) |
130 { |
130 { |
131 $this->_fields[$name] = $value; |
131 $this->_fields[$name] = $value; |
132 return $this; |
132 return $this; |
133 } |
133 } |
134 |
134 |
135 /** |
135 /** |
136 * Overloading: get value |
136 * Overloading: get value |
137 * |
137 * |
138 * @param string $name |
138 * @param string $name |
139 * @return mixed |
139 * @return mixed |
140 */ |
140 */ |
141 public function __get($name) |
141 public function __get($name) |
142 { |
142 { |
143 return $this->getField($name); |
143 return $this->getField($name); |
144 } |
144 } |
145 |
145 |
146 /** |
146 /** |
147 * Overloading: set field |
147 * Overloading: set field |
148 * |
148 * |
149 * @param string $name |
149 * @param string $name |
150 * @param mixed $value |
150 * @param mixed $value |
151 * @return void |
151 * @return void |
152 */ |
152 */ |
153 public function __set($name, $value) |
153 public function __set($name, $value) |
154 { |
154 { |
155 $this->setField($name, $value); |
155 $this->setField($name, $value); |
156 } |
156 } |
157 |
157 |
158 /** |
158 /** |
159 * ArrayAccess: does field exist? |
159 * ArrayAccess: does field exist? |
160 * |
160 * |
161 * @param string $name |
161 * @param string $name |
162 * @return bool |
162 * @return bool |
163 */ |
163 */ |
164 public function offsetExists($name) |
164 public function offsetExists($name) |
165 { |
165 { |
166 return isset($this->_fields[$name]); |
166 return isset($this->_fields[$name]); |
167 } |
167 } |
168 |
168 |
169 /** |
169 /** |
170 * ArrayAccess: get field by name |
170 * ArrayAccess: get field by name |
171 * |
171 * |
172 * @param string $name |
172 * @param string $name |
173 * @return mixed |
173 * @return mixed |
174 */ |
174 */ |
175 public function offsetGet($name) |
175 public function offsetGet($name) |
176 { |
176 { |
177 return $this->getField($name); |
177 return $this->getField($name); |
178 } |
178 } |
179 |
179 |
180 /** |
180 /** |
181 * ArrayAccess: set field to value |
181 * ArrayAccess: set field to value |
182 * |
182 * |
183 * @param string $name |
183 * @param string $name |
184 * @param mixed $value |
184 * @param mixed $value |
185 * @return void |
185 * @return void |
186 */ |
186 */ |
187 public function offsetSet($name, $value) |
187 public function offsetSet($name, $value) |
188 { |
188 { |
189 $this->setField($name, $value); |
189 $this->setField($name, $value); |
190 } |
190 } |
191 |
191 |
192 /** |
192 /** |
193 * ArrayAccess: remove field from document |
193 * ArrayAccess: remove field from document |
194 * |
194 * |
195 * @param string $name |
195 * @param string $name |
196 * @return void |
196 * @return void |
197 */ |
197 */ |
198 public function offsetUnset($name) |
198 public function offsetUnset($name) |
199 { |
199 { |
200 if ($this->offsetExists($name)) { |
200 if ($this->offsetExists($name)) { |
201 unset($this->_fields[$name]); |
201 unset($this->_fields[$name]); |
202 } |
202 } |
203 } |
203 } |
204 |
204 |
205 /** |
205 /** |
206 * Overloading: retrieve and set fields by name |
206 * Overloading: retrieve and set fields by name |
207 * |
207 * |
208 * @param string $name |
208 * @param string $name |
209 * @param mixed $args |
209 * @param mixed $args |
210 * @return mixed |
210 * @return mixed |
211 */ |
211 */ |
212 public function __call($name, $args) |
212 public function __call($name, $args) |
213 { |
213 { |
214 $prefix = substr($name, 0, 3); |
214 $prefix = substr($name, 0, 3); |