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