/library/Zend/Feed/Writer/Deleted.php

https://github.com/leerbag/zf2 · PHP · 205 lines · 121 code · 19 blank · 65 comment · 24 complexity · 4148974514a15e360eaa614274e4db27 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_Feed_Writer
  17. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. */
  20. /**
  21. * @namespace
  22. */
  23. namespace Zend\Feed\Writer;
  24. use Zend\Date,
  25. Zend\Uri;
  26. /**
  27. * @category Zend
  28. * @package Zend_Feed_Writer
  29. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Deleted
  33. {
  34. /**
  35. * Internal array containing all data associated with this entry or item.
  36. *
  37. * @var array
  38. */
  39. protected $_data = array();
  40. /**
  41. * Holds the value "atom" or "rss" depending on the feed type set when
  42. * when last exported.
  43. *
  44. * @var string
  45. */
  46. protected $_type = null;
  47. /**
  48. * Set the feed character encoding
  49. *
  50. * @return string|null
  51. */
  52. public function setEncoding($encoding)
  53. {
  54. if (empty($encoding) || !is_string($encoding)) {
  55. throw new Exception('Invalid parameter: parameter must be a non-empty string');
  56. }
  57. $this->_data['encoding'] = $encoding;
  58. }
  59. /**
  60. * Get the feed character encoding
  61. *
  62. * @return string|null
  63. */
  64. public function getEncoding()
  65. {
  66. if (!array_key_exists('encoding', $this->_data)) {
  67. return 'UTF-8';
  68. }
  69. return $this->_data['encoding'];
  70. }
  71. /**
  72. * Unset a specific data point
  73. *
  74. * @param string $name
  75. */
  76. public function remove($name)
  77. {
  78. if (isset($this->_data[$name])) {
  79. unset($this->_data[$name]);
  80. }
  81. }
  82. /**
  83. * Set the current feed type being exported to "rss" or "atom". This allows
  84. * other objects to gracefully choose whether to execute or not, depending
  85. * on their appropriateness for the current type, e.g. renderers.
  86. *
  87. * @param string $type
  88. */
  89. public function setType($type)
  90. {
  91. $this->_type = $type;
  92. }
  93. /**
  94. * Retrieve the current or last feed type exported.
  95. *
  96. * @return string Value will be "rss" or "atom"
  97. */
  98. public function getType()
  99. {
  100. return $this->_type;
  101. }
  102. public function setReference($reference)
  103. {
  104. if (empty($reference) || !is_string($reference)) {
  105. throw new Exception('Invalid parameter: reference must be a non-empty string');
  106. }
  107. $this->_data['reference'] = $reference;
  108. }
  109. public function getReference()
  110. {
  111. if (!array_key_exists('reference', $this->_data)) {
  112. return null;
  113. }
  114. return $this->_data['reference'];
  115. }
  116. public function setWhen($date = null)
  117. {
  118. $zdate = null;
  119. if ($date === null) {
  120. $zdate = new Date\Date;
  121. } elseif (ctype_digit($date) && strlen($date) == 10) {
  122. $zdate = new Date\Date($date, Date\Date::TIMESTAMP);
  123. } elseif ($date instanceof Date\Date) {
  124. $zdate = $date;
  125. } else {
  126. throw new Exception('Invalid Date\Date object or UNIX Timestamp'
  127. . ' passed as parameter');
  128. }
  129. $this->_data['when'] = $zdate;
  130. }
  131. public function getWhen()
  132. {
  133. if (!array_key_exists('when', $this->_data)) {
  134. return null;
  135. }
  136. return $this->_data['when'];
  137. }
  138. public function setBy(array $by)
  139. {
  140. $author = array();
  141. if (!array_key_exists('name', $by)
  142. || empty($by['name'])
  143. || !is_string($by['name'])
  144. ) {
  145. throw new Exception('Invalid parameter: author array must include a'
  146. . ' "name" key with a non-empty string value');
  147. }
  148. $author['name'] = $by['name'];
  149. if (isset($by['email'])) {
  150. if (empty($by['email']) || !is_string($by['email'])) {
  151. throw new Exception('Invalid parameter: "email" array'
  152. . ' value must be a non-empty string');
  153. }
  154. $author['email'] = $by['email'];
  155. }
  156. if (isset($by['uri'])) {
  157. if (empty($by['uri'])
  158. || !is_string($by['uri'])
  159. || !Uri\UriFactory::factory($by['uri'])->isValid()
  160. ) {
  161. throw new Exception('Invalid parameter: "uri" array value must'
  162. . ' be a non-empty string and valid URI/IRI');
  163. }
  164. $author['uri'] = $by['uri'];
  165. }
  166. $this->_data['by'] = $author;
  167. }
  168. public function getBy()
  169. {
  170. if (!array_key_exists('by', $this->_data)) {
  171. return null;
  172. }
  173. return $this->_data['by'];
  174. }
  175. public function setComment($comment)
  176. {
  177. $this->_data['comment'] = $comment;
  178. }
  179. public function getComment()
  180. {
  181. if (!array_key_exists('comment', $this->_data)) {
  182. return null;
  183. }
  184. return $this->_data['comment'];
  185. }
  186. }