Mercurial > hg > isophonics-drupal-site
comparison vendor/zendframework/zend-feed/src/Writer/Extension/GooglePlayPodcast/Entry.php @ 16:c2387f117808
Routine composer update
author | Chris Cannam |
---|---|
date | Tue, 10 Jul 2018 15:07:59 +0100 |
parents | |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
15:e200cb7efeb3 | 16:c2387f117808 |
---|---|
1 <?php | |
2 /** | |
3 * @see https://github.com/zendframework/zend-feed for the canonical source repository | |
4 * @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com) | |
5 * @license https://github.com/zendframework/zend-feed/blob/master/LICENSE.md New BSD License | |
6 */ | |
7 | |
8 namespace Zend\Feed\Writer\Extension\GooglePlayPodcast; | |
9 | |
10 use Zend\Feed\Uri; | |
11 use Zend\Feed\Writer; | |
12 use Zend\Stdlib\StringUtils; | |
13 use Zend\Stdlib\StringWrapper\StringWrapperInterface; | |
14 | |
15 class Entry | |
16 { | |
17 /** | |
18 * Array of Feed data for rendering by Extension's renderers | |
19 * | |
20 * @var array | |
21 */ | |
22 protected $data = []; | |
23 | |
24 /** | |
25 * Encoding of all text values | |
26 * | |
27 * @var string | |
28 */ | |
29 protected $encoding = 'UTF-8'; | |
30 | |
31 /** | |
32 * The used string wrapper supporting encoding | |
33 * | |
34 * @var StringWrapperInterface | |
35 */ | |
36 protected $stringWrapper; | |
37 | |
38 public function __construct() | |
39 { | |
40 $this->stringWrapper = StringUtils::getWrapper($this->encoding); | |
41 } | |
42 | |
43 /** | |
44 * Set feed encoding | |
45 * | |
46 * @param string $enc | |
47 * @return Entry | |
48 */ | |
49 public function setEncoding($enc) | |
50 { | |
51 $this->stringWrapper = StringUtils::getWrapper($enc); | |
52 $this->encoding = $enc; | |
53 return $this; | |
54 } | |
55 | |
56 /** | |
57 * Get feed encoding | |
58 * | |
59 * @return string | |
60 */ | |
61 public function getEncoding() | |
62 { | |
63 return $this->encoding; | |
64 } | |
65 | |
66 /** | |
67 * Set a block value of "yes" or "no". You may also set an empty string. | |
68 * | |
69 * @param string | |
70 * @return Entry | |
71 * @throws Writer\Exception\InvalidArgumentException | |
72 */ | |
73 public function setPlayPodcastBlock($value) | |
74 { | |
75 if (! ctype_alpha($value) && strlen($value) > 0) { | |
76 throw new Writer\Exception\InvalidArgumentException( | |
77 'invalid parameter: "block" may only contain alphabetic characters' | |
78 ); | |
79 } | |
80 | |
81 if ($this->stringWrapper->strlen($value) > 255) { | |
82 throw new Writer\Exception\InvalidArgumentException( | |
83 'invalid parameter: "block" may only contain a maximum of 255 characters' | |
84 ); | |
85 } | |
86 $this->data['block'] = $value; | |
87 } | |
88 | |
89 /** | |
90 * Set "explicit" flag | |
91 * | |
92 * @param bool $value | |
93 * @return Entry | |
94 * @throws Writer\Exception\InvalidArgumentException | |
95 */ | |
96 public function setPlayPodcastExplicit($value) | |
97 { | |
98 if (! in_array($value, ['yes', 'no', 'clean'], true)) { | |
99 throw new Writer\Exception\InvalidArgumentException( | |
100 'invalid parameter: "explicit" may only be one of "yes", "no" or "clean"' | |
101 ); | |
102 } | |
103 $this->data['explicit'] = $value; | |
104 return $this; | |
105 } | |
106 | |
107 /** | |
108 * Set episode description | |
109 * | |
110 * @param string $value | |
111 * @return Entry | |
112 * @throws Writer\Exception\InvalidArgumentException | |
113 */ | |
114 public function setPlayPodcastDescription($value) | |
115 { | |
116 if ($this->stringWrapper->strlen($value) > 4000) { | |
117 throw new Writer\Exception\InvalidArgumentException( | |
118 'invalid parameter: "description" may only contain a maximum of 4000 characters' | |
119 ); | |
120 } | |
121 $this->data['description'] = $value; | |
122 return $this; | |
123 } | |
124 | |
125 /** | |
126 * Overloading to itunes specific setters | |
127 * | |
128 * @param string $method | |
129 * @param array $params | |
130 * @throws Writer\Exception\BadMethodCallException | |
131 * @return mixed | |
132 */ | |
133 public function __call($method, array $params) | |
134 { | |
135 $point = lcfirst(substr($method, 14)); | |
136 if (! method_exists($this, 'setPlayPodcast' . ucfirst($point)) | |
137 && ! method_exists($this, 'addPlayPodcast' . ucfirst($point)) | |
138 ) { | |
139 throw new Writer\Exception\BadMethodCallException( | |
140 'invalid method: ' . $method | |
141 ); | |
142 } | |
143 if (! array_key_exists($point, $this->data) | |
144 || empty($this->data[$point]) | |
145 ) { | |
146 return; | |
147 } | |
148 return $this->data[$point]; | |
149 } | |
150 } |