You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
974 B

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. <?php
  2. namespace CustomHandlers\Response;
  3. use App\Handlers\Response\ResponseHandler;
  4. use SimpleXMLElement;
  5. /**
  6. * Handle Response of a Rss Feed,
  7. * response will parsed to SimpleXMLElement
  8. * each item in a channel will be run through actions
  9. *
  10. *
  11. */
  12. class Rss extends ResponseHandler
  13. {
  14. /**
  15. * getting data from
  16. *
  17. *
  18. * @return object
  19. *
  20. */
  21. public function getResponse()
  22. {
  23. $this->response = Http::withHeaders([
  24. "Content-Type" => "text/xml;charset=utf-8"
  25. ])->get($this->source->url);
  26. return $this->response;
  27. }
  28. /**
  29. * handle response
  30. *
  31. *
  32. *
  33. */
  34. public function run()
  35. {
  36. // parse xml from body
  37. $xml = new SimpleXMLElement($this->response->body());
  38. // only process if xml is valid
  39. if ($xml) {
  40. foreach($xml->channel->item as $item) {
  41. $this->processActions($item);
  42. }
  43. }
  44. }
  45. }