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