6d94997f01d60d7062ae9e2987527f15ff5940f9
[yaffs-website] / vendor / zendframework / zend-feed / src / Writer / Deleted.php
1 <?php
2 /**
3  * Zend Framework (http://framework.zend.com/)
4  *
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
8  */
9
10 namespace Zend\Feed\Writer;
11
12 use DateTime;
13 use Zend\Feed\Uri;
14
15 /**
16 */
17 class Deleted
18 {
19     /**
20      * Internal array containing all data associated with this entry or item.
21      *
22      * @var array
23      */
24     protected $data = [];
25
26     /**
27      * Holds the value "atom" or "rss" depending on the feed type set when
28      * when last exported.
29      *
30      * @var string
31      */
32     protected $type = null;
33
34     /**
35      * Set the feed character encoding
36      *
37      * @param  $encoding
38      * @throws Exception\InvalidArgumentException
39      * @return string|null
40      * @return Deleted
41      */
42     public function setEncoding($encoding)
43     {
44         if (empty($encoding) || ! is_string($encoding)) {
45             throw new Exception\InvalidArgumentException('Invalid parameter: parameter must be a non-empty string');
46         }
47         $this->data['encoding'] = $encoding;
48
49         return $this;
50     }
51
52     /**
53      * Get the feed character encoding
54      *
55      * @return string|null
56      */
57     public function getEncoding()
58     {
59         if (! array_key_exists('encoding', $this->data)) {
60             return 'UTF-8';
61         }
62         return $this->data['encoding'];
63     }
64
65     /**
66      * Unset a specific data point
67      *
68      * @param string $name
69      * @return Deleted
70      */
71     public function remove($name)
72     {
73         if (isset($this->data[$name])) {
74             unset($this->data[$name]);
75         }
76
77         return $this;
78     }
79
80     /**
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.
84      *
85      * @param string $type
86      * @return Deleted
87      */
88     public function setType($type)
89     {
90         $this->type = $type;
91         return $this;
92     }
93
94     /**
95      * Retrieve the current or last feed type exported.
96      *
97      * @return string Value will be "rss" or "atom"
98      */
99     public function getType()
100     {
101         return $this->type;
102     }
103
104     /**
105      * Set reference
106      *
107      * @param $reference
108      * @throws Exception\InvalidArgumentException
109      * @return Deleted
110      */
111     public function setReference($reference)
112     {
113         if (empty($reference) || ! is_string($reference)) {
114             throw new Exception\InvalidArgumentException('Invalid parameter: reference must be a non-empty string');
115         }
116         $this->data['reference'] = $reference;
117
118         return $this;
119     }
120
121     /**
122      * @return string
123      */
124     public function getReference()
125     {
126         if (! array_key_exists('reference', $this->data)) {
127             return;
128         }
129         return $this->data['reference'];
130     }
131
132     /**
133      * Set when
134      *
135      * @param null|string|DateTime $date
136      * @throws Exception\InvalidArgumentException
137      * @return Deleted
138      */
139     public function setWhen($date = null)
140     {
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');
148         }
149         $this->data['when'] = $date;
150
151         return $this;
152     }
153
154     /**
155      * @return DateTime
156      */
157     public function getWhen()
158     {
159         if (! array_key_exists('when', $this->data)) {
160             return;
161         }
162         return $this->data['when'];
163     }
164
165     /**
166      * Set by
167      *
168      * @param array $by
169      * @throws Exception\InvalidArgumentException
170      * @return Deleted
171      */
172     public function setBy(array $by)
173     {
174         $author = [];
175         if (! array_key_exists('name', $by)
176             || empty($by['name'])
177             || ! is_string($by['name'])
178         ) {
179             throw new Exception\InvalidArgumentException('Invalid parameter: author array must include a'
180             . ' "name" key with a non-empty string value');
181         }
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');
187             }
188             $author['email'] = $by['email'];
189         }
190         if (isset($by['uri'])) {
191             if (empty($by['uri'])
192                 || ! is_string($by['uri'])
193                 || ! Uri::factory($by['uri'])->isValid()
194             ) {
195                 throw new Exception\InvalidArgumentException('Invalid parameter: "uri" array value must'
196                  . ' be a non-empty string and valid URI/IRI');
197             }
198             $author['uri'] = $by['uri'];
199         }
200         $this->data['by'] = $author;
201
202         return $this;
203     }
204
205     /**
206      * @return string
207      */
208     public function getBy()
209     {
210         if (! array_key_exists('by', $this->data)) {
211             return;
212         }
213         return $this->data['by'];
214     }
215
216     /**
217      * @param string $comment
218      * @return Deleted
219      */
220     public function setComment($comment)
221     {
222         $this->data['comment'] = $comment;
223         return $this;
224     }
225
226     /**
227      * @return string
228      */
229     public function getComment()
230     {
231         if (! array_key_exists('comment', $this->data)) {
232             return;
233         }
234         return $this->data['comment'];
235     }
236 }