Skip to content

Instantly share code, notes, and snippets.

@AleksMeshkov
Created March 18, 2014 10:38
Show Gist options
  • Save AleksMeshkov/9617624 to your computer and use it in GitHub Desktop.
Save AleksMeshkov/9617624 to your computer and use it in GitHub Desktop.
<?php namespace InfinitiWeb\Services;
use XMLReader;
use DOMDocument;
class AdmitADYMLParserService {
private $xml_reader = null;
private $offer = null;
public function __construct($offer_id)
{
$this->offer = \Offer::findOrFail($offer_id);
if (empty($this->offer->products_xml_link))
{
throw new \Exception('Offer ' . $this->offer->name . ' doesn\'t have a YML catalog to parse');
}
$this->xml_reader = new XMLReader();
\DB::disableQueryLog();
}
public function parseCatalog()
{
$reader = $this->xml_reader;
$offer = $this->offer;
$reader->open($offer->products_xml_link);
while ($reader->read())
{
if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'offer')
{
$doc = new DOMDocument('1.0', 'UTF-8');
$xml = simplexml_import_dom($doc->importNode($reader->expand(), true));
$name = $xml->name;
$description = $xml->description; //or whatever
$url = $xml->url;
$picture = $xml->picture;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment