TYPO3 CMS  TYPO3_6-2
ExtensionXmlPullParser.php
Go to the documentation of this file.
1 <?php
3 
30 
34  public function __construct() {
35  $this->requiredPhpExtensions = 'xmlreader';
36  }
37 
43  protected function createParser() {
44  $this->objXml = new \XMLReader();
45  }
46 
54  public function parseXml($file) {
55  $this->createParser();
56  if (!(is_object($this->objXml) && get_class($this->objXml) == 'XMLReader')) {
57  throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException('Unable to create XML parser.', 1342640540);
58  }
59  if ($this->objXml->open($file, 'utf-8') === FALSE) {
60  throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(sprintf('Unable to open file resource %s.', htmlspecialchars($file)));
61  }
62  while ($this->objXml->read()) {
63  if ($this->objXml->nodeType == \XMLReader::ELEMENT) {
64  $this->startElement($this->objXml->name);
65  } else {
66  if ($this->objXml->nodeType == \XMLReader::END_ELEMENT) {
67  $this->endElement($this->objXml->name);
68  } else {
69  continue;
70  }
71  }
72  }
73  $this->objXml->close();
74  }
75 
82  protected function startElement($elementName) {
83  switch ($elementName) {
84  case 'extension':
85  $this->extensionKey = $this->objXml->getAttribute('extensionkey');
86  break;
87  case 'version':
88  $this->version = $this->objXml->getAttribute('version');
89  break;
90  case 'downloadcounter':
91  // downloadcounter could be a child node of
92  // extension or version
93  if ($this->version == NULL) {
94  $this->extensionDownloadCounter = $this->getElementValue($elementName);
95  } else {
96  $this->versionDownloadCounter = $this->getElementValue($elementName);
97  }
98  break;
99  case 'title':
100  $this->title = $this->getElementValue($elementName);
101  break;
102  case 'description':
103  $this->description = $this->getElementValue($elementName);
104  break;
105  case 'state':
106  $this->state = $this->getElementValue($elementName);
107  break;
108  case 'reviewstate':
109  $this->reviewstate = $this->getElementValue($elementName);
110  break;
111  case 'category':
112  $this->category = $this->getElementValue($elementName);
113  break;
114  case 'lastuploaddate':
115  $this->lastuploaddate = $this->getElementValue($elementName);
116  break;
117  case 'uploadcomment':
118  $this->uploadcomment = $this->getElementValue($elementName);
119  break;
120  case 'dependencies':
121  $this->dependencies = $this->convertDependencies($this->getElementValue($elementName));
122  break;
123  case 'authorname':
124  $this->authorname = $this->getElementValue($elementName);
125  break;
126  case 'authoremail':
127  $this->authoremail = $this->getElementValue($elementName);
128  break;
129  case 'authorcompany':
130  $this->authorcompany = $this->getElementValue($elementName);
131  break;
132  case 'ownerusername':
133  $this->ownerusername = $this->getElementValue($elementName);
134  break;
135  case 't3xfilemd5':
136  $this->t3xfilemd5 = $this->getElementValue($elementName);
137  break;
138  }
139  }
140 
147  protected function endElement($elementName) {
148  switch ($elementName) {
149  case 'extension':
150  $this->resetProperties(TRUE);
151  break;
152  case 'version':
153  $this->notify();
154  $this->resetProperties();
155  break;
156  }
157  }
158 
169  protected function getElementValue(&$elementName) {
170  $value = NULL;
171  if (!$this->objXml->isEmptyElement) {
172  $value = '';
173  while ($this->objXml->read()) {
174  if ($this->objXml->nodeType == \XMLReader::TEXT || $this->objXml->nodeType == \XMLReader::CDATA || $this->objXml->nodeType == \XMLReader::WHITESPACE || $this->objXml->nodeType == \XMLReader::SIGNIFICANT_WHITESPACE) {
175  $value .= $this->objXml->value;
176  } else {
177  if ($this->objXml->nodeType == \XMLReader::END_ELEMENT && $this->objXml->name === $elementName) {
178  break;
179  }
180  }
181  }
182  }
183  return $value;
184  }
185 }