Example #1
0
 /**
  * Read News Stories
  *
  * @access  public
  * @param   mixed  $input
  * @param   array  $options
  * @throws  RonException
  * @return  array
  */
 public function read($input, array $options = [])
 {
     // Fetch input from a URL
     if ($url = filter_var($input, FILTER_VALIDATE_URL)) {
         if ($this->client === null || $this->message === null) {
             throw new RonException('HttpClient and MessageFactory required to fetch data from a URL');
         }
         try {
             $request = $this->message->createRequest('GET', $url);
             $response = $this->client->sendRequest($request);
             $input = $response->getBody()->getContents();
         } catch (Exception $e) {
             throw new RonException($e->getMessage(), $e->getCode(), $e);
         }
     }
     try {
         $options = array_replace_recursive(['options' => LIBXML_PARSEHUGE | LIBXML_DTDLOAD | LIBXML_NSCLEAN], $options);
         $stories = [];
         $this->parser->extract($input, $options, $stories);
         return $stories;
     } catch (EssenceException $e) {
         throw new RonException($e->getMessage(), $e->getCode(), $e);
     }
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function dump($input, array $config = array())
 {
     if (!is_array($input)) {
         throw new EssenceException('The input must be an associative array');
     }
     $response = $this->makeCall($input);
     return parent::dump($response, $config);
 }