‪TYPO3CMS  9.5
ExtensionXmlPushParser.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 {
35  protected ‪$elementData = '';
36 
40  public function ‪__construct()
41  {
42  $this->requiredPhpExtensions = 'xml';
43  }
44 
48  protected function ‪createParser()
49  {
50  $this->objXml = xml_parser_create();
51  xml_set_object($this->objXml, $this);
52  }
53 
60  public function ‪parseXml($file)
61  {
62  $this->‪createParser();
63  if (!is_resource($this->objXml)) {
64  throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException('Unable to create XML parser.', 1342640663);
65  }
66  // Disables the functionality to allow external entities to be loaded when parsing the XML, must be kept
67  $previousValueOfEntityLoader = libxml_disable_entity_loader(true);
68  // keep original character case of XML document
69  xml_parser_set_option($this->objXml, XML_OPTION_CASE_FOLDING, false);
70  xml_parser_set_option($this->objXml, XML_OPTION_SKIP_WHITE, false);
71  xml_parser_set_option($this->objXml, XML_OPTION_TARGET_ENCODING, 'utf-8');
72  xml_set_element_handler($this->objXml, 'startElement', 'endElement');
73  xml_set_character_data_handler($this->objXml, 'characterData');
74  if (!($fp = fopen($file, 'r'))) {
75  throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(sprintf('Unable to open file resource %s.', $file), 1342640689);
76  }
77  while ($data = fread($fp, 4096)) {
78  if (!xml_parse($this->objXml, $data, feof($fp))) {
79  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), 1342640703);
80  }
81  }
82  libxml_disable_entity_loader($previousValueOfEntityLoader);
83  xml_parser_free($this->objXml);
84  }
85 
93  protected function ‪startElement(‪$parser, $elementName, $attrs)
94  {
95  switch ($elementName) {
96  case 'extension':
97  $this->extensionKey = $attrs['extensionkey'];
98  break;
99  case 'version':
100  $this->version = $attrs['version'];
101  break;
102  default:
103  $this->elementData = '';
104  }
105  }
106 
113  protected function ‪endElement(‪$parser, $elementName)
114  {
115  switch ($elementName) {
116  case 'extension':
117  $this->‪resetProperties(true);
118  break;
119  case 'version':
120  $this->‪notify();
121  $this->‪resetProperties();
122  break;
123  case 'downloadcounter':
124  // downloadcounter could be a child node of
125  // extension or version
126  if ($this->version == null) {
127  $this->extensionDownloadCounter = ‪$this->elementData;
128  } else {
129  $this->versionDownloadCounter = ‪$this->elementData;
130  }
131  break;
132  case 'title':
133  $this->title = ‪$this->elementData;
134  break;
135  case 'description':
136  $this->description = ‪$this->elementData;
137  break;
138  case 'state':
139  $this->state = ‪$this->elementData;
140  break;
141  case 'reviewstate':
142  $this->reviewstate = ‪$this->elementData;
143  break;
144  case 'category':
145  $this->category = ‪$this->elementData;
146  break;
147  case 'lastuploaddate':
148  $this->lastuploaddate = ‪$this->elementData;
149  break;
150  case 'uploadcomment':
151  $this->uploadcomment = ‪$this->elementData;
152  break;
153  case 'dependencies':
154  $this->dependencies = $this->‪convertDependencies($this->elementData);
155  break;
156  case 'authorname':
157  $this->authorname = ‪$this->elementData;
158  break;
159  case 'authoremail':
160  $this->authoremail = ‪$this->elementData;
161  break;
162  case 'authorcompany':
163  $this->authorcompany = ‪$this->elementData;
164  break;
165  case 'ownerusername':
166  $this->ownerusername = ‪$this->elementData;
167  break;
168  case 't3xfilemd5':
169  $this->t3xfilemd5 = ‪$this->elementData;
170  break;
171  }
172  }
173 
180  protected function ‪characterData(‪$parser, $data)
181  {
182  $this->elementData .= $data;
183  }
184 }
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPushParser\endElement
‪endElement($parser, $elementName)
Definition: ExtensionXmlPushParser.php:112
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPushParser\$elementData
‪string $elementData
Definition: ExtensionXmlPushParser.php:34
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPushParser\createParser
‪createParser()
Definition: ExtensionXmlPushParser.php:47
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPushParser\__construct
‪__construct()
Definition: ExtensionXmlPushParser.php:39
‪TYPO3\CMS\Extensionmanager\Utility\Parser
Definition: AbstractExtensionXmlParser.php:2
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\convertDependencies
‪string convertDependencies($dependencies)
Definition: AbstractExtensionXmlParser.php:369
‪$parser
‪$parser
Definition: annotationChecker.php:100
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPushParser\startElement
‪startElement($parser, $elementName, $attrs)
Definition: ExtensionXmlPushParser.php:92
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractXmlParser\notify
‪notify()
Definition: AbstractXmlParser.php:72
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser
Definition: AbstractExtensionXmlParser.php:22
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\resetProperties
‪resetProperties($resetAll=false)
Definition: AbstractExtensionXmlParser.php:352
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPushParser\parseXml
‪parseXml($file)
Definition: ExtensionXmlPushParser.php:59
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPushParser\characterData
‪characterData($parser, $data)
Definition: ExtensionXmlPushParser.php:179
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPushParser
Definition: ExtensionXmlPushParser.php:29