comparison vendor/zendframework/zend-feed/src/Writer/Extension/ITunes/Entry.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children 5311817fb629
comparison
equal deleted inserted replaced
-1:000000000000 0:c75dbcec494b
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\Extension\ITunes;
11
12 use Zend\Feed\Writer;
13 use Zend\Feed\Writer\Extension;
14 use Zend\Stdlib\StringUtils;
15 use Zend\Stdlib\StringWrapper\StringWrapperInterface;
16
17 /**
18 */
19 class Entry
20 {
21 /**
22 * Array of Feed data for rendering by Extension's renderers
23 *
24 * @var array
25 */
26 protected $data = [];
27
28 /**
29 * Encoding of all text values
30 *
31 * @var string
32 */
33 protected $encoding = 'UTF-8';
34
35 /**
36 * The used string wrapper supporting encoding
37 *
38 * @var StringWrapperInterface
39 */
40 protected $stringWrapper;
41
42 public function __construct()
43 {
44 $this->stringWrapper = StringUtils::getWrapper($this->encoding);
45 }
46
47 /**
48 * Set feed encoding
49 *
50 * @param string $enc
51 * @return Entry
52 */
53 public function setEncoding($enc)
54 {
55 $this->stringWrapper = StringUtils::getWrapper($enc);
56 $this->encoding = $enc;
57 return $this;
58 }
59
60 /**
61 * Get feed encoding
62 *
63 * @return string
64 */
65 public function getEncoding()
66 {
67 return $this->encoding;
68 }
69
70 /**
71 * Set a block value of "yes" or "no". You may also set an empty string.
72 *
73 * @param string
74 * @return Entry
75 * @throws Writer\Exception\InvalidArgumentException
76 */
77 public function setItunesBlock($value)
78 {
79 if (!ctype_alpha($value) && strlen($value) > 0) {
80 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only'
81 . ' contain alphabetic characters');
82 }
83
84 if ($this->stringWrapper->strlen($value) > 255) {
85 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only'
86 . ' contain a maximum of 255 characters');
87 }
88 $this->data['block'] = $value;
89 }
90
91 /**
92 * Add authors to itunes entry
93 *
94 * @param array $values
95 * @return Entry
96 */
97 public function addItunesAuthors(array $values)
98 {
99 foreach ($values as $value) {
100 $this->addItunesAuthor($value);
101 }
102 return $this;
103 }
104
105 /**
106 * Add author to itunes entry
107 *
108 * @param string $value
109 * @return Entry
110 * @throws Writer\Exception\InvalidArgumentException
111 */
112 public function addItunesAuthor($value)
113 {
114 if ($this->stringWrapper->strlen($value) > 255) {
115 throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "author" may only'
116 . ' contain a maximum of 255 characters each');
117 }
118 if (!isset($this->data['authors'])) {
119 $this->data['authors'] = [];
120 }
121 $this->data['authors'][] = $value;
122 return $this;
123 }
124
125 /**
126 * Set duration
127 *
128 * @param int $value
129 * @return Entry
130 * @throws Writer\Exception\InvalidArgumentException
131 */
132 public function setItunesDuration($value)
133 {
134 $value = (string) $value;
135 if (!ctype_digit($value)
136 && !preg_match("/^\d+:[0-5]{1}[0-9]{1}$/", $value)
137 && !preg_match("/^\d+:[0-5]{1}[0-9]{1}:[0-5]{1}[0-9]{1}$/", $value)
138 ) {
139 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "duration" may only'
140 . ' be of a specified [[HH:]MM:]SS format');
141 }
142 $this->data['duration'] = $value;
143 return $this;
144 }
145
146 /**
147 * Set "explicit" flag
148 *
149 * @param bool $value
150 * @return Entry
151 * @throws Writer\Exception\InvalidArgumentException
152 */
153 public function setItunesExplicit($value)
154 {
155 if (!in_array($value, ['yes', 'no', 'clean'])) {
156 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "explicit" may only'
157 . ' be one of "yes", "no" or "clean"');
158 }
159 $this->data['explicit'] = $value;
160 return $this;
161 }
162
163 /**
164 * Set keywords
165 *
166 * @param array $value
167 * @return Entry
168 * @throws Writer\Exception\InvalidArgumentException
169 */
170 public function setItunesKeywords(array $value)
171 {
172 if (count($value) > 12) {
173 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "keywords" may only'
174 . ' contain a maximum of 12 terms');
175 }
176
177 $concat = implode(',', $value);
178 if ($this->stringWrapper->strlen($concat) > 255) {
179 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "keywords" may only'
180 . ' have a concatenated length of 255 chars where terms are delimited'
181 . ' by a comma');
182 }
183 $this->data['keywords'] = $value;
184 return $this;
185 }
186
187 /**
188 * Set subtitle
189 *
190 * @param string $value
191 * @return Entry
192 * @throws Writer\Exception\InvalidArgumentException
193 */
194 public function setItunesSubtitle($value)
195 {
196 if ($this->stringWrapper->strlen($value) > 255) {
197 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "subtitle" may only'
198 . ' contain a maximum of 255 characters');
199 }
200 $this->data['subtitle'] = $value;
201 return $this;
202 }
203
204 /**
205 * Set summary
206 *
207 * @param string $value
208 * @return Entry
209 * @throws Writer\Exception\InvalidArgumentException
210 */
211 public function setItunesSummary($value)
212 {
213 if ($this->stringWrapper->strlen($value) > 4000) {
214 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "summary" may only'
215 . ' contain a maximum of 4000 characters');
216 }
217 $this->data['summary'] = $value;
218 return $this;
219 }
220
221 /**
222 * Overloading to itunes specific setters
223 *
224 * @param string $method
225 * @param array $params
226 * @throws Writer\Exception\BadMethodCallException
227 * @return mixed
228 */
229 public function __call($method, array $params)
230 {
231 $point = lcfirst(substr($method, 9));
232 if (!method_exists($this, 'setItunes' . ucfirst($point))
233 && !method_exists($this, 'addItunes' . ucfirst($point))
234 ) {
235 throw new Writer\Exception\BadMethodCallException(
236 'invalid method: ' . $method
237 );
238 }
239 if (!array_key_exists($point, $this->data)
240 || empty($this->data[$point])
241 ) {
242 return;
243 }
244 return $this->data[$point];
245 }
246 }