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