ast
13 years ago
cache
13 years ago
XmlImportConfig.php
13 years ago
XmlImportCsvParse.php
13 years ago
XmlImportException.php
13 years ago
XmlImportParser.php
13 years ago
XmlImportReaderInterface.php
13 years ago
XmlImportStringReader.php
13 years ago
XmlImportTemplate.php
13 years ago
XmlImportTemplateCodeGenerator.php
13 years ago
XmlImportTemplateParser.php
13 years ago
XmlImportTemplateScanner.php
13 years ago
XmlImportToken.php
13 years ago
pclzip.lib.php
13 years ago
XmlImportTemplate.php
78 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @author Olexandr Zanichkovsky <olexandr.zanichkovsky@zophiatech.com> |
| 4 | * @author Pavel Kulbakin <p.kulbakin@gmail.com> |
| 5 | * @package General |
| 6 | */ |
| 7 | |
| 8 | require_once dirname(__FILE__) . '/XmlImportConfig.php'; |
| 9 | |
| 10 | /** |
| 11 | * Represents a template |
| 12 | */ |
| 13 | class XmlImportTemplate { |
| 14 | /** |
| 15 | * Root element of the record that is being parsed |
| 16 | * |
| 17 | * @var SimpleXMLElement |
| 18 | */ |
| 19 | protected $xml; |
| 20 | |
| 21 | /** |
| 22 | * file name of the cached template |
| 23 | * |
| 24 | * @var string |
| 25 | */ |
| 26 | protected $cachedTemplate; |
| 27 | |
| 28 | /** |
| 29 | * Creates new instance |
| 30 | * |
| 31 | * @param SimpleXmlElement $xml |
| 32 | * @param string $cachedTemplate |
| 33 | */ |
| 34 | public function __construct($xml, $cachedTemplate) |
| 35 | { |
| 36 | $this->xml = $xml; |
| 37 | $this->cachedTemplate = $cachedTemplate; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Parses a template using {@see $this->xml} |
| 42 | * |
| 43 | * @return string |
| 44 | */ |
| 45 | public function parse() |
| 46 | { |
| 47 | |
| 48 | ob_start(); |
| 49 | $err_lvl = error_reporting(E_ALL); |
| 50 | include $this->cachedTemplate; |
| 51 | error_reporting($err_lvl); |
| 52 | |
| 53 | return ob_get_clean(); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Get the value by XPath expression |
| 58 | * |
| 59 | * @param SimpleXmlElement $xpath XPath result |
| 60 | * @return mixed |
| 61 | */ |
| 62 | protected function getValue($xpath) |
| 63 | { |
| 64 | |
| 65 | if (is_array($xpath) && count($xpath) > 0) { |
| 66 | $result = array(); |
| 67 | foreach ($xpath as $xp) { // cancatenate multiple elements into 1 string |
| 68 | ob_start(); |
| 69 | echo $xp; |
| 70 | $result[] = trim(ob_get_clean()); |
| 71 | } |
| 72 | return implode(XmlImportConfig::getInstance()->getMultiGlue(), $result); |
| 73 | } else { |
| 74 | // return null if nothing found |
| 75 | return null; |
| 76 | } |
| 77 | } |
| 78 | } |