File indexing completed on 2025-03-02 05:29:26
0001 <?php 0002 0003 /** 0004 * Zend Framework 0005 * 0006 * LICENSE 0007 * 0008 * This source file is subject to the new BSD license that is bundled 0009 * with this package in the file LICENSE.txt. 0010 * It is also available through the world-wide-web at this URL: 0011 * http://framework.zend.com/license/new-bsd 0012 * If you did not receive a copy of the license and are unable to 0013 * obtain it through the world-wide-web, please send an email 0014 * to license@zend.com so we can send you a copy immediately. 0015 * 0016 * @category Zend 0017 * @package Zend_Gdata 0018 * @subpackage App 0019 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0020 * @license http://framework.zend.com/license/new-bsd New BSD License 0021 * @version $Id$ 0022 */ 0023 0024 /** 0025 * @see Zend_Gdata_App_Entry 0026 */ 0027 // require_once 'Zend/Gdata/App/Entry.php'; 0028 0029 /** 0030 * @see Zend_Gdata_App_FeedSourceParent 0031 */ 0032 // require_once 'Zend/Gdata/App/FeedSourceParent.php'; 0033 0034 /** 0035 * Atom feed class 0036 * 0037 * @category Zend 0038 * @package Zend_Gdata 0039 * @subpackage App 0040 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0041 * @license http://framework.zend.com/license/new-bsd New BSD License 0042 */ 0043 class Zend_Gdata_App_Feed extends Zend_Gdata_App_FeedSourceParent 0044 implements Iterator, ArrayAccess, Countable 0045 { 0046 0047 /** 0048 * The root xml element of this data element 0049 * 0050 * @var string 0051 */ 0052 protected $_rootElement = 'feed'; 0053 0054 /** 0055 * Cache of feed entries. 0056 * 0057 * @var array 0058 */ 0059 protected $_entry = array(); 0060 0061 /** 0062 * Current location in $_entry array 0063 * 0064 * @var int 0065 */ 0066 protected $_entryIndex = 0; 0067 0068 /** 0069 * Make accessing some individual elements of the feed easier. 0070 * 0071 * Special accessors 'entry' and 'entries' are provided so that if 0072 * you wish to iterate over an Atom feed's entries, you can do so 0073 * using foreach ($feed->entries as $entry) or foreach 0074 * ($feed->entry as $entry). 0075 * 0076 * @param string $var The property to get. 0077 * @return mixed 0078 */ 0079 public function __get($var) 0080 { 0081 switch ($var) { 0082 case 'entries': 0083 return $this; 0084 default: 0085 return parent::__get($var); 0086 } 0087 } 0088 0089 /** 0090 * Retrieves the DOM model representing this object and all children 0091 * 0092 * @param DOMDocument $doc 0093 * @return DOMElement 0094 */ 0095 public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null) 0096 { 0097 $element = parent::getDOM($doc, $majorVersion, $minorVersion); 0098 foreach ($this->_entry as $entry) { 0099 $element->appendChild($entry->getDOM($element->ownerDocument)); 0100 } 0101 return $element; 0102 } 0103 0104 /** 0105 * Creates individual Entry objects of the appropriate type and 0106 * stores them in the $_entry array based upon DOM data. 0107 * 0108 * @param DOMNode $child The DOMNode to process 0109 */ 0110 protected function takeChildFromDOM($child) 0111 { 0112 $absoluteNodeName = $child->namespaceURI . ':' . $child->localName; 0113 switch ($absoluteNodeName) { 0114 case $this->lookupNamespace('atom') . ':' . 'entry': 0115 $newEntry = new $this->_entryClassName($child); 0116 $newEntry->setHttpClient($this->getHttpClient()); 0117 $newEntry->setMajorProtocolVersion($this->getMajorProtocolVersion()); 0118 $newEntry->setMinorProtocolVersion($this->getMinorProtocolVersion()); 0119 $this->_entry[] = $newEntry; 0120 break; 0121 default: 0122 parent::takeChildFromDOM($child); 0123 break; 0124 } 0125 } 0126 0127 /** 0128 * Get the number of entries in this feed object. 0129 * 0130 * @return integer Entry count. 0131 */ 0132 public function count() 0133 { 0134 return count($this->_entry); 0135 } 0136 0137 /** 0138 * Required by the Iterator interface. 0139 * 0140 * @return void 0141 */ 0142 public function rewind() 0143 { 0144 $this->_entryIndex = 0; 0145 } 0146 0147 /** 0148 * Required by the Iterator interface. 0149 * 0150 * @return mixed The current row, or null if no rows. 0151 */ 0152 public function current() 0153 { 0154 return $this->_entry[$this->_entryIndex]; 0155 } 0156 0157 /** 0158 * Required by the Iterator interface. 0159 * 0160 * @return mixed The current row number (starts at 0), or NULL if no rows 0161 */ 0162 public function key() 0163 { 0164 return $this->_entryIndex; 0165 } 0166 0167 /** 0168 * Required by the Iterator interface. 0169 * 0170 * @return mixed The next row, or null if no more rows. 0171 */ 0172 public function next() 0173 { 0174 ++$this->_entryIndex; 0175 } 0176 0177 /** 0178 * Required by the Iterator interface. 0179 * 0180 * @return boolean Whether the iteration is valid 0181 */ 0182 public function valid() 0183 { 0184 return 0 <= $this->_entryIndex && $this->_entryIndex < $this->count(); 0185 } 0186 0187 /** 0188 * Gets the array of atom:entry elements contained within this 0189 * atom:feed representation 0190 * 0191 * @return array Zend_Gdata_App_Entry array 0192 */ 0193 public function getEntry() 0194 { 0195 return $this->_entry; 0196 } 0197 0198 /** 0199 * Sets the array of atom:entry elements contained within this 0200 * atom:feed representation 0201 * 0202 * @param array $value The array of Zend_Gdata_App_Entry elements 0203 * @return Zend_Gdata_App_Feed Provides a fluent interface 0204 */ 0205 public function setEntry($value) 0206 { 0207 $this->_entry = $value; 0208 return $this; 0209 } 0210 0211 /** 0212 * Adds an entry representation to the array of entries 0213 * contained within this feed 0214 * 0215 * @param Zend_Gdata_App_Entry An individual entry to add. 0216 * @return Zend_Gdata_App_Feed Provides a fluent interface 0217 */ 0218 public function addEntry($value) 0219 { 0220 $this->_entry[] = $value; 0221 return $this; 0222 } 0223 0224 /** 0225 * Required by the ArrayAccess interface 0226 * 0227 * @param int $key The index to set 0228 * @param Zend_Gdata_App_Entry $value The value to set 0229 * @return void 0230 */ 0231 public function offsetSet($key, $value) 0232 { 0233 $this->_entry[$key] = $value; 0234 } 0235 0236 /** 0237 * Required by the ArrayAccess interface 0238 * 0239 * @param int $key The index to get 0240 * @param Zend_Gdata_App_Entry $value The value to set 0241 */ 0242 public function offsetGet($key) 0243 { 0244 if (array_key_exists($key, $this->_entry)) { 0245 return $this->_entry[$key]; 0246 } 0247 } 0248 0249 /** 0250 * Required by the ArrayAccess interface 0251 * 0252 * @param int $key The index to set 0253 * @param Zend_Gdata_App_Entry $value The value to set 0254 */ 0255 public function offsetUnset($key) 0256 { 0257 if (array_key_exists($key, $this->_entry)) { 0258 unset($this->_entry[$key]); 0259 } 0260 } 0261 0262 /** 0263 * Required by the ArrayAccess interface 0264 * 0265 * @param int $key The index to check for existence 0266 * @return boolean 0267 */ 0268 public function offsetExists($key) 0269 { 0270 return (array_key_exists($key, $this->_entry)); 0271 } 0272 0273 /** 0274 * Retrieve the next set of results from this feed. 0275 * 0276 * @throws Zend_Gdata_App_Exception 0277 * @return mixed|null Returns the next set of results as a feed of the same 0278 * class as this feed, or null if no results exist. 0279 */ 0280 public function getNextFeed() 0281 { 0282 $nextLink = $this->getNextLink(); 0283 if (!$nextLink) { 0284 // require_once 'Zend/Gdata/App/HttpException.php'; 0285 throw new Zend_Gdata_App_Exception('No link to next set ' . 0286 'of results found.'); 0287 } 0288 $nextLinkHref = $nextLink->getHref(); 0289 $service = new Zend_Gdata_App($this->getHttpClient()); 0290 0291 return $service->getFeed($nextLinkHref, get_class($this)); 0292 } 0293 0294 /** 0295 * Retrieve the previous set of results from this feed. 0296 * 0297 * @throws Zend_Gdata_App_Exception 0298 * @return mixed|null Returns the previous set of results as a feed of 0299 * the same class as this feed, or null if no results exist. 0300 */ 0301 public function getPreviousFeed() 0302 { 0303 $previousLink = $this->getPreviousLink(); 0304 if (!$previousLink) { 0305 // require_once 'Zend/Gdata/App/HttpException.php'; 0306 throw new Zend_Gdata_App_Exception('No link to previous set ' . 0307 'of results found.'); 0308 } 0309 $previousLinkHref = $previousLink->getHref(); 0310 $service = new Zend_Gdata_App($this->getHttpClient()); 0311 0312 return $service->getFeed($previousLinkHref, get_class($this)); 0313 } 0314 0315 /** 0316 * Set the major protocol version that should be used. Values < 1 will 0317 * cause a Zend_Gdata_App_InvalidArgumentException to be thrown. 0318 * 0319 * This value will be propogated to all child entries. 0320 * 0321 * @see _majorProtocolVersion 0322 * @param (int|NULL) $value The major protocol version to use. 0323 * @throws Zend_Gdata_App_InvalidArgumentException 0324 */ 0325 public function setMajorProtocolVersion($value) 0326 { 0327 parent::setMajorProtocolVersion($value); 0328 foreach ($this->entries as $entry) { 0329 $entry->setMajorProtocolVersion($value); 0330 } 0331 } 0332 0333 /** 0334 * Set the minor protocol version that should be used. If set to NULL, no 0335 * minor protocol version will be sent to the server. Values < 0 will 0336 * cause a Zend_Gdata_App_InvalidArgumentException to be thrown. 0337 * 0338 * This value will be propogated to all child entries. 0339 * 0340 * @see _minorProtocolVersion 0341 * @param (int|NULL) $value The minor protocol version to use. 0342 * @throws Zend_Gdata_App_InvalidArgumentException 0343 */ 0344 public function setMinorProtocolVersion($value) 0345 { 0346 parent::setMinorProtocolVersion($value); 0347 foreach ($this->entries as $entry) { 0348 $entry->setMinorProtocolVersion($value); 0349 } 0350 } 0351 0352 }