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.

45 lines
847 B

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