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\Extension\ITunes
;
13 use Zend\Feed\Writer\Extension
;
14 use Zend\Stdlib\StringUtils
;
15 use Zend\Stdlib\StringWrapper\StringWrapperInterface
;
22 * Array of Feed data for rendering by Extension's renderers
26 protected $data = array();
29 * Encoding of all text values
33 protected $encoding = 'UTF-8';
36 * The used string wrapper supporting encoding
38 * @var StringWrapperInterface
40 protected $stringWrapper;
42 public function __construct()
44 $this->stringWrapper
= StringUtils
::getWrapper($this->encoding
);
53 public function setEncoding($enc)
55 $this->stringWrapper
= StringUtils
::getWrapper($enc);
56 $this->encoding
= $enc;
65 public function getEncoding()
67 return $this->encoding
;
71 * Set a block value of "yes" or "no". You may also set an empty string.
75 * @throws Writer\Exception\InvalidArgumentException
77 public function setItunesBlock($value)
79 if (!ctype_alpha($value) && strlen($value) > 0) {
80 throw new Writer\Exception\
InvalidArgumentException('invalid parameter: "block" may only'
81 . ' contain alphabetic characters');
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');
88 $this->data
['block'] = $value;
92 * Add authors to itunes entry
94 * @param array $values
97 public function addItunesAuthors(array $values)
99 foreach ($values as $value) {
100 $this->addItunesAuthor($value);
106 * Add author to itunes entry
108 * @param string $value
110 * @throws Writer\Exception\InvalidArgumentException
112 public function addItunesAuthor($value)
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');
118 if (!isset($this->data
['authors'])) {
119 $this->data
['authors'] = array();
121 $this->data
['authors'][] = $value;
130 * @throws Writer\Exception\InvalidArgumentException
132 public function setItunesDuration($value)
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)
139 throw new Writer\Exception\
InvalidArgumentException('invalid parameter: "duration" may only'
140 . ' be of a specified [[HH:]MM:]SS format');
142 $this->data
['duration'] = $value;
147 * Set "explicit" flag
151 * @throws Writer\Exception\InvalidArgumentException
153 public function setItunesExplicit($value)
155 if (!in_array($value, array('yes', 'no', 'clean'))) {
156 throw new Writer\Exception\
InvalidArgumentException('invalid parameter: "explicit" may only'
157 . ' be one of "yes", "no" or "clean"');
159 $this->data
['explicit'] = $value;
166 * @param array $value
168 * @throws Writer\Exception\InvalidArgumentException
170 public function setItunesKeywords(array $value)
172 if (count($value) > 12) {
173 throw new Writer\Exception\
InvalidArgumentException('invalid parameter: "keywords" may only'
174 . ' contain a maximum of 12 terms');
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'
183 $this->data
['keywords'] = $value;
190 * @param string $value
192 * @throws Writer\Exception\InvalidArgumentException
194 public function setItunesSubtitle($value)
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');
200 $this->data
['subtitle'] = $value;
207 * @param string $value
209 * @throws Writer\Exception\InvalidArgumentException
211 public function setItunesSummary($value)
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');
217 $this->data
['summary'] = $value;
222 * Overloading to itunes specific setters
224 * @param string $method
225 * @param array $params
226 * @throws Writer\Exception\BadMethodCallException
229 public function __call($method, array $params)
231 $point = lcfirst(substr($method, 9));
232 if (!method_exists($this, 'setItunes' . ucfirst($point))
233 && !method_exists($this, 'addItunes' . ucfirst($point))
235 throw new Writer\Exception\
BadMethodCallException(
236 'invalid method: ' . $method
239 if (!array_key_exists($point, $this->data
)
240 ||
empty($this->data
[$point])
244 return $this->data
[$point];