3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Feed\Writer;
20 * Internal array containing all data associated with this entry or item.
27 * Holds the value "atom" or "rss" depending on the feed type set when
32 protected $type = null;
35 * Set the feed character encoding
38 * @throws Exception\InvalidArgumentException
42 public function setEncoding($encoding)
44 if (empty($encoding) || ! is_string($encoding)) {
45 throw new Exception\InvalidArgumentException('Invalid parameter: parameter must be a non-empty string');
47 $this->data['encoding'] = $encoding;
53 * Get the feed character encoding
57 public function getEncoding()
59 if (! array_key_exists('encoding', $this->data)) {
62 return $this->data['encoding'];
66 * Unset a specific data point
71 public function remove($name)
73 if (isset($this->data[$name])) {
74 unset($this->data[$name]);
81 * Set the current feed type being exported to "rss" or "atom". This allows
82 * other objects to gracefully choose whether to execute or not, depending
83 * on their appropriateness for the current type, e.g. renderers.
88 public function setType($type)
95 * Retrieve the current or last feed type exported.
97 * @return string Value will be "rss" or "atom"
99 public function getType()
108 * @throws Exception\InvalidArgumentException
111 public function setReference($reference)
113 if (empty($reference) || ! is_string($reference)) {
114 throw new Exception\InvalidArgumentException('Invalid parameter: reference must be a non-empty string');
116 $this->data['reference'] = $reference;
124 public function getReference()
126 if (! array_key_exists('reference', $this->data)) {
129 return $this->data['reference'];
135 * @param null|string|DateTime $date
136 * @throws Exception\InvalidArgumentException
139 public function setWhen($date = null)
141 if ($date === null) {
142 $date = new DateTime();
143 } elseif (is_int($date)) {
144 $date = new DateTime('@' . $date);
145 } elseif (! $date instanceof DateTime) {
146 throw new Exception\InvalidArgumentException('Invalid DateTime object or UNIX Timestamp'
147 . ' passed as parameter');
149 $this->data['when'] = $date;
157 public function getWhen()
159 if (! array_key_exists('when', $this->data)) {
162 return $this->data['when'];
169 * @throws Exception\InvalidArgumentException
172 public function setBy(array $by)
175 if (! array_key_exists('name', $by)
176 || empty($by['name'])
177 || ! is_string($by['name'])
179 throw new Exception\InvalidArgumentException('Invalid parameter: author array must include a'
180 . ' "name" key with a non-empty string value');
182 $author['name'] = $by['name'];
183 if (isset($by['email'])) {
184 if (empty($by['email']) || ! is_string($by['email'])) {
185 throw new Exception\InvalidArgumentException('Invalid parameter: "email" array'
186 . ' value must be a non-empty string');
188 $author['email'] = $by['email'];
190 if (isset($by['uri'])) {
191 if (empty($by['uri'])
192 || ! is_string($by['uri'])
193 || ! Uri::factory($by['uri'])->isValid()
195 throw new Exception\InvalidArgumentException('Invalid parameter: "uri" array value must'
196 . ' be a non-empty string and valid URI/IRI');
198 $author['uri'] = $by['uri'];
200 $this->data['by'] = $author;
208 public function getBy()
210 if (! array_key_exists('by', $this->data)) {
213 return $this->data['by'];
217 * @param string $comment
220 public function setComment($comment)
222 $this->data['comment'] = $comment;
229 public function getComment()
231 if (! array_key_exists('comment', $this->data)) {
234 return $this->data['comment'];