ItemBuilder.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. namespace PicoFeed\Syndication;
  3. use DateTime;
  4. use DOMElement;
  5. /**
  6. * Class ItemBuilder
  7. *
  8. * @package PicoFeed\Syndication
  9. * @author Frederic Guillot
  10. */
  11. abstract class ItemBuilder
  12. {
  13. /**
  14. * @var string
  15. */
  16. protected $itemTitle;
  17. /**
  18. * @var string
  19. */
  20. protected $itemId;
  21. /**
  22. * @var string
  23. */
  24. protected $itemSummary;
  25. /**
  26. * @var string
  27. */
  28. protected $authorName;
  29. /**
  30. * @var string
  31. */
  32. protected $authorEmail;
  33. /**
  34. * @var string
  35. */
  36. protected $authorUrl;
  37. /**
  38. * @var DateTime
  39. */
  40. protected $itemPublishedDate;
  41. /**
  42. * @var DateTime
  43. */
  44. protected $itemUpdatedDate;
  45. /**
  46. * @var string
  47. */
  48. protected $itemContent;
  49. /**
  50. * @var string
  51. */
  52. protected $itemUrl;
  53. /**
  54. * @var FeedBuilder
  55. */
  56. protected $feedBuilder;
  57. /**
  58. * Constructor
  59. *
  60. * @param FeedBuilder $feedBuilder
  61. */
  62. public function __construct(FeedBuilder $feedBuilder)
  63. {
  64. $this->feedBuilder = $feedBuilder;
  65. }
  66. /**
  67. * Get new object instance
  68. *
  69. * @access public
  70. * @param FeedBuilder $feedBuilder
  71. * @return static
  72. */
  73. public static function create(FeedBuilder $feedBuilder)
  74. {
  75. return new static($feedBuilder);
  76. }
  77. /**
  78. * Add item title
  79. *
  80. * @access public
  81. * @param string $title
  82. * @return $this
  83. */
  84. public function withTitle($title)
  85. {
  86. $this->itemTitle = $title;
  87. return $this;
  88. }
  89. /**
  90. * Add item id
  91. *
  92. * @access public
  93. * @param string $id
  94. * @return $this
  95. */
  96. public function withId($id)
  97. {
  98. $this->itemId = $id;
  99. return $this;
  100. }
  101. /**
  102. * Add item url
  103. *
  104. * @access public
  105. * @param string $url
  106. * @return $this
  107. */
  108. public function withUrl($url)
  109. {
  110. $this->itemUrl = $url;
  111. return $this;
  112. }
  113. /**
  114. * Add item summary
  115. *
  116. * @access public
  117. * @param string $summary
  118. * @return $this
  119. */
  120. public function withSummary($summary)
  121. {
  122. $this->itemSummary = $summary;
  123. return $this;
  124. }
  125. /**
  126. * Add item content
  127. *
  128. * @access public
  129. * @param string $content
  130. * @return $this
  131. */
  132. public function withContent($content)
  133. {
  134. $this->itemContent = $content;
  135. return $this;
  136. }
  137. /**
  138. * Add item updated date
  139. *
  140. * @access public
  141. * @param DateTime $date
  142. * @return $this
  143. */
  144. public function withUpdatedDate(DateTime $date)
  145. {
  146. $this->itemUpdatedDate = $date;
  147. return $this;
  148. }
  149. /**
  150. * Add item published date
  151. *
  152. * @access public
  153. * @param DateTime $date
  154. * @return $this
  155. */
  156. public function withPublishedDate(DateTime $date)
  157. {
  158. $this->itemPublishedDate = $date;
  159. return $this;
  160. }
  161. /**
  162. * Add item author
  163. *
  164. * @access public
  165. * @param string $name
  166. * @param string $email
  167. * @param string $url
  168. * @return $this
  169. */
  170. public function withAuthor($name, $email = '', $url ='')
  171. {
  172. $this->authorName = $name;
  173. $this->authorEmail = $email;
  174. $this->authorUrl = $url;
  175. return $this;
  176. }
  177. /**
  178. * Build item
  179. *
  180. * @abstract
  181. * @access public
  182. * @return DOMElement
  183. */
  184. abstract public function build();
  185. }