‪TYPO3CMS  9.5
ExtensionXmlPullParser.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 
25 {
29  public function ‪__construct()
30  {
31  $this->requiredPhpExtensions = 'xmlreader';
32  }
33 
37  protected function ‪createParser()
38  {
39  $this->objXml = new \XMLReader();
40  }
41 
48  public function ‪parseXml($file)
49  {
50  $this->‪createParser();
51  if (!(is_object($this->objXml) && get_class($this->objXml) === 'XMLReader')) {
52  throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException('Unable to create XML parser.', 1342640540);
53  }
54  if ($this->objXml->open($file, 'utf-8') === false) {
55  throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(
56  sprintf('Unable to open file resource %s.', $file),
57  1476108651
58  );
59  }
60  while ($this->objXml->read()) {
61  if ($this->objXml->nodeType == \XMLReader::ELEMENT) {
62  $this->‪startElement($this->objXml->name);
63  } else {
64  if ($this->objXml->nodeType == \XMLReader::END_ELEMENT) {
65  $this->‪endElement($this->objXml->name);
66  } else {
67  continue;
68  }
69  }
70  }
71  $this->objXml->close();
72  }
73 
79  protected function ‪startElement($elementName)
80  {
81  switch ($elementName) {
82  case 'extension':
83  $this->extensionKey = $this->objXml->getAttribute('extensionkey');
84  break;
85  case 'version':
86  $this->version = $this->objXml->getAttribute('version');
87  break;
88  case 'downloadcounter':
89  // downloadcounter could be a child node of
90  // extension or version
91  if ($this->version == null) {
92  $this->extensionDownloadCounter = $this->‪getElementValue($elementName);
93  } else {
94  $this->versionDownloadCounter = $this->‪getElementValue($elementName);
95  }
96  break;
97  case 'title':
98  $this->title = $this->‪getElementValue($elementName);
99  break;
100  case 'description':
101  $this->description = $this->‪getElementValue($elementName);
102  break;
103  case 'state':
104  $this->state = $this->‪getElementValue($elementName);
105  break;
106  case 'reviewstate':
107  $this->reviewstate = $this->‪getElementValue($elementName);
108  break;
109  case 'category':
110  $this->category = $this->‪getElementValue($elementName);
111  break;
112  case 'lastuploaddate':
113  $this->lastuploaddate = $this->‪getElementValue($elementName);
114  break;
115  case 'uploadcomment':
116  $this->uploadcomment = $this->‪getElementValue($elementName);
117  break;
118  case 'dependencies':
119  $this->dependencies = $this->‪convertDependencies($this->‪getElementValue($elementName));
120  break;
121  case 'authorname':
122  $this->authorname = $this->‪getElementValue($elementName);
123  break;
124  case 'authoremail':
125  $this->authoremail = $this->‪getElementValue($elementName);
126  break;
127  case 'authorcompany':
128  $this->authorcompany = $this->‪getElementValue($elementName);
129  break;
130  case 'ownerusername':
131  $this->ownerusername = $this->‪getElementValue($elementName);
132  break;
133  case 't3xfilemd5':
134  $this->t3xfilemd5 = $this->‪getElementValue($elementName);
135  break;
136  }
137  }
138 
144  protected function ‪endElement($elementName)
145  {
146  switch ($elementName) {
147  case 'extension':
148  $this->‪resetProperties(true);
149  break;
150  case 'version':
151  $this->‪notify();
152  $this->‪resetProperties();
153  break;
154  }
155  }
156 
167  protected function ‪getElementValue(&$elementName)
168  {
169  $value = null;
170  if (!$this->objXml->isEmptyElement) {
171  $value = '';
172  while ($this->objXml->read()) {
173  if ($this->objXml->nodeType == \XMLReader::TEXT || $this->objXml->nodeType == \XMLReader::CDATA || $this->objXml->nodeType == \XMLReader::WHITESPACE || $this->objXml->nodeType == \XMLReader::SIGNIFICANT_WHITESPACE) {
174  $value .= $this->objXml->value;
175  } else {
176  if ($this->objXml->nodeType == \XMLReader::END_ELEMENT && $this->objXml->name === $elementName) {
177  break;
178  }
179  }
180  }
181  }
182  return $value;
183  }
184 }
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPullParser\startElement
‪startElement($elementName)
Definition: ExtensionXmlPullParser.php:79
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPullParser\parseXml
‪parseXml($file)
Definition: ExtensionXmlPullParser.php:48
‪TYPO3\CMS\Extensionmanager\Utility\Parser
Definition: AbstractExtensionXmlParser.php:2
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\convertDependencies
‪string convertDependencies($dependencies)
Definition: AbstractExtensionXmlParser.php:369
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPullParser\endElement
‪endElement($elementName)
Definition: ExtensionXmlPullParser.php:144
‪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\ExtensionXmlPullParser\__construct
‪__construct()
Definition: ExtensionXmlPullParser.php:29
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\resetProperties
‪resetProperties($resetAll=false)
Definition: AbstractExtensionXmlParser.php:352
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPullParser\getElementValue
‪string getElementValue(&$elementName)
Definition: ExtensionXmlPullParser.php:167
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPullParser\createParser
‪createParser()
Definition: ExtensionXmlPullParser.php:37
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPullParser
Definition: ExtensionXmlPullParser.php:25