source: trunk/www.guidonia.net/wp/wp-content/plugins/webtv/Drivers/Zend/Gdata/App/Feed.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 9.5 KB
Line 
1<?php
2
3/**
4 * Zend Framework
5 *
6 * LICENSE
7 *
8 * This source file is subject to the new BSD license that is bundled
9 * with this package in the file LICENSE.txt.
10 * It is also available through the world-wide-web at this URL:
11 * http://framework.zend.com/license/new-bsd
12 * If you did not receive a copy of the license and are unable to
13 * obtain it through the world-wide-web, please send an email
14 * to license@zend.com so we can send you a copy immediately.
15 *
16 * @category Zend
17 * @package Zend_Gdata
18 * @subpackage App
19 * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license http://framework.zend.com/license/new-bsd New BSD License
21 */
22
23/**
24 * @see Zend_Gdata_App_Entry
25 */
26require_once 'Zend/Gdata/App/Entry.php';
27
28/**
29 * @see Zend_Gdata_App_FeedSourceParent
30 */
31require_once 'Zend/Gdata/App/FeedSourceParent.php';
32
33/**
34 * Atom feed class
35 *
36 * @category Zend
37 * @package Zend_Gdata
38 * @subpackage App
39 * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
40 * @license http://framework.zend.com/license/new-bsd New BSD License
41 */
42class Zend_Gdata_App_Feed extends Zend_Gdata_App_FeedSourceParent
43 implements Iterator, ArrayAccess
44{
45
46 /**
47 * The root xml element of this data element
48 *
49 * @var string
50 */
51 protected $_rootElement = 'feed';
52
53 /**
54 * Cache of feed entries.
55 *
56 * @var array
57 */
58 protected $_entry = array();
59
60 /**
61 * Current location in $_entry array
62 *
63 * @var int
64 */
65 protected $_entryIndex = 0;
66
67 /**
68 * Make accessing some individual elements of the feed easier.
69 *
70 * Special accessors 'entry' and 'entries' are provided so that if
71 * you wish to iterate over an Atom feed's entries, you can do so
72 * using foreach ($feed->entries as $entry) or foreach
73 * ($feed->entry as $entry).
74 *
75 * @param string $var The property to get.
76 * @return mixed
77 */
78 public function __get($var)
79 {
80 switch ($var) {
81 case 'entries':
82 return $this;
83 default:
84 return parent::__get($var);
85 }
86 }
87
88 /**
89 * Retrieves the DOM model representing this object and all children
90 *
91 * @param DOMDocument $doc
92 * @return DOMElement
93 */
94 public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
95 {
96 $element = parent::getDOM($doc, $majorVersion, $minorVersion);
97 foreach ($this->_entry as $entry) {
98 $element->appendChild($entry->getDOM($element->ownerDocument));
99 }
100 return $element;
101 }
102
103 /**
104 * Creates individual Entry objects of the appropriate type and
105 * stores them in the $_entry array based upon DOM data.
106 *
107 * @param DOMNode $child The DOMNode to process
108 */
109 protected function takeChildFromDOM($child)
110 {
111 $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
112 switch ($absoluteNodeName) {
113 case $this->lookupNamespace('atom') . ':' . 'entry':
114 $newEntry = new $this->_entryClassName($child);
115 $newEntry->setHttpClient($this->getHttpClient());
116 $newEntry->setMajorProtocolVersion($this->getMajorProtocolVersion());
117 $newEntry->setMinorProtocolVersion($this->getMinorProtocolVersion());
118 $this->_entry[] = $newEntry;
119 break;
120 default:
121 parent::takeChildFromDOM($child);
122 break;
123 }
124 }
125
126 /**
127 * Get the number of entries in this feed object.
128 *
129 * @return integer Entry count.
130 */
131 public function count()
132 {
133 return count($this->_entry);
134 }
135
136 /**
137 * Required by the Iterator interface.
138 *
139 * @return void
140 */
141 public function rewind()
142 {
143 $this->_entryIndex = 0;
144 }
145
146 /**
147 * Required by the Iterator interface.
148 *
149 * @return mixed The current row, or null if no rows.
150 */
151 public function current()
152 {
153 return $this->_entry[$this->_entryIndex];
154 }
155
156 /**
157 * Required by the Iterator interface.
158 *
159 * @return mixed The current row number (starts at 0), or NULL if no rows
160 */
161 public function key()
162 {
163 return $this->_entryIndex;
164 }
165
166 /**
167 * Required by the Iterator interface.
168 *
169 * @return mixed The next row, or null if no more rows.
170 */
171 public function next()
172 {
173 ++$this->_entryIndex;
174 }
175
176 /**
177 * Required by the Iterator interface.
178 *
179 * @return boolean Whether the iteration is valid
180 */
181 public function valid()
182 {
183 return 0 <= $this->_entryIndex && $this->_entryIndex < $this->count();
184 }
185
186 /**
187 * Gets the array of atom:entry elements contained within this
188 * atom:feed representation
189 *
190 * @return array Zend_Gdata_App_Entry array
191 */
192 public function getEntry()
193 {
194 return $this->_entry;
195 }
196
197 /**
198 * Sets the array of atom:entry elements contained within this
199 * atom:feed representation
200 *
201 * @param array $value The array of Zend_Gdata_App_Entry elements
202 * @return Zend_Gdata_App_Feed Provides a fluent interface
203 */
204 public function setEntry($value)
205 {
206 $this->_entry = $value;
207 return $this;
208 }
209
210 /**
211 * Adds an entry representation to the array of entries
212 * contained within this feed
213 *
214 * @param Zend_Gdata_App_Entry An individual entry to add.
215 * @return Zend_Gdata_App_Feed Provides a fluent interface
216 */
217 public function addEntry($value)
218 {
219 $this->_entry[] = $value;
220 return $this;
221 }
222
223 /**
224 * Required by the ArrayAccess interface
225 *
226 * @param int $key The index to set
227 * @param Zend_Gdata_App_Entry $value The value to set
228 * @return void
229 */
230 public function offsetSet($key, $value)
231 {
232 $this->_entry[$key] = $value;
233 }
234
235 /**
236 * Required by the ArrayAccess interface
237 *
238 * @param int $key The index to get
239 * @param Zend_Gdata_App_Entry $value The value to set
240 */
241 public function offsetGet($key)
242 {
243 if (array_key_exists($key, $this->_entry)) {
244 return $this->_entry[$key];
245 }
246 }
247
248 /**
249 * Required by the ArrayAccess interface
250 *
251 * @param int $key The index to set
252 * @param Zend_Gdata_App_Entry $value The value to set
253 */
254 public function offsetUnset($key)
255 {
256 if (array_key_exists($key, $this->_entry)) {
257 unset($this->_entry[$key]);
258 }
259 }
260
261 /**
262 * Required by the ArrayAccess interface
263 *
264 * @param int $key The index to check for existence
265 * @return boolean
266 */
267 public function offsetExists($key)
268 {
269 return (array_key_exists($key, $this->_entry));
270 }
271
272 /**
273 * Retrieve the next set of results from this feed.
274 *
275 * @throws Zend_Gdata_App_Exception
276 * @return mixed|null Returns the next set of results as a feed of the same
277 * class as this feed, or null if no results exist.
278 */
279 public function getNextFeed()
280 {
281 $nextLink = $this->getNextLink();
282 if (!$nextLink) {
283 require_once 'Zend/Gdata/App/HttpException.php';
284 throw new Zend_Gdata_App_Exception('No link to next set ' .
285 'of results found.');
286 }
287 $nextLinkHref = $nextLink->getHref();
288 $service = new Zend_Gdata_App($this->getHttpClient());
289
290 return $service->getFeed($nextLinkHref, get_class($this));
291 }
292
293 /**
294 * Retrieve the previous set of results from this feed.
295 *
296 * @throws Zend_Gdata_App_Exception
297 * @return mixed|null Returns the previous set of results as a feed of
298 * the same class as this feed, or null if no results exist.
299 */
300 public function getPreviousFeed()
301 {
302 $previousLink = $this->getPreviousLink();
303 if (!$previousLink) {
304 require_once 'Zend/Gdata/App/HttpException.php';
305 throw new Zend_Gdata_App_Exception('No link to previous set ' .
306 'of results found.');
307 }
308 $previousLinkHref = $previousLink->getHref();
309 $service = new Zend_Gdata_App($this->getHttpClient());
310
311 return $service->getFeed($previousLinkHref, get_class($this));
312 }
313
314 /**
315 * Set the major protocol version that should be used. Values < 1 will
316 * cause a Zend_Gdata_App_InvalidArgumentException to be thrown.
317 *
318 * This value will be propogated to all child entries.
319 *
320 * @see _majorProtocolVersion
321 * @param (int|NULL) $value The major protocol version to use.
322 * @throws Zend_Gdata_App_InvalidArgumentException
323 */
324 public function setMajorProtocolVersion($value)
325 {
326 parent::setMajorProtocolVersion($value);
327 foreach ($this->entries as $entry) {
328 $entry->setMajorProtocolVersion($value);
329 }
330 }
331
332 /**
333 * Set the minor protocol version that should be used. If set to NULL, no
334 * minor protocol version will be sent to the server. Values < 0 will
335 * cause a Zend_Gdata_App_InvalidArgumentException to be thrown.
336 *
337 * This value will be propogated to all child entries.
338 *
339 * @see _minorProtocolVersion
340 * @param (int|NULL) $value The minor protocol version to use.
341 * @throws Zend_Gdata_App_InvalidArgumentException
342 */
343 public function setMinorProtocolVersion($value)
344 {
345 parent::setMinorProtocolVersion($value);
346 foreach ($this->entries as $entry) {
347 $entry->setMinorProtocolVersion($value);
348 }
349 }
350
351}
Note: See TracBrowser for help on using the repository browser.