PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/tine20/library/Zend/Gdata/App/Feed.php

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