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\Stdlib\StringUtils;
14 use Zend\Stdlib\StringWrapper\StringWrapperInterface;
21 * Array of Feed data for rendering by Extension's renderers
28 * Encoding of all text values
32 protected $encoding = 'UTF-8';
35 * The used string wrapper supporting encoding
37 * @var StringWrapperInterface
39 protected $stringWrapper;
41 public function __construct()
43 $this->stringWrapper = StringUtils::getWrapper($this->encoding);
52 public function setEncoding($enc)
54 $this->stringWrapper = StringUtils::getWrapper($enc);
55 $this->encoding = $enc;
64 public function getEncoding()
66 return $this->encoding;
70 * Set a block value of "yes" or "no". You may also set an empty string.
74 * @throws Writer\Exception\InvalidArgumentException
76 public function setItunesBlock($value)
78 if (! ctype_alpha($value) && strlen($value) > 0) {
79 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only'
80 . ' contain alphabetic characters');
83 if ($this->stringWrapper->strlen($value) > 255) {
84 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only'
85 . ' contain a maximum of 255 characters');
87 $this->data['block'] = $value;
91 * Add authors to itunes entry
93 * @param array $values
96 public function addItunesAuthors(array $values)
98 foreach ($values as $value) {
99 $this->addItunesAuthor($value);
105 * Add author to itunes entry
107 * @param string $value
109 * @throws Writer\Exception\InvalidArgumentException
111 public function addItunesAuthor($value)
113 if ($this->stringWrapper->strlen($value) > 255) {
114 throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "author" may only'
115 . ' contain a maximum of 255 characters each');
117 if (! isset($this->data['authors'])) {
118 $this->data['authors'] = [];
120 $this->data['authors'][] = $value;
129 * @throws Writer\Exception\InvalidArgumentException
131 public function setItunesDuration($value)
133 $value = (string) $value;
134 if (! ctype_digit($value)
135 && ! preg_match("/^\d+:[0-5]{1}[0-9]{1}$/", $value)
136 && ! preg_match("/^\d+:[0-5]{1}[0-9]{1}:[0-5]{1}[0-9]{1}$/", $value)
138 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "duration" may only'
139 . ' be of a specified [[HH:]MM:]SS format');
141 $this->data['duration'] = $value;
146 * Set "explicit" flag
150 * @throws Writer\Exception\InvalidArgumentException
152 public function setItunesExplicit($value)
154 if (! in_array($value, ['yes', 'no', 'clean'])) {
155 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "explicit" may only'
156 . ' be one of "yes", "no" or "clean"');
158 $this->data['explicit'] = $value;
165 * @param array $value
167 * @throws Writer\Exception\InvalidArgumentException
169 public function setItunesKeywords(array $value)
171 if (count($value) > 12) {
172 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "keywords" may only'
173 . ' contain a maximum of 12 terms');
176 $concat = implode(',', $value);
177 if ($this->stringWrapper->strlen($concat) > 255) {
178 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "keywords" may only'
179 . ' have a concatenated length of 255 chars where terms are delimited'
182 $this->data['keywords'] = $value;
189 * @param string $value
191 * @throws Writer\Exception\InvalidArgumentException
193 public function setItunesSubtitle($value)
195 if ($this->stringWrapper->strlen($value) > 255) {
196 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "subtitle" may only'
197 . ' contain a maximum of 255 characters');
199 $this->data['subtitle'] = $value;
206 * @param string $value
208 * @throws Writer\Exception\InvalidArgumentException
210 public function setItunesSummary($value)
212 if ($this->stringWrapper->strlen($value) > 4000) {
213 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "summary" may only'
214 . ' contain a maximum of 4000 characters');
216 $this->data['summary'] = $value;
221 * Overloading to itunes specific setters
223 * @param string $method
224 * @param array $params
225 * @throws Writer\Exception\BadMethodCallException
228 public function __call($method, array $params)
230 $point = lcfirst(substr($method, 9));
231 if (! method_exists($this, 'setItunes' . ucfirst($point))
232 && ! method_exists($this, 'addItunes' . ucfirst($point))
234 throw new Writer\Exception\BadMethodCallException(
235 'invalid method: ' . $method
238 if (! array_key_exists($point, $this->data)
239 || empty($this->data[$point])
243 return $this->data[$point];