‪TYPO3CMS  9.5
MirrorXmlPullParser.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 {
26  public function ‪__construct()
27  {
28  $this->requiredPhpExtensions = 'xmlreader';
29  }
30 
34  protected function ‪createParser()
35  {
36  $this->objXml = new \XMLReader();
37  }
38 
45  public function ‪parseXml($file)
46  {
47  $this->‪createParser();
48  if (!(is_object($this->objXml) && get_class($this->objXml) === 'XMLReader')) {
49  throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException('Unable to create XML parser.', 1342640820);
50  }
51  if ($this->objXml->open($file, 'utf-8') === false) {
52  throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(sprintf('Unable to open file resource %s.', $file), 1342640893);
53  }
54  while ($this->objXml->read()) {
55  if ($this->objXml->nodeType == \XMLReader::ELEMENT) {
56  $this->‪startElement($this->objXml->name);
57  } else {
58  if ($this->objXml->nodeType == \XMLReader::END_ELEMENT) {
59  $this->‪endElement($this->objXml->name);
60  } else {
61  continue;
62  }
63  }
64  }
65  $this->objXml->close();
66  }
67 
74  protected function ‪startElement($elementName)
75  {
76  switch ($elementName) {
77  case 'title':
78  $this->title = $this->‪getElementValue($elementName);
79  break;
80  case 'host':
81  $this->host = $this->‪getElementValue($elementName);
82  break;
83  case 'path':
84  $this->path = $this->‪getElementValue($elementName);
85  break;
86  case 'country':
87  $this->country = $this->‪getElementValue($elementName);
88  break;
89  case 'name':
90  $this->sponsorname = $this->‪getElementValue($elementName);
91  break;
92  case 'link':
93  $this->sponsorlink = $this->‪getElementValue($elementName);
94  break;
95  case 'logo':
96  $this->sponsorlogo = $this->‪getElementValue($elementName);
97  break;
98  default:
99  // Do nothing
100  }
101  }
102 
109  protected function ‪endElement($elementName)
110  {
111  switch ($elementName) {
112  case 'mirror':
113  $this->‪notify();
114  $this->‪resetProperties();
115  break;
116  default:
117  // Do nothing
118  }
119  }
120 
131  protected function ‪getElementValue(&$elementName)
132  {
133  $value = null;
134  if (!$this->objXml->isEmptyElement) {
135  $value = '';
136  while ($this->objXml->read()) {
137  if ($this->objXml->nodeType == \XMLReader::TEXT || $this->objXml->nodeType == \XMLReader::CDATA || $this->objXml->nodeType == \XMLReader::WHITESPACE || $this->objXml->nodeType == \XMLReader::SIGNIFICANT_WHITESPACE) {
138  $value .= $this->objXml->value;
139  } else {
140  if ($this->objXml->nodeType == \XMLReader::END_ELEMENT && $this->objXml->name === $elementName) {
141  break;
142  }
143  }
144  }
145  }
146  return $value;
147  }
148 }
‪TYPO3\CMS\Extensionmanager\Utility\Parser\MirrorXmlPullParser\parseXml
‪parseXml($file)
Definition: MirrorXmlPullParser.php:45
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractMirrorXmlParser\resetProperties
‪resetProperties()
Definition: AbstractMirrorXmlParser.php:169
‪TYPO3\CMS\Extensionmanager\Utility\Parser
Definition: AbstractExtensionXmlParser.php:2
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractXmlParser\notify
‪notify()
Definition: AbstractXmlParser.php:72
‪TYPO3\CMS\Extensionmanager\Utility\Parser\MirrorXmlPullParser\startElement
‪startElement($elementName)
Definition: MirrorXmlPullParser.php:74
‪TYPO3\CMS\Extensionmanager\Utility\Parser\MirrorXmlPullParser
Definition: MirrorXmlPullParser.php:25
‪TYPO3\CMS\Extensionmanager\Utility\Parser\MirrorXmlPullParser\endElement
‪endElement($elementName)
Definition: MirrorXmlPullParser.php:109
‪TYPO3\CMS\Extensionmanager\Utility\Parser\AbstractMirrorXmlParser
Definition: AbstractMirrorXmlParser.php:22
‪TYPO3\CMS\Extensionmanager\Utility\Parser\MirrorXmlPullParser\__construct
‪__construct()
Definition: MirrorXmlPullParser.php:26
‪TYPO3\CMS\Extensionmanager\Utility\Parser\MirrorXmlPullParser\getElementValue
‪string getElementValue(&$elementName)
Definition: MirrorXmlPullParser.php:131
‪TYPO3\CMS\Extensionmanager\Utility\Parser\MirrorXmlPullParser\createParser
‪createParser()
Definition: MirrorXmlPullParser.php:34