<?php
|
|
|
|
namespace CustomHandlers\Response;
|
|
|
|
use App\Handlers\Response\ResponseHandler;
|
|
use SimpleXMLElement;
|
|
|
|
/**
|
|
* Handle Response of a Rss Feed,
|
|
* response will parsed to SimpleXMLElement
|
|
* each item in a channel will be run through actions
|
|
*
|
|
*
|
|
*/
|
|
class Rss extends ResponseHandler
|
|
{
|
|
/**
|
|
* getting data from
|
|
*
|
|
*
|
|
* @return object
|
|
*
|
|
*/
|
|
public function getResponse()
|
|
{
|
|
$this->response = Http::withHeaders([
|
|
"Content-Type" => "text/xml;charset=utf-8"
|
|
])->get($this->source->url);
|
|
|
|
return $this->response;
|
|
}
|
|
|
|
/**
|
|
* handle response
|
|
*
|
|
*
|
|
*
|
|
*/
|
|
public function run()
|
|
{
|
|
// parse xml from body
|
|
$xml = new SimpleXMLElement($this->response->body());
|
|
|
|
// only process if xml is valid
|
|
if ($xml) {
|
|
foreach($xml->channel->item as $item) {
|
|
$this->processActions($item);
|
|
}
|
|
}
|
|
}
|
|
}
|