Last active
December 5, 2017 19:31
-
-
Save a-ast/da432527d7dbae7c3cf6b13f624582f5 to your computer and use it in GitHub Desktop.
Spryker DataImport: implement XmlDataReader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// DataImportBusinessFactory.php | |
protected function createGlossaryImporter() | |
{ | |
$dataImporterConfigurationTransfer = $this->getConfig()->getGlossaryDataImporterConfiguration(); | |
$xmlReader = new XmlDataReader($dataImporterConfigurationTransfer->getReaderConfiguration()->getFileName()); | |
$dataImporter = $this->createDataImporter($dataImporterConfigurationTransfer->getImportType(), $xmlReader); | |
// ... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// XmlDataReader.php | |
namespace Pyz\Zed\DataImport\Business\Model\DataReader; | |
use SimpleXMLIterator; | |
use Spryker\Zed\DataImport\Business\Model\DataReader\DataReaderInterface; | |
use Spryker\Zed\DataImport\Business\Model\DataSet\DataSet; | |
use Spryker\Zed\DataImport\Business\Model\DataSet\DataSetInterface; | |
class XmlDataReader implements DataReaderInterface | |
{ | |
/* | |
* SimpleXMLIterator | |
*/ | |
private $iterator; | |
public function __construct(string $filename) | |
{ | |
$this->iterator = new SimpleXMLIterator(file_get_contents($filename)); | |
} | |
public function next() | |
{ | |
$this->iterator->next(); | |
} | |
public function key() | |
{ | |
return $this->iterator->key(); | |
} | |
public function valid() | |
{ | |
return $this->iterator->valid(); | |
} | |
public function rewind() | |
{ | |
$this->iterator->rewind(); | |
} | |
public function current(): DataSetInterface | |
{ | |
$data = $this->iterator->current(); | |
return new DataSet($data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment