‪TYPO3CMS  9.5
MirrorXmlPushParser.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 
29 {
33  protected ‪$element;
34 
38  public function ‪__construct()
39  {
40  $this->requiredPhpExtensions = 'xml';
41  }
42 
46  protected function ‪createParser()
47  {
48  $this->objXml = xml_parser_create();
49  xml_set_object($this->objXml, $this);
50  }
51 
58  public function ‪parseXml($file)
59  {
60  $this->‪createParser();
61  if (!is_resource($this->objXml)) {
62  throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException('Unable to create XML parser.', 1342641009);
63  }
64  // Disables the functionality to allow external entities to be loaded when parsing the XML, must be kept
65  $previousValueOfEntityLoader = libxml_disable_entity_loader(true);
66  // keep original character case of XML document
67  xml_parser_set_option($this->objXml, XML_OPTION_CASE_FOLDING, false);
68  xml_parser_set_option($this->objXml, XML_OPTION_SKIP_WHITE, false);
69  xml_parser_set_option($this->objXml, XML_OPTION_TARGET_ENCODING, 'utf-8');
70  xml_set_element_handler($this->objXml, 'startElement', 'endElement');
71  xml_set_character_data_handler($this->objXml, 'characterData');
72  if (!($fp = fopen($file, 'r'))) {
73  throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(sprintf('Unable to open file resource %s.', $file), 1342641010);
74  }
75  while ($data = fread($fp, 4096)) {
76  if (!xml_parse($this->objXml, $data, feof($fp))) {
77  throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(sprintf('XML error %s in line %u of file resource %s.', xml_error_string(xml_get_error_code($this->objXml)), xml_get_current_line_number($this->objXml), $file), 1342641011);
78  }
79  }
80  libxml_disable_entity_loader($previousValueOfEntityLoader);
81  xml_parser_free($this->objXml);
82  }
83 
91  protected function ‪startElement(‪$parser, $elementName, $attrs)
92  {
93  switch ($elementName) {
94  default:
95  $this->element = $elementName;
96  }
97  }
98 
108  protected function ‪endElement(‪$parser, $elementName)
109  {
110  switch ($elementName) {
111  case 'mirror':
112  $this->‪notify();
113  $this->‪resetProperties();
114  break;
115  default:
116  $this->element = null;
117  }
118  }
119 
129  protected function ‪characterData(‪$parser, $data)
130  {
131  if (isset($this->element)) {
132  switch ($this->element) {
133  case 'title':
134  $this->title = $data;
135  break;
136  case 'host':
137  $this->host = $data;
138  break;
139  case 'path':
140  $this->path = $data;
141  break;
142  case 'country':
143  $this->country = $data;
144  break;
145  case 'name':
146  $this->sponsorname = $data;
147  break;
148  case 'link':
149  $this->sponsorlink = $data;
150  break;
151  case 'logo':
152  $this->sponsorlogo = $data;
153  break;
154  default:
155  // Do nothing
156  }
157  }
158  }
159 }
‪TYPO3\CMS\Extensionmanager\Utility\Parser\MirrorXmlPushParser
Definition: MirrorXmlPushParser.php:29
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractMirrorXmlParser\resetProperties
‪resetProperties()
Definition: AbstractMirrorXmlParser.php:169
‪TYPO3\CMS\Extensionmanager\Utility\Parser
Definition: AbstractExtensionXmlParser.php:2
‪TYPO3\CMS\Extensionmanager\Utility\Parser\MirrorXmlPushParser\characterData
‪characterData($parser, $data)
Definition: MirrorXmlPushParser.php:128
‪TYPO3\CMS\Extensionmanager\Utility\Parser\MirrorXmlPushParser\createParser
‪createParser()
Definition: MirrorXmlPushParser.php:45
‪TYPO3\CMS\Extensionmanager\Utility\Parser\MirrorXmlPushParser\parseXml
‪parseXml($file)
Definition: MirrorXmlPushParser.php:57
‪TYPO3\CMS\Extensionmanager\Utility\Parser\MirrorXmlPushParser\startElement
‪startElement($parser, $elementName, $attrs)
Definition: MirrorXmlPushParser.php:90
‪TYPO3\CMS\Extensionmanager\Utility\Parser\MirrorXmlPushParser\endElement
‪endElement($parser, $elementName)
Definition: MirrorXmlPushParser.php:107
‪$parser
‪$parser
Definition: annotationChecker.php:100
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractXmlParser\notify
‪notify()
Definition: AbstractXmlParser.php:72
‪TYPO3\CMS\Extensionmanager\Utility\Parser\MirrorXmlPushParser\__construct
‪__construct()
Definition: MirrorXmlPushParser.php:37
‪TYPO3\CMS\Extensionmanager\Utility\Parser\MirrorXmlPushParser\$element
‪string $element
Definition: MirrorXmlPushParser.php:32
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractMirrorXmlParser
Definition: AbstractMirrorXmlParser.php:22