TYPO3 CMS  TYPO3_8-7
AbstractXmlParser.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
20 
25 {
29  protected $sourcePath;
30 
34  protected $languageKey;
35 
45  public function getParsedData($sourcePath, $languageKey, $charset = '')
46  {
47  $this->sourcePath = $sourcePath;
48  $this->languageKey = $languageKey;
49  if ($this->languageKey !== 'default') {
50  $this->sourcePath = GeneralUtility::getFileAbsFileName(GeneralUtility::llXmlAutoFileName($this->sourcePath, $this->languageKey));
51  if (!@is_file($this->sourcePath)) {
52  // Global localization is not available, try split localization file
54  }
55  if (!@is_file($this->sourcePath)) {
56  throw new FileNotFoundException('Localization file does not exist', 1306332397);
57  }
58  }
59  $LOCAL_LANG = [];
60  $LOCAL_LANG[$languageKey] = $this->parseXmlFile();
61  return $LOCAL_LANG;
62  }
63 
70  protected function parseXmlFile()
71  {
72  $xmlContent = file_get_contents($this->sourcePath);
73  // Disables the functionality to allow external entities to be loaded when parsing the XML, must be kept
74  $previousValueOfEntityLoader = libxml_disable_entity_loader(true);
75  $rootXmlNode = simplexml_load_string($xmlContent, 'SimpleXMLElement', LIBXML_NOWARNING);
76  libxml_disable_entity_loader($previousValueOfEntityLoader);
77  if (!isset($rootXmlNode) || $rootXmlNode === false) {
78  $xmlError = libxml_get_last_error();
79  throw new InvalidXmlFileException(
80  'The path provided does not point to existing and accessible well-formed XML file. Reason: ' . $xmlError->message . ' in ' . $this->sourcePath . ', line ' . $xmlError->line,
81  1278155988
82  );
83  }
84  return $this->doParsingFromRoot($rootXmlNode);
85  }
86 
93  abstract protected function doParsingFromRoot(\SimpleXMLElement $root);
94 }
static getFileAbsFileName($filename, $_=null, $_2=null)
static llXmlAutoFileName($fileRef, $language, $sameLocation=false)
getParsedData($sourcePath, $languageKey, $charset='')