‪TYPO3CMS  10.4
ExtensionXmlPushParser.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
19 
32 {
38  protected ‪$elementData = '';
39 
43  public function ‪__construct()
44  {
45  $this->requiredPhpExtensions = 'xml';
46  }
47 
51  protected function ‪createParser()
52  {
53  $this->objXml = xml_parser_create();
54  xml_set_object($this->objXml, $this);
55  }
56 
63  public function ‪parseXml($file)
64  {
65  $this->‪createParser();
66  if (!is_resource($this->objXml)) {
67  throw new ‪ExtensionManagerException('Unable to create XML parser.', 1342640663);
68  }
69  // Disables the functionality to allow external entities to be loaded when parsing the XML, must be kept
70  $previousValueOfEntityLoader = null;
71  if (PHP_MAJOR_VERSION < 8) {
72  $previousValueOfEntityLoader = libxml_disable_entity_loader(true);
73  }
74  // keep original character case of XML document
75  xml_parser_set_option($this->objXml, XML_OPTION_CASE_FOLDING, false);
76  xml_parser_set_option($this->objXml, XML_OPTION_SKIP_WHITE, false);
77  xml_parser_set_option($this->objXml, XML_OPTION_TARGET_ENCODING, 'utf-8');
78  xml_set_element_handler($this->objXml, [$this, 'startElement'], [$this, 'endElement']);
79  xml_set_character_data_handler($this->objXml, [$this, 'characterData']);
80  if (!($fp = fopen($file, 'r'))) {
81  throw new ‪ExtensionManagerException(sprintf('Unable to open file resource %s.', $file), 1342640689);
82  }
83  while ($data = fread($fp, 4096)) {
84  if (!xml_parse($this->objXml, $data, feof($fp))) {
85  throw new ‪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), 1342640703);
86  }
87  }
88  if (PHP_MAJOR_VERSION < 8) {
89  libxml_disable_entity_loader($previousValueOfEntityLoader);
90  }
91  xml_parser_free($this->objXml);
92  }
93 
101  protected function ‪startElement(‪$parser, $elementName, $attrs)
102  {
103  switch ($elementName) {
104  case 'extension':
105  $this->extensionKey = $attrs['extensionkey'];
106  break;
107  case 'version':
108  $this->version = $attrs['version'];
109  break;
110  default:
111  $this->elementData = '';
112  }
113  }
114 
121  protected function ‪endElement(‪$parser, $elementName)
122  {
123  switch ($elementName) {
124  case 'extension':
125  $this->‪resetProperties(true);
126  break;
127  case 'version':
128  $this->‪notify();
129  $this->‪resetProperties();
130  break;
131  case 'downloadcounter':
132  // downloadcounter could be a child node of
133  // extension or version
134  if ($this->version == null) {
135  $this->extensionDownloadCounter = ‪$this->elementData;
136  } else {
137  $this->versionDownloadCounter = ‪$this->elementData;
138  }
139  break;
140  case 'title':
141  $this->title = ‪$this->elementData;
142  break;
143  case 'description':
144  $this->description = ‪$this->elementData;
145  break;
146  case 'state':
147  $this->state = ‪$this->elementData;
148  break;
149  case 'reviewstate':
150  $this->reviewstate = ‪$this->elementData;
151  break;
152  case 'category':
153  $this->category = ‪$this->elementData;
154  break;
155  case 'lastuploaddate':
156  $this->lastuploaddate = ‪$this->elementData;
157  break;
158  case 'uploadcomment':
159  $this->uploadcomment = ‪$this->elementData;
160  break;
161  case 'dependencies':
162  $this->dependencies = $this->‪convertDependencies($this->elementData);
163  break;
164  case 'authorname':
165  $this->authorname = ‪$this->elementData;
166  break;
167  case 'authoremail':
168  $this->authoremail = ‪$this->elementData;
169  break;
170  case 'authorcompany':
171  $this->authorcompany = ‪$this->elementData;
172  break;
173  case 'ownerusername':
174  $this->ownerusername = ‪$this->elementData;
175  break;
176  case 't3xfilemd5':
177  $this->t3xfilemd5 = ‪$this->elementData;
178  break;
179  case 'documentation_link':
180  $this->documentationLink = ‪$this->elementData;
181  break;
182  }
183  }
184 
191  protected function ‪characterData(‪$parser, $data)
192  {
193  $this->elementData .= $data;
194  }
195 }
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPushParser\endElement
‪endElement($parser, $elementName)
Definition: ExtensionXmlPushParser.php:120
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPushParser\$elementData
‪string $elementData
Definition: ExtensionXmlPushParser.php:37
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPushParser\createParser
‪createParser()
Definition: ExtensionXmlPushParser.php:50
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPushParser\__construct
‪__construct()
Definition: ExtensionXmlPushParser.php:42
‪TYPO3\CMS\Extensionmanager\Utility\Parser
Definition: AbstractExtensionXmlParser.php:16
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\convertDependencies
‪string convertDependencies($dependencies)
Definition: AbstractExtensionXmlParser.php:392
‪$parser
‪$parser
Definition: annotationChecker.php:108
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPushParser\startElement
‪startElement($parser, $elementName, $attrs)
Definition: ExtensionXmlPushParser.php:100
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractXmlParser\notify
‪notify()
Definition: AbstractXmlParser.php:76
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser
Definition: AbstractExtensionXmlParser.php:23
‪TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
Definition: ExtensionManagerException.php:24
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\resetProperties
‪resetProperties($resetAll=false)
Definition: AbstractExtensionXmlParser.php:375
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPushParser\parseXml
‪parseXml($file)
Definition: ExtensionXmlPushParser.php:62
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPushParser\characterData
‪characterData($parser, $data)
Definition: ExtensionXmlPushParser.php:190
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPushParser
Definition: ExtensionXmlPushParser.php:32