‪TYPO3CMS  10.4
ExtensionXmlPullParser.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 
28 {
32  public function ‪__construct()
33  {
34  $this->requiredPhpExtensions = 'xmlreader';
35  }
36 
40  protected function ‪createParser()
41  {
42  $this->objXml = new \XMLReader();
43  }
44 
51  public function ‪parseXml($file)
52  {
53  $this->‪createParser();
54  if (!(is_object($this->objXml) && get_class($this->objXml) === \XMLReader::class)) {
55  throw new ‪ExtensionManagerException('Unable to create XML parser.', 1342640540);
56  }
57  if ($this->objXml->open($file, 'utf-8') === false) {
59  sprintf('Unable to open file resource %s.', $file),
60  1476108651
61  );
62  }
63  while ($this->objXml->read()) {
64  if ($this->objXml->nodeType == \XMLReader::ELEMENT) {
65  $this->‪startElement($this->objXml->name);
66  } else {
67  if ($this->objXml->nodeType == \XMLReader::END_ELEMENT) {
68  $this->‪endElement($this->objXml->name);
69  } else {
70  continue;
71  }
72  }
73  }
74  $this->objXml->close();
75  }
76 
82  protected function ‪startElement($elementName)
83  {
84  switch ($elementName) {
85  case 'extension':
86  $this->extensionKey = $this->objXml->getAttribute('extensionkey');
87  break;
88  case 'version':
89  $this->version = $this->objXml->getAttribute('version');
90  break;
91  case 'downloadcounter':
92  // downloadcounter could be a child node of
93  // extension or version
94  if ($this->version == null) {
95  $this->extensionDownloadCounter = $this->‪getElementValue($elementName);
96  } else {
97  $this->versionDownloadCounter = $this->‪getElementValue($elementName);
98  }
99  break;
100  case 'title':
101  $this->title = $this->‪getElementValue($elementName);
102  break;
103  case 'description':
104  $this->description = $this->‪getElementValue($elementName);
105  break;
106  case 'state':
107  $this->state = $this->‪getElementValue($elementName);
108  break;
109  case 'reviewstate':
110  $this->reviewstate = $this->‪getElementValue($elementName);
111  break;
112  case 'category':
113  $this->category = $this->‪getElementValue($elementName);
114  break;
115  case 'lastuploaddate':
116  $this->lastuploaddate = $this->‪getElementValue($elementName);
117  break;
118  case 'uploadcomment':
119  $this->uploadcomment = $this->‪getElementValue($elementName);
120  break;
121  case 'dependencies':
122  $this->dependencies = $this->‪convertDependencies($this->‪getElementValue($elementName));
123  break;
124  case 'authorname':
125  $this->authorname = $this->‪getElementValue($elementName);
126  break;
127  case 'authoremail':
128  $this->authoremail = $this->‪getElementValue($elementName);
129  break;
130  case 'authorcompany':
131  $this->authorcompany = $this->‪getElementValue($elementName);
132  break;
133  case 'ownerusername':
134  $this->ownerusername = $this->‪getElementValue($elementName);
135  break;
136  case 't3xfilemd5':
137  $this->t3xfilemd5 = $this->‪getElementValue($elementName);
138  break;
139  case 'documentation_link':
140  $this->documentationLink = $this->‪getElementValue($elementName);
141  break;
142  }
143  }
144 
150  protected function ‪endElement($elementName)
151  {
152  switch ($elementName) {
153  case 'extension':
154  $this->‪resetProperties(true);
155  break;
156  case 'version':
157  $this->‪notify();
158  $this->‪resetProperties();
159  break;
160  }
161  }
162 
173  protected function ‪getElementValue(&$elementName)
174  {
175  $value = null;
176  if (!$this->objXml->isEmptyElement) {
177  $value = '';
178  while ($this->objXml->read()) {
179  if ($this->objXml->nodeType == \XMLReader::TEXT || $this->objXml->nodeType == \XMLReader::CDATA || $this->objXml->nodeType == \XMLReader::WHITESPACE || $this->objXml->nodeType == \XMLReader::SIGNIFICANT_WHITESPACE) {
180  $value .= $this->objXml->value;
181  } else {
182  if ($this->objXml->nodeType == \XMLReader::END_ELEMENT && $this->objXml->name === $elementName) {
183  break;
184  }
185  }
186  }
187  }
188  return $value;
189  }
190 }
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPullParser\startElement
‪startElement($elementName)
Definition: ExtensionXmlPullParser.php:82
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPullParser\parseXml
‪parseXml($file)
Definition: ExtensionXmlPullParser.php:51
‪TYPO3\CMS\Extensionmanager\Utility\Parser
Definition: AbstractExtensionXmlParser.php:16
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\convertDependencies
‪string convertDependencies($dependencies)
Definition: AbstractExtensionXmlParser.php:392
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPullParser\endElement
‪endElement($elementName)
Definition: ExtensionXmlPullParser.php:150
‪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\ExtensionXmlPullParser\__construct
‪__construct()
Definition: ExtensionXmlPullParser.php:32
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractExtensionXmlParser\resetProperties
‪resetProperties($resetAll=false)
Definition: AbstractExtensionXmlParser.php:375
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPullParser\getElementValue
‪string getElementValue(&$elementName)
Definition: ExtensionXmlPullParser.php:173
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPullParser\createParser
‪createParser()
Definition: ExtensionXmlPullParser.php:40
‪TYPO3\CMS\Extensionmanager\Utility\Parser\ExtensionXmlPullParser
Definition: ExtensionXmlPullParser.php:28