| 1 |
<?php |
| 2 |
|
| 3 |
namespace ImportWP\Common\Importer; |
| 4 |
|
| 5 |
/** |
| 6 |
* Class DataParser |
| 7 |
* |
| 8 |
* Run all template queries on xml record. |
| 9 |
* |
| 10 |
* @package ImportWP\Common\Importer |
| 11 |
*/ |
| 12 |
class DataParser |
| 13 |
{ |
| 14 |
private $config_data; |
| 15 |
|
| 16 |
/** |
| 17 |
* @var ParserInterface $parser |
| 18 |
*/ |
| 19 |
private $parser; |
| 20 |
|
| 21 |
/** |
| 22 |
* @var MapperInterface $mapper |
| 23 |
*/ |
| 24 |
private $mapper; |
| 25 |
|
| 26 |
public function __construct(ParserInterface $parser, MapperInterface $mapper, $config_data) |
| 27 |
{ |
| 28 |
$this->parser = $parser; |
| 29 |
$this->config_data = $config_data; |
| 30 |
$this->mapper = $mapper; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Get record from parser matching the template |
| 35 |
* |
| 36 |
* @param int $index |
| 37 |
* |
| 38 |
* @return ParsedData |
| 39 |
*/ |
| 40 |
public function get($index) |
| 41 |
{ |
| 42 |
|
| 43 |
$parsed_data = new ParsedData($this->mapper); |
| 44 |
|
| 45 |
if ($this->config_data) { |
| 46 |
foreach ($this->config_data as $group) { |
| 47 |
$data = $this->parser->getRecord($index) |
| 48 |
->queryGroup($group); |
| 49 |
|
| 50 |
$parsed_data->add($data, $group); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
return $parsed_data; |
| 55 |
} |
| 56 |
} |
| 57 |
|