TYPO3  7.6
ExtensionXmlPushParser.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Utility\Parser;
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 
32 {
38  protected $element = null;
39 
43  public function __construct()
44  {
45  $this->requiredPhpExtensions = 'xml';
46  }
47 
53  protected function createParser()
54  {
55  $this->objXml = xml_parser_create();
56  xml_set_object($this->objXml, $this);
57  }
58 
66  public function parseXml($file)
67  {
68  $this->createParser();
69  if (!is_resource($this->objXml)) {
70  throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException('Unable to create XML parser.', 1342640663);
71  }
72  // keep original character case of XML document
73  xml_parser_set_option($this->objXml, XML_OPTION_CASE_FOLDING, false);
74  xml_parser_set_option($this->objXml, XML_OPTION_SKIP_WHITE, false);
75  xml_parser_set_option($this->objXml, XML_OPTION_TARGET_ENCODING, 'utf-8');
76  xml_set_element_handler($this->objXml, 'startElement', 'endElement');
77  xml_set_character_data_handler($this->objXml, 'characterData');
78  if (!($fp = fopen($file, 'r'))) {
79  throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(sprintf('Unable to open file resource %s.', $file), 1342640689);
80  }
81  while ($data = fread($fp, 4096)) {
82  if (!xml_parse($this->objXml, $data, feof($fp))) {
83  throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(sprintf('XML error %s in line %u of file resource %s.', xml_error_string(xml_get_error_code($this->objXml)), xml_get_current_line_number($this->objXml), $file), 1342640703);
84  }
85  }
86  xml_parser_free($this->objXml);
87  }
88 
97  protected function startElement($parser, $elementName, $attrs)
98  {
99  switch ($elementName) {
100  case 'extension':
101  $this->extensionKey = $attrs['extensionkey'];
102  break;
103  case 'version':
104  $this->version = $attrs['version'];
105  break;
106  default:
107  $this->element = $elementName;
108  }
109  }
110 
118  protected function endElement($parser, $elementName)
119  {
120  switch ($elementName) {
121  case 'extension':
122  $this->resetProperties(true);
123  break;
124  case 'version':
125  $this->notify();
126  $this->resetProperties();
127  break;
128  default:
129  $this->element = null;
130  }
131  }
132 
140  protected function characterData($parser, $data)
141  {
142  if (isset($this->element)) {
143  switch ($this->element) {
144  case 'downloadcounter':
145  // downloadcounter could be a child node of
146  // extension or version
147  if ($this->version == null) {
148  $this->extensionDownloadCounter = $data;
149  } else {
150  $this->versionDownloadCounter = $data;
151  }
152  break;
153  case 'title':
154  $this->title = $data;
155  break;
156  case 'description':
157  $this->description = $data;
158  break;
159  case 'state':
160  $this->state = $data;
161  break;
162  case 'reviewstate':
163  $this->reviewstate = $data;
164  break;
165  case 'category':
166  $this->category = $data;
167  break;
168  case 'lastuploaddate':
169  $this->lastuploaddate = $data;
170  break;
171  case 'uploadcomment':
172  $this->uploadcomment = $data;
173  break;
174  case 'dependencies':
175  $this->dependencies = $this->convertDependencies($data);
176  break;
177  case 'authorname':
178  $this->authorname = $data;
179  break;
180  case 'authoremail':
181  $this->authoremail = $data;
182  break;
183  case 'authorcompany':
184  $this->authorcompany = $data;
185  break;
186  case 'ownerusername':
187  $this->ownerusername = $data;
188  break;
189  case 't3xfilemd5':
190  $this->t3xfilemd5 = $data;
191  break;
192  }
193  }
194  }
195 }