Feed.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <?php
  2. namespace PicoFeed\Parser;
  3. /**
  4. * Feed.
  5. *
  6. * @package PicoFeed\Parser
  7. * @author Frederic Guillot
  8. */
  9. class Feed
  10. {
  11. /**
  12. * Feed items.
  13. *
  14. * @var Item[]
  15. */
  16. public $items = array();
  17. /**
  18. * Feed id.
  19. *
  20. * @var string
  21. */
  22. public $id = '';
  23. /**
  24. * Feed title.
  25. *
  26. * @var string
  27. */
  28. public $title = '';
  29. /**
  30. * Feed description.
  31. *
  32. * @var string
  33. */
  34. public $description = '';
  35. /**
  36. * Feed url.
  37. *
  38. * @var string
  39. */
  40. public $feedUrl = '';
  41. /**
  42. * Site url.
  43. *
  44. * @var string
  45. */
  46. public $siteUrl = '';
  47. /**
  48. * Feed date.
  49. *
  50. * @var \DateTime
  51. */
  52. public $date = null;
  53. /**
  54. * Feed language.
  55. *
  56. * @var string
  57. */
  58. public $language = '';
  59. /**
  60. * Feed logo URL.
  61. *
  62. * @var string
  63. */
  64. public $logo = '';
  65. /**
  66. * Feed icon URL.
  67. *
  68. * @var string
  69. */
  70. public $icon = '';
  71. /**
  72. * Return feed information.
  73. */
  74. public function __toString()
  75. {
  76. $output = '';
  77. foreach (array('id', 'title', 'feedUrl', 'siteUrl', 'language', 'description', 'logo') as $property) {
  78. $output .= 'Feed::'.$property.' = '.$this->$property.PHP_EOL;
  79. }
  80. $output .= 'Feed::date = '.$this->date->format(DATE_RFC822).PHP_EOL;
  81. $output .= 'Feed::isRTL() = '.($this->isRTL() ? 'true' : 'false').PHP_EOL;
  82. $output .= 'Feed::items = '.count($this->items).' items'.PHP_EOL;
  83. foreach ($this->items as $item) {
  84. $output .= '----'.PHP_EOL;
  85. $output .= $item;
  86. }
  87. return $output;
  88. }
  89. /**
  90. * Get title.
  91. */
  92. public function getTitle()
  93. {
  94. return $this->title;
  95. }
  96. /**
  97. * Get description.
  98. */
  99. public function getDescription()
  100. {
  101. return $this->description;
  102. }
  103. /**
  104. * Get the logo url.
  105. */
  106. public function getLogo()
  107. {
  108. return $this->logo;
  109. }
  110. /**
  111. * Get the icon url.
  112. */
  113. public function getIcon()
  114. {
  115. return $this->icon;
  116. }
  117. /**
  118. * Get feed url.
  119. */
  120. public function getFeedUrl()
  121. {
  122. return $this->feedUrl;
  123. }
  124. /**
  125. * Get site url.
  126. */
  127. public function getSiteUrl()
  128. {
  129. return $this->siteUrl;
  130. }
  131. /**
  132. * Get date.
  133. */
  134. public function getDate()
  135. {
  136. return $this->date;
  137. }
  138. /**
  139. * Get language.
  140. */
  141. public function getLanguage()
  142. {
  143. return $this->language;
  144. }
  145. /**
  146. * Get id.
  147. */
  148. public function getId()
  149. {
  150. return $this->id;
  151. }
  152. /**
  153. * Get feed items.
  154. */
  155. public function getItems()
  156. {
  157. return $this->items;
  158. }
  159. /**
  160. * Return true if the feed is "Right to Left".
  161. *
  162. * @return bool
  163. */
  164. public function isRTL()
  165. {
  166. return Parser::isLanguageRTL($this->language);
  167. }
  168. /**
  169. * Set feed items.
  170. *
  171. * @param Item[] $items
  172. * @return Feed
  173. */
  174. public function setItems(array $items)
  175. {
  176. $this->items = $items;
  177. return $this;
  178. }
  179. /**
  180. * Set feed id.
  181. *
  182. * @param string $id
  183. * @return Feed
  184. */
  185. public function setId($id)
  186. {
  187. $this->id = $id;
  188. return $this;
  189. }
  190. /**
  191. * Set feed title.
  192. *
  193. * @param string $title
  194. * @return Feed
  195. */
  196. public function setTitle($title)
  197. {
  198. $this->title = $title;
  199. return $this;
  200. }
  201. /**
  202. * Set feed description.
  203. *
  204. * @param string $description
  205. * @return Feed
  206. */
  207. public function setDescription($description)
  208. {
  209. $this->description = $description;
  210. return $this;
  211. }
  212. /**
  213. * Set feed url.
  214. *
  215. * @param string $feedUrl
  216. * @return Feed
  217. */
  218. public function setFeedUrl($feedUrl)
  219. {
  220. $this->feedUrl = $feedUrl;
  221. return $this;
  222. }
  223. /**
  224. * Set feed website url.
  225. *
  226. * @param string $siteUrl
  227. * @return Feed
  228. */
  229. public function setSiteUrl($siteUrl)
  230. {
  231. $this->siteUrl = $siteUrl;
  232. return $this;
  233. }
  234. /**
  235. * Set feed date.
  236. *
  237. * @param \DateTime $date
  238. * @return Feed
  239. */
  240. public function setDate($date)
  241. {
  242. $this->date = $date;
  243. return $this;
  244. }
  245. /**
  246. * Set feed language.
  247. *
  248. * @param string $language
  249. * @return Feed
  250. */
  251. public function setLanguage($language)
  252. {
  253. $this->language = $language;
  254. return $this;
  255. }
  256. /**
  257. * Set feed logo.
  258. *
  259. * @param string $logo
  260. * @return Feed
  261. */
  262. public function setLogo($logo)
  263. {
  264. $this->logo = $logo;
  265. return $this;
  266. }
  267. /**
  268. * Set feed icon.
  269. *
  270. * @param string $icon
  271. * @return Feed
  272. */
  273. public function setIcon($icon)
  274. {
  275. $this->icon = $icon;
  276. return $this;
  277. }
  278. }