1<?php
2namespace 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
17/**
18 * Abstract parser for TYPO3's extension.xml file.
19 * @internal This class is a specific ExtensionManager implementation and is not part of the Public TYPO3 API.
20 */
21abstract class AbstractExtensionXmlParser extends AbstractXmlParser
22{
23    /**
24     * Keeps current author company of an extension's version.
25     *
26     * @var string
27     */
28    protected $authorcompany;
29
30    /**
31     * Keeps current author mail address of an extension's version.
32     *
33     * @var string
34     */
35    protected $authoremail;
36
37    /**
38     * Keeps current author name of an extension's version.
39     *
40     * @var string
41     */
42    protected $authorname;
43
44    /**
45     * Keeps current category of an extension's version.
46     *
47     * @var string
48     */
49    protected $category;
50
51    /**
52     * Keeps current dependencies of an extension's version.
53     *
54     * @var string
55     */
56    protected $dependencies;
57
58    /**
59     * Keeps current description of an extension's version.
60     *
61     * @var string
62     */
63    protected $description;
64
65    /**
66     * Keeps current download number sum of all extension's versions.
67     *
68     * @var string
69     */
70    protected $extensionDownloadCounter;
71
72    /**
73     * Keeps current key of an extension.
74     *
75     * @var string
76     */
77    protected $extensionKey;
78
79    /**
80     * Keeps current upload date of an extension's version.
81     *
82     * @var string
83     */
84    protected $lastuploaddate;
85
86    /**
87     * Keeps current owner username of an extension's version.
88     *
89     * @var string
90     */
91    protected $ownerusername;
92
93    /**
94     * Keeps current reviewstate of an extension's version.
95     *
96     * @var string
97     */
98    protected $reviewstate;
99
100    /**
101     * Keeps current state of an extension's version.
102     *
103     * @var string
104     */
105    protected $state;
106
107    /**
108     * Keeps current t3x file hash of an extension's version.
109     *
110     * @var string
111     */
112    protected $t3xfilemd5;
113
114    /**
115     * Keeps current title of an extension's version.
116     *
117     * @var string
118     */
119    protected $title;
120
121    /**
122     * Keeps current upload comment of an extension's version.
123     *
124     * @var string
125     */
126    protected $uploadcomment;
127
128    /**
129     * Keeps current version number.
130     *
131     * @var string
132     */
133    protected $version;
134
135    /**
136     * Keeps current download number of an extension's version.
137     *
138     * @var string
139     */
140    protected $versionDownloadCounter;
141
142    /**
143     * Returns an assoziative array of all extension version properties.
144     *
145     * Valid array keys of returned array are:
146     * extkey, version, alldownloadcounter, downloadcounter, title, description,
147     * state, reviewstate, category, lastuploaddate, uploadcomment, dependencies,
148     * authorname, authoremail, authorcompany, ownerusername, t3xfilemd5
149     *
150     * @see $extensionKey, $version, $extensionDownloadCounter,
151     * @return array assoziative array of an extension version's properties
152     */
153    public function getAll()
154    {
155        $versionProperties = [];
156        $versionProperties['extkey'] = $this->extensionKey;
157        $versionProperties['version'] = $this->version;
158        $versionProperties['alldownloadcounter'] = $this->extensionDownloadCounter;
159        $versionProperties['downloadcounter'] = $this->versionDownloadCounter;
160        $versionProperties['title'] = $this->title;
161        $versionProperties['description'] = $this->description;
162        $versionProperties['state'] = $this->state;
163        $versionProperties['reviewstate'] = $this->reviewstate;
164        $versionProperties['category'] = $this->category;
165        $versionProperties['lastuploaddate'] = $this->lastuploaddate;
166        $versionProperties['uploadcomment'] = $this->uploadcomment;
167        $versionProperties['dependencies'] = $this->dependencies;
168        $versionProperties['authorname'] = $this->authorname;
169        $versionProperties['authoremail'] = $this->authoremail;
170        $versionProperties['authorcompany'] = $this->authorcompany;
171        $versionProperties['ownerusername'] = $this->ownerusername;
172        $versionProperties['t3xfilemd5'] = $this->t3xfilemd5;
173        return $versionProperties;
174    }
175
176    /**
177     * Returns download number sum of all extension's versions.
178     *
179     * @return string download number sum
180     * @see $extensionDLCounter, getAll()
181     */
182    public function getAlldownloadcounter()
183    {
184        return $this->extensionDownloadCounter;
185    }
186
187    /**
188     * Returns company name of extension author.
189     *
190     * @return string company name of extension author
191     * @see $authorcompany, getAll()
192     */
193    public function getAuthorcompany()
194    {
195        return $this->authorcompany;
196    }
197
198    /**
199     * Returns e-mail address of extension author.
200     *
201     * @return string e-mail address of extension author
202     * @see $authoremail, getAll()
203     */
204    public function getAuthoremail()
205    {
206        return $this->authoremail;
207    }
208
209    /**
210     * Returns name of extension author.
211     *
212     * @return string name of extension author
213     * @see $authorname, getAll()
214     */
215    public function getAuthorname()
216    {
217        return $this->authorname;
218    }
219
220    /**
221     * Returns category of an extension.
222     *
223     * @return string extension category
224     * @see $category, getAll()
225     */
226    public function getCategory()
227    {
228        return $this->category;
229    }
230
231    /**
232     * Returns dependencies of an extension's version.
233     *
234     * @return string extension dependencies
235     * @see $dependencies, getAll()
236     */
237    public function getDependencies()
238    {
239        return $this->dependencies;
240    }
241
242    /**
243     * Returns description of an extension's version.
244     *
245     * @return string extension description
246     * @see $description, getAll()
247     */
248    public function getDescription()
249    {
250        return $this->description;
251    }
252
253    /**
254     * Returns download number of an extension's version.
255     *
256     * @return string download number
257     * @see $versionDLCounter, getAll()
258     */
259    public function getDownloadcounter()
260    {
261        return $this->versionDownloadCounter;
262    }
263
264    /**
265     * Returns key of an extension.
266     *
267     * @return string extension key
268     * @see $extensionKey, getAll()
269     */
270    public function getExtkey()
271    {
272        return $this->extensionKey;
273    }
274
275    /**
276     * Returns last uploaddate of an extension's version.
277     *
278     * @return string last upload date of an extension's version
279     * @see $lastuploaddate, getAll()
280     */
281    public function getLastuploaddate()
282    {
283        return $this->lastuploaddate;
284    }
285
286    /**
287     * Returns username of extension owner.
288     *
289     * @return string extension owner's username
290     * @see $ownerusername, getAll()
291     */
292    public function getOwnerusername()
293    {
294        return $this->ownerusername;
295    }
296
297    /**
298     * Returns review state of an extension's version.
299     *
300     * @return string extension review state
301     * @see $reviewstate, getAll()
302     */
303    public function getReviewstate()
304    {
305        return $this->reviewstate;
306    }
307
308    /**
309     * Returns state of an extension's version.
310     *
311     * @return string extension state
312     * @see $state, getAll()
313     */
314    public function getState()
315    {
316        return $this->state;
317    }
318
319    /**
320     * Returns t3x file hash of an extension's version.
321     *
322     * @return string t3x file hash
323     * @see $t3xfilemd5, getAll()
324     */
325    public function getT3xfilemd5()
326    {
327        return $this->t3xfilemd5;
328    }
329
330    /**
331     * Returns title of an extension's version.
332     *
333     * @return string extension title
334     * @see $title, getAll()
335     */
336    public function getTitle()
337    {
338        return $this->title;
339    }
340
341    /**
342     * Returns extension upload comment.
343     *
344     * @return string extension upload comment
345     * @see $uploadcomment, getAll()
346     */
347    public function getUploadcomment()
348    {
349        return $this->uploadcomment;
350    }
351
352    /**
353     * Returns version number.
354     *
355     * @return string version number
356     * @see $version, getAll()
357     */
358    public function getVersion()
359    {
360        return $this->version;
361    }
362
363    /**
364     * Method resets version class properties.
365     *
366     * @param bool $resetAll If TRUE, additionally extension properties are reset
367     * @see $extensionKey, $version, $extensionDLCounter, $versionDLCounter,
368     */
369    protected function resetProperties($resetAll = false)
370    {
371        // resetting at least class property "version" is mandatory
372        // as we need to do some magic in regards to
373        // an extension's and version's child node "downloadcounter"
374        $this->version = $this->title = $this->versionDownloadCounter = $this->description = $this->state = $this->reviewstate = $this->category = $this->lastuploaddate = $this->uploadcomment = $this->dependencies = $this->authorname = $this->authoremail = $this->authorcompany = $this->ownerusername = $this->t3xfilemd5 = null;
375        if ($resetAll) {
376            $this->extensionKey = $this->extensionDownloadCounter = null;
377        }
378    }
379
380    /**
381     * Convert dependencies from TER format to EM_CONF format
382     *
383     * @param string $dependencies serialized dependency array
384     * @return string
385     */
386    protected function convertDependencies($dependencies)
387    {
388        $newDependencies = [];
389        $dependenciesArray = unserialize($dependencies, ['allowed_classes' => false]);
390        if (is_array($dependenciesArray)) {
391            foreach ($dependenciesArray as $version) {
392                if (!empty($version['kind']) && !empty($version['extensionKey'])) {
393                    $newDependencies[$version['kind']][$version['extensionKey']] = $version['versionRange'];
394                }
395            }
396        }
397        return serialize($newDependencies);
398    }
399}
400