‪TYPO3CMS  10.4
MirrorXmlPullParser.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 {
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::class)) {
52  throw new ‪ExtensionManagerException('Unable to create XML parser.', 1342640820);
53  }
54  if ($this->objXml->open($file, 'utf-8') === false) {
55  throw new ‪ExtensionManagerException(sprintf('Unable to open file resource %s.', $file), 1342640893);
56  }
57  while ($this->objXml->read()) {
58  if ($this->objXml->nodeType == \XMLReader::ELEMENT) {
59  $this->‪startElement($this->objXml->name);
60  } else {
61  if ($this->objXml->nodeType == \XMLReader::END_ELEMENT) {
62  $this->‪endElement($this->objXml->name);
63  } else {
64  continue;
65  }
66  }
67  }
68  $this->objXml->close();
69  }
70 
77  protected function ‪startElement($elementName)
78  {
79  switch ($elementName) {
80  case 'title':
81  $this->title = $this->‪getElementValue($elementName);
82  break;
83  case 'host':
84  $this->host = $this->‪getElementValue($elementName);
85  break;
86  case 'path':
87  $this->path = $this->‪getElementValue($elementName);
88  break;
89  case 'country':
90  $this->country = $this->‪getElementValue($elementName);
91  break;
92  default:
93  // Do nothing
94  }
95  }
96 
103  protected function ‪endElement($elementName)
104  {
105  switch ($elementName) {
106  case 'mirror':
107  $this->‪notify();
108  $this->‪resetProperties();
109  break;
110  default:
111  // Do nothing
112  }
113  }
114 
125  protected function ‪getElementValue(&$elementName)
126  {
127  $value = null;
128  if (!$this->objXml->isEmptyElement) {
129  $value = '';
130  while ($this->objXml->read()) {
131  if ($this->objXml->nodeType == \XMLReader::TEXT || $this->objXml->nodeType == \XMLReader::CDATA || $this->objXml->nodeType == \XMLReader::WHITESPACE || $this->objXml->nodeType == \XMLReader::SIGNIFICANT_WHITESPACE) {
132  $value .= $this->objXml->value;
133  } else {
134  if ($this->objXml->nodeType == \XMLReader::END_ELEMENT && $this->objXml->name === $elementName) {
135  break;
136  }
137  }
138  }
139  }
140  return $value;
141  }
142 }
‪TYPO3\CMS\Extensionmanager\Utility\Parser\MirrorXmlPullParser\parseXml
‪parseXml($file)
Definition: MirrorXmlPullParser.php:48
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractMirrorXmlParser\resetProperties
‪resetProperties()
Definition: AbstractMirrorXmlParser.php:113
‪TYPO3\CMS\Extensionmanager\Utility\Parser
Definition: AbstractExtensionXmlParser.php:16
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractXmlParser\notify
‪notify()
Definition: AbstractXmlParser.php:76
‪TYPO3\CMS\Extensionmanager\Utility\Parser\MirrorXmlPullParser\startElement
‪startElement($elementName)
Definition: MirrorXmlPullParser.php:77
‪TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
Definition: ExtensionManagerException.php:24
‪TYPO3\CMS\Extensionmanager\Utility\Parser\MirrorXmlPullParser
Definition: MirrorXmlPullParser.php:28
‪TYPO3\CMS\Extensionmanager\Utility\Parser\MirrorXmlPullParser\endElement
‪endElement($elementName)
Definition: MirrorXmlPullParser.php:103
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractMirrorXmlParser
Definition: AbstractMirrorXmlParser.php:23
‪TYPO3\CMS\Extensionmanager\Utility\Parser\MirrorXmlPullParser\__construct
‪__construct()
Definition: MirrorXmlPullParser.php:29
‪TYPO3\CMS\Extensionmanager\Utility\Parser\MirrorXmlPullParser\getElementValue
‪string getElementValue(&$elementName)
Definition: MirrorXmlPullParser.php:125
‪TYPO3\CMS\Extensionmanager\Utility\Parser\MirrorXmlPullParser\createParser
‪createParser()
Definition: MirrorXmlPullParser.php:37