Mercurial > hg > isophonics-drupal-site
comparison vendor/zendframework/zend-feed/src/PubSubHubbub/Publisher.php @ 12:7a779792577d
Update Drupal core to v8.4.5 (via Composer)
author | Chris Cannam |
---|---|
date | Fri, 23 Feb 2018 15:52:07 +0000 |
parents | 4c8ae668cc8c |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
11:bfffd8d7479a | 12:7a779792577d |
---|---|
73 { | 73 { |
74 if ($options instanceof Traversable) { | 74 if ($options instanceof Traversable) { |
75 $options = ArrayUtils::iteratorToArray($options); | 75 $options = ArrayUtils::iteratorToArray($options); |
76 } | 76 } |
77 | 77 |
78 if (!is_array($options)) { | 78 if (! is_array($options)) { |
79 throw new Exception\InvalidArgumentException('Array or Traversable object' | 79 throw new Exception\InvalidArgumentException('Array or Traversable object' |
80 . 'expected, got ' . gettype($options)); | 80 . 'expected, got ' . gettype($options)); |
81 } | 81 } |
82 if (array_key_exists('hubUrls', $options)) { | 82 if (array_key_exists('hubUrls', $options)) { |
83 $this->addHubUrls($options['hubUrls']); | 83 $this->addHubUrls($options['hubUrls']); |
98 * @return Publisher | 98 * @return Publisher |
99 * @throws Exception\InvalidArgumentException | 99 * @throws Exception\InvalidArgumentException |
100 */ | 100 */ |
101 public function addHubUrl($url) | 101 public function addHubUrl($url) |
102 { | 102 { |
103 if (empty($url) || !is_string($url) || !Uri::factory($url)->isValid()) { | 103 if (empty($url) || ! is_string($url) || ! Uri::factory($url)->isValid()) { |
104 throw new Exception\InvalidArgumentException('Invalid parameter "url"' | 104 throw new Exception\InvalidArgumentException('Invalid parameter "url"' |
105 . ' of "' . $url . '" must be a non-empty string and a valid' | 105 . ' of "' . $url . '" must be a non-empty string and a valid' |
106 . 'URL'); | 106 . 'URL'); |
107 } | 107 } |
108 $this->hubUrls[] = $url; | 108 $this->hubUrls[] = $url; |
129 * @param string $url | 129 * @param string $url |
130 * @return Publisher | 130 * @return Publisher |
131 */ | 131 */ |
132 public function removeHubUrl($url) | 132 public function removeHubUrl($url) |
133 { | 133 { |
134 if (!in_array($url, $this->getHubUrls())) { | 134 if (! in_array($url, $this->getHubUrls())) { |
135 return $this; | 135 return $this; |
136 } | 136 } |
137 $key = array_search($url, $this->hubUrls); | 137 $key = array_search($url, $this->hubUrls); |
138 unset($this->hubUrls[$key]); | 138 unset($this->hubUrls[$key]); |
139 return $this; | 139 return $this; |
157 * @return Publisher | 157 * @return Publisher |
158 * @throws Exception\InvalidArgumentException | 158 * @throws Exception\InvalidArgumentException |
159 */ | 159 */ |
160 public function addUpdatedTopicUrl($url) | 160 public function addUpdatedTopicUrl($url) |
161 { | 161 { |
162 if (empty($url) || !is_string($url) || !Uri::factory($url)->isValid()) { | 162 if (empty($url) || ! is_string($url) || ! Uri::factory($url)->isValid()) { |
163 throw new Exception\InvalidArgumentException('Invalid parameter "url"' | 163 throw new Exception\InvalidArgumentException('Invalid parameter "url"' |
164 . ' of "' . $url . '" must be a non-empty string and a valid' | 164 . ' of "' . $url . '" must be a non-empty string and a valid' |
165 . 'URL'); | 165 . 'URL'); |
166 } | 166 } |
167 $this->updatedTopicUrls[] = $url; | 167 $this->updatedTopicUrls[] = $url; |
188 * @param string $url | 188 * @param string $url |
189 * @return Publisher | 189 * @return Publisher |
190 */ | 190 */ |
191 public function removeUpdatedTopicUrl($url) | 191 public function removeUpdatedTopicUrl($url) |
192 { | 192 { |
193 if (!in_array($url, $this->getUpdatedTopicUrls())) { | 193 if (! in_array($url, $this->getUpdatedTopicUrls())) { |
194 return $this; | 194 return $this; |
195 } | 195 } |
196 $key = array_search($url, $this->updatedTopicUrls); | 196 $key = array_search($url, $this->updatedTopicUrls); |
197 unset($this->updatedTopicUrls[$key]); | 197 unset($this->updatedTopicUrls[$key]); |
198 return $this; | 198 return $this; |
217 * @throws Exception\InvalidArgumentException | 217 * @throws Exception\InvalidArgumentException |
218 * @throws Exception\RuntimeException | 218 * @throws Exception\RuntimeException |
219 */ | 219 */ |
220 public function notifyHub($url) | 220 public function notifyHub($url) |
221 { | 221 { |
222 if (empty($url) || !is_string($url) || !Uri::factory($url)->isValid()) { | 222 if (empty($url) || ! is_string($url) || ! Uri::factory($url)->isValid()) { |
223 throw new Exception\InvalidArgumentException('Invalid parameter "url"' | 223 throw new Exception\InvalidArgumentException('Invalid parameter "url"' |
224 . ' of "' . $url . '" must be a non-empty string and a valid' | 224 . ' of "' . $url . '" must be a non-empty string and a valid' |
225 . 'URL'); | 225 . 'URL'); |
226 } | 226 } |
227 $client = $this->_getHttpClient(); | 227 $client = $this->_getHttpClient(); |
279 { | 279 { |
280 if (is_array($name)) { | 280 if (is_array($name)) { |
281 $this->setParameters($name); | 281 $this->setParameters($name); |
282 return $this; | 282 return $this; |
283 } | 283 } |
284 if (empty($name) || !is_string($name)) { | 284 if (empty($name) || ! is_string($name)) { |
285 throw new Exception\InvalidArgumentException('Invalid parameter "name"' | 285 throw new Exception\InvalidArgumentException('Invalid parameter "name"' |
286 . ' of "' . $name . '" must be a non-empty string'); | 286 . ' of "' . $name . '" must be a non-empty string'); |
287 } | 287 } |
288 if ($value === null) { | 288 if ($value === null) { |
289 $this->removeParameter($name); | 289 $this->removeParameter($name); |
290 return $this; | 290 return $this; |
291 } | 291 } |
292 if (empty($value) || (!is_string($value) && $value !== null)) { | 292 if (empty($value) || (! is_string($value) && $value !== null)) { |
293 throw new Exception\InvalidArgumentException('Invalid parameter "value"' | 293 throw new Exception\InvalidArgumentException('Invalid parameter "value"' |
294 . ' of "' . $value . '" must be a non-empty string'); | 294 . ' of "' . $value . '" must be a non-empty string'); |
295 } | 295 } |
296 $this->parameters[$name] = $value; | 296 $this->parameters[$name] = $value; |
297 return $this; | 297 return $this; |
318 * @return Publisher | 318 * @return Publisher |
319 * @throws Exception\InvalidArgumentException | 319 * @throws Exception\InvalidArgumentException |
320 */ | 320 */ |
321 public function removeParameter($name) | 321 public function removeParameter($name) |
322 { | 322 { |
323 if (empty($name) || !is_string($name)) { | 323 if (empty($name) || ! is_string($name)) { |
324 throw new Exception\InvalidArgumentException('Invalid parameter "name"' | 324 throw new Exception\InvalidArgumentException('Invalid parameter "name"' |
325 . ' of "' . $name . '" must be a non-empty string'); | 325 . ' of "' . $name . '" must be a non-empty string'); |
326 } | 326 } |
327 if (array_key_exists($name, $this->parameters)) { | 327 if (array_key_exists($name, $this->parameters)) { |
328 unset($this->parameters[$name]); | 328 unset($this->parameters[$name]); |
346 * | 346 * |
347 * @return bool | 347 * @return bool |
348 */ | 348 */ |
349 public function isSuccess() | 349 public function isSuccess() |
350 { | 350 { |
351 return !(count($this->errors) != 0); | 351 return ! (count($this->errors) != 0); |
352 } | 352 } |
353 | 353 |
354 /** | 354 /** |
355 * Return an array of errors met from any failures, including keys: | 355 * Return an array of errors met from any failures, including keys: |
356 * 'response' => the Zend\Http\Response object from the failure | 356 * 'response' => the Zend\Http\Response object from the failure |
367 * Get a basic prepared HTTP client for use | 367 * Get a basic prepared HTTP client for use |
368 * | 368 * |
369 * @return \Zend\Http\Client | 369 * @return \Zend\Http\Client |
370 * @throws Exception\RuntimeException | 370 * @throws Exception\RuntimeException |
371 */ | 371 */ |
372 // @codingStandardsIgnoreStart | |
372 protected function _getHttpClient() | 373 protected function _getHttpClient() |
373 { | 374 { |
375 // @codingStandardsIgnoreEnd | |
374 $client = PubSubHubbub::getHttpClient(); | 376 $client = PubSubHubbub::getHttpClient(); |
375 $client->setMethod(HttpRequest::METHOD_POST); | 377 $client->setMethod(HttpRequest::METHOD_POST); |
376 $client->setOptions([ | 378 $client->setOptions([ |
377 'useragent' => 'Zend_Feed_Pubsubhubbub_Publisher/' . Version::VERSION, | 379 'useragent' => 'Zend_Feed_Pubsubhubbub_Publisher/' . Version::VERSION, |
378 ]); | 380 ]); |