|
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
|
|
|
|
|
16
|
|
|
namespace TYPO3\CMS\Extensionmanager\Utility\Parser; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Abstract parser for TYPO3's extension.xml file. |
|
20
|
|
|
* @internal This class is a specific ExtensionManager implementation and is not part of the Public TYPO3 API. |
|
21
|
|
|
*/ |
|
22
|
|
|
abstract class AbstractExtensionXmlParser implements \SplSubject |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Keeps XML parser instance. |
|
26
|
|
|
* |
|
27
|
|
|
* @var mixed |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $objXml; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Keeps name of required PHP extension |
|
33
|
|
|
* for this class to work properly. |
|
34
|
|
|
* |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $requiredPhpExtensions; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Keeps list of attached observers. |
|
41
|
|
|
* |
|
42
|
|
|
* @var \SplObserver[] |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $observers = []; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Method attaches an observer. |
|
48
|
|
|
* |
|
49
|
|
|
* @param \SplObserver $observer an observer to attach |
|
50
|
|
|
* @see detach() |
|
51
|
|
|
* @see notify() |
|
52
|
|
|
*/ |
|
53
|
|
|
public function attach(\SplObserver $observer) |
|
54
|
|
|
{ |
|
55
|
|
|
$this->observers[] = $observer; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Method detaches an attached observer |
|
60
|
|
|
* |
|
61
|
|
|
* @param \SplObserver $observer an observer to detach |
|
62
|
|
|
* @see attach() |
|
63
|
|
|
* @see notify() |
|
64
|
|
|
*/ |
|
65
|
|
|
public function detach(\SplObserver $observer) |
|
66
|
|
|
{ |
|
67
|
|
|
$key = array_search($observer, $this->observers, true); |
|
68
|
|
|
if ($key !== false) { |
|
69
|
|
|
unset($this->observers[$key]); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Method notifies attached observers. |
|
75
|
|
|
* |
|
76
|
|
|
* @see attach() |
|
77
|
|
|
* @see detach() |
|
78
|
|
|
*/ |
|
79
|
|
|
public function notify() |
|
80
|
|
|
{ |
|
81
|
|
|
foreach ($this->observers as $observer) { |
|
82
|
|
|
$observer->update($this); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Method determines if a necessary PHP extension is available. |
|
88
|
|
|
* |
|
89
|
|
|
* Method tries to load the extension if necessary and possible. |
|
90
|
|
|
* |
|
91
|
|
|
* @return bool TRUE, if PHP extension is available, otherwise FALSE |
|
92
|
|
|
*/ |
|
93
|
|
|
public function isAvailable() |
|
94
|
|
|
{ |
|
95
|
|
|
$isAvailable = true; |
|
96
|
|
|
if (!extension_loaded($this->requiredPhpExtensions)) { |
|
97
|
|
|
$prefix = PHP_SHLIB_SUFFIX === 'dll' ? 'php_' : ''; |
|
98
|
|
|
if (!(((bool)ini_get('enable_dl') && !(bool)ini_get('safe_mode')) && function_exists('dl') && dl($prefix . $this->requiredPhpExtensions . PHP_SHLIB_SUFFIX))) { |
|
99
|
|
|
$isAvailable = false; |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
return $isAvailable; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Method parses an XML file. |
|
107
|
|
|
* |
|
108
|
|
|
* @param string $file GZIP stream resource |
|
109
|
|
|
* @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException in case of XML parser errors |
|
110
|
|
|
*/ |
|
111
|
|
|
abstract public function parseXml($file); |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Create required parser |
|
115
|
|
|
*/ |
|
116
|
|
|
abstract protected function createParser(); |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Keeps current author company of an extension's version. |
|
120
|
|
|
* |
|
121
|
|
|
* @var string |
|
122
|
|
|
*/ |
|
123
|
|
|
protected $authorcompany; |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Keeps current author mail address of an extension's version. |
|
127
|
|
|
* |
|
128
|
|
|
* @var string |
|
129
|
|
|
*/ |
|
130
|
|
|
protected $authoremail; |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Keeps current author name of an extension's version. |
|
134
|
|
|
* |
|
135
|
|
|
* @var string |
|
136
|
|
|
*/ |
|
137
|
|
|
protected $authorname; |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Keeps current category of an extension's version. |
|
141
|
|
|
* |
|
142
|
|
|
* @var string |
|
143
|
|
|
*/ |
|
144
|
|
|
protected $category; |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* Keeps current dependencies of an extension's version. |
|
148
|
|
|
* |
|
149
|
|
|
* @var string |
|
150
|
|
|
*/ |
|
151
|
|
|
protected $dependencies; |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* Keeps current description of an extension's version. |
|
155
|
|
|
* |
|
156
|
|
|
* @var string |
|
157
|
|
|
*/ |
|
158
|
|
|
protected $description; |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* Keeps current download number sum of all extension's versions. |
|
162
|
|
|
* |
|
163
|
|
|
* @var string |
|
164
|
|
|
*/ |
|
165
|
|
|
protected $extensionDownloadCounter; |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Keeps current key of an extension. |
|
169
|
|
|
* |
|
170
|
|
|
* @var string |
|
171
|
|
|
*/ |
|
172
|
|
|
protected $extensionKey; |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* Keeps current upload date of an extension's version. |
|
176
|
|
|
* |
|
177
|
|
|
* @var string |
|
178
|
|
|
*/ |
|
179
|
|
|
protected $lastuploaddate; |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* Keeps current owner username of an extension's version. |
|
183
|
|
|
* |
|
184
|
|
|
* @var string |
|
185
|
|
|
*/ |
|
186
|
|
|
protected $ownerusername; |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* Keeps current reviewstate of an extension's version. |
|
190
|
|
|
* |
|
191
|
|
|
* @var string |
|
192
|
|
|
*/ |
|
193
|
|
|
protected $reviewstate; |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* Keeps current state of an extension's version. |
|
197
|
|
|
* |
|
198
|
|
|
* @var string |
|
199
|
|
|
*/ |
|
200
|
|
|
protected $state; |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* Keeps current t3x file hash of an extension's version. |
|
204
|
|
|
* |
|
205
|
|
|
* @var string |
|
206
|
|
|
*/ |
|
207
|
|
|
protected $t3xfilemd5; |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* Keeps current title of an extension's version. |
|
211
|
|
|
* |
|
212
|
|
|
* @var string |
|
213
|
|
|
*/ |
|
214
|
|
|
protected $title; |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* Keeps current upload comment of an extension's version. |
|
218
|
|
|
* |
|
219
|
|
|
* @var string |
|
220
|
|
|
*/ |
|
221
|
|
|
protected $uploadcomment; |
|
222
|
|
|
|
|
223
|
|
|
/** |
|
224
|
|
|
* Keeps current version number. |
|
225
|
|
|
* |
|
226
|
|
|
* @var string |
|
227
|
|
|
*/ |
|
228
|
|
|
protected $version; |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* Keeps current download number of an extension's version. |
|
232
|
|
|
* |
|
233
|
|
|
* @var string |
|
234
|
|
|
*/ |
|
235
|
|
|
protected $versionDownloadCounter; |
|
236
|
|
|
|
|
237
|
|
|
/** |
|
238
|
|
|
* Link to the documentation |
|
239
|
|
|
* |
|
240
|
|
|
* @var string |
|
241
|
|
|
*/ |
|
242
|
|
|
protected $documentationLink; |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* Returns an associative array of all extension version properties. |
|
246
|
|
|
* |
|
247
|
|
|
* Valid array keys of returned array are: |
|
248
|
|
|
* extkey, version, alldownloadcounter, downloadcounter, title, description, |
|
249
|
|
|
* state, reviewstate, category, lastuploaddate, uploadcomment, dependencies, |
|
250
|
|
|
* authorname, authoremail, authorcompany, ownerusername, t3xfilemd5 |
|
251
|
|
|
* |
|
252
|
|
|
* @return array associative array of an extension version's properties |
|
253
|
|
|
*/ |
|
254
|
|
|
public function getAll() |
|
255
|
|
|
{ |
|
256
|
|
|
$versionProperties = []; |
|
257
|
|
|
$versionProperties['extkey'] = $this->extensionKey; |
|
258
|
|
|
$versionProperties['version'] = $this->version; |
|
259
|
|
|
$versionProperties['alldownloadcounter'] = $this->extensionDownloadCounter; |
|
260
|
|
|
$versionProperties['downloadcounter'] = $this->versionDownloadCounter; |
|
261
|
|
|
$versionProperties['title'] = $this->title; |
|
262
|
|
|
$versionProperties['description'] = $this->description; |
|
263
|
|
|
$versionProperties['state'] = $this->state; |
|
264
|
|
|
$versionProperties['reviewstate'] = $this->reviewstate; |
|
265
|
|
|
$versionProperties['category'] = $this->category; |
|
266
|
|
|
$versionProperties['lastuploaddate'] = $this->lastuploaddate; |
|
267
|
|
|
$versionProperties['uploadcomment'] = $this->uploadcomment; |
|
268
|
|
|
$versionProperties['dependencies'] = $this->dependencies; |
|
269
|
|
|
$versionProperties['authorname'] = $this->authorname; |
|
270
|
|
|
$versionProperties['authoremail'] = $this->authoremail; |
|
271
|
|
|
$versionProperties['authorcompany'] = $this->authorcompany; |
|
272
|
|
|
$versionProperties['ownerusername'] = $this->ownerusername; |
|
273
|
|
|
$versionProperties['t3xfilemd5'] = $this->t3xfilemd5; |
|
274
|
|
|
$versionProperties['documentationlink'] = $this->documentationLink; |
|
275
|
|
|
return $versionProperties; |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
/** |
|
279
|
|
|
* Returns download number sum of all extension's versions. |
|
280
|
|
|
* |
|
281
|
|
|
* @return string download number sum |
|
282
|
|
|
* @see getAll() |
|
283
|
|
|
*/ |
|
284
|
|
|
public function getAlldownloadcounter() |
|
285
|
|
|
{ |
|
286
|
|
|
return $this->extensionDownloadCounter; |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
|
|
/** |
|
290
|
|
|
* Returns company name of extension author. |
|
291
|
|
|
* |
|
292
|
|
|
* @return string company name of extension author |
|
293
|
|
|
* @see getAll() |
|
294
|
|
|
*/ |
|
295
|
|
|
public function getAuthorcompany() |
|
296
|
|
|
{ |
|
297
|
|
|
return $this->authorcompany; |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
/** |
|
301
|
|
|
* Returns e-mail address of extension author. |
|
302
|
|
|
* |
|
303
|
|
|
* @return string e-mail address of extension author |
|
304
|
|
|
* @see getAll() |
|
305
|
|
|
*/ |
|
306
|
|
|
public function getAuthoremail() |
|
307
|
|
|
{ |
|
308
|
|
|
return $this->authoremail; |
|
309
|
|
|
} |
|
310
|
|
|
|
|
311
|
|
|
/** |
|
312
|
|
|
* Returns name of extension author. |
|
313
|
|
|
* |
|
314
|
|
|
* @return string name of extension author |
|
315
|
|
|
* @see getAll() |
|
316
|
|
|
*/ |
|
317
|
|
|
public function getAuthorname() |
|
318
|
|
|
{ |
|
319
|
|
|
return $this->authorname; |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
/** |
|
323
|
|
|
* Returns category of an extension. |
|
324
|
|
|
* |
|
325
|
|
|
* @return string extension category |
|
326
|
|
|
* @see getAll() |
|
327
|
|
|
*/ |
|
328
|
|
|
public function getCategory() |
|
329
|
|
|
{ |
|
330
|
|
|
return $this->category; |
|
331
|
|
|
} |
|
332
|
|
|
|
|
333
|
|
|
/** |
|
334
|
|
|
* Returns dependencies of an extension's version. |
|
335
|
|
|
* |
|
336
|
|
|
* @return string extension dependencies |
|
337
|
|
|
* @see getAll() |
|
338
|
|
|
*/ |
|
339
|
|
|
public function getDependencies() |
|
340
|
|
|
{ |
|
341
|
|
|
return $this->dependencies; |
|
342
|
|
|
} |
|
343
|
|
|
|
|
344
|
|
|
/** |
|
345
|
|
|
* Returns description of an extension's version. |
|
346
|
|
|
* |
|
347
|
|
|
* @return string extension description |
|
348
|
|
|
* @see getAll() |
|
349
|
|
|
*/ |
|
350
|
|
|
public function getDescription() |
|
351
|
|
|
{ |
|
352
|
|
|
return $this->description; |
|
353
|
|
|
} |
|
354
|
|
|
|
|
355
|
|
|
/** |
|
356
|
|
|
* Returns download number of an extension's version. |
|
357
|
|
|
* |
|
358
|
|
|
* @return string download number |
|
359
|
|
|
* @see getAll() |
|
360
|
|
|
*/ |
|
361
|
|
|
public function getDownloadcounter() |
|
362
|
|
|
{ |
|
363
|
|
|
return $this->versionDownloadCounter; |
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
|
|
/** |
|
367
|
|
|
* Returns key of an extension. |
|
368
|
|
|
* |
|
369
|
|
|
* @return string extension key |
|
370
|
|
|
* @see getAll() |
|
371
|
|
|
*/ |
|
372
|
|
|
public function getExtkey() |
|
373
|
|
|
{ |
|
374
|
|
|
return $this->extensionKey; |
|
375
|
|
|
} |
|
376
|
|
|
|
|
377
|
|
|
/** |
|
378
|
|
|
* Returns last uploaddate of an extension's version. |
|
379
|
|
|
* |
|
380
|
|
|
* @return string last upload date of an extension's version |
|
381
|
|
|
* @see getAll() |
|
382
|
|
|
*/ |
|
383
|
|
|
public function getLastuploaddate() |
|
384
|
|
|
{ |
|
385
|
|
|
return $this->lastuploaddate; |
|
386
|
|
|
} |
|
387
|
|
|
|
|
388
|
|
|
/** |
|
389
|
|
|
* Returns username of extension owner. |
|
390
|
|
|
* |
|
391
|
|
|
* @return string extension owner's username |
|
392
|
|
|
* @see getAll() |
|
393
|
|
|
*/ |
|
394
|
|
|
public function getOwnerusername() |
|
395
|
|
|
{ |
|
396
|
|
|
return $this->ownerusername; |
|
397
|
|
|
} |
|
398
|
|
|
|
|
399
|
|
|
/** |
|
400
|
|
|
* Returns review state of an extension's version. |
|
401
|
|
|
* |
|
402
|
|
|
* @return string extension review state |
|
403
|
|
|
* @see getAll() |
|
404
|
|
|
*/ |
|
405
|
|
|
public function getReviewstate() |
|
406
|
|
|
{ |
|
407
|
|
|
return $this->reviewstate; |
|
408
|
|
|
} |
|
409
|
|
|
|
|
410
|
|
|
/** |
|
411
|
|
|
* Returns state of an extension's version. |
|
412
|
|
|
* |
|
413
|
|
|
* @return string extension state |
|
414
|
|
|
* @see getAll() |
|
415
|
|
|
*/ |
|
416
|
|
|
public function getState() |
|
417
|
|
|
{ |
|
418
|
|
|
return $this->state; |
|
419
|
|
|
} |
|
420
|
|
|
|
|
421
|
|
|
/** |
|
422
|
|
|
* Returns t3x file hash of an extension's version. |
|
423
|
|
|
* |
|
424
|
|
|
* @return string t3x file hash |
|
425
|
|
|
* @see getAll() |
|
426
|
|
|
*/ |
|
427
|
|
|
public function getT3xfilemd5() |
|
428
|
|
|
{ |
|
429
|
|
|
return $this->t3xfilemd5; |
|
430
|
|
|
} |
|
431
|
|
|
|
|
432
|
|
|
/** |
|
433
|
|
|
* Returns title of an extension's version. |
|
434
|
|
|
* |
|
435
|
|
|
* @return string extension title |
|
436
|
|
|
* @see getAll() |
|
437
|
|
|
*/ |
|
438
|
|
|
public function getTitle() |
|
439
|
|
|
{ |
|
440
|
|
|
return $this->title; |
|
441
|
|
|
} |
|
442
|
|
|
|
|
443
|
|
|
/** |
|
444
|
|
|
* Returns extension upload comment. |
|
445
|
|
|
* |
|
446
|
|
|
* @return string extension upload comment |
|
447
|
|
|
* @see getAll() |
|
448
|
|
|
*/ |
|
449
|
|
|
public function getUploadcomment() |
|
450
|
|
|
{ |
|
451
|
|
|
return $this->uploadcomment; |
|
452
|
|
|
} |
|
453
|
|
|
|
|
454
|
|
|
/** |
|
455
|
|
|
* Returns version number. |
|
456
|
|
|
* |
|
457
|
|
|
* @return string version number |
|
458
|
|
|
* @see getAll() |
|
459
|
|
|
*/ |
|
460
|
|
|
public function getVersion() |
|
461
|
|
|
{ |
|
462
|
|
|
return $this->version; |
|
463
|
|
|
} |
|
464
|
|
|
|
|
465
|
|
|
/** |
|
466
|
|
|
* @return string |
|
467
|
|
|
*/ |
|
468
|
|
|
public function getDocumentationLink() |
|
469
|
|
|
{ |
|
470
|
|
|
return $this->documentationLink; |
|
471
|
|
|
} |
|
472
|
|
|
|
|
473
|
|
|
/** |
|
474
|
|
|
* Method resets version class properties. |
|
475
|
|
|
* |
|
476
|
|
|
* @param bool $resetAll If TRUE, additionally extension properties are reset |
|
477
|
|
|
*/ |
|
478
|
|
|
protected function resetProperties($resetAll = false) |
|
479
|
|
|
{ |
|
480
|
|
|
// resetting at least class property "version" is mandatory |
|
481
|
|
|
// as we need to do some magic in regards to |
|
482
|
|
|
// an extension's and version's child node "downloadcounter" |
|
483
|
|
|
$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 = $this->documentationLink = null; |
|
484
|
|
|
if ($resetAll) { |
|
485
|
|
|
$this->extensionKey = $this->extensionDownloadCounter = null; |
|
486
|
|
|
} |
|
487
|
|
|
} |
|
488
|
|
|
|
|
489
|
|
|
/** |
|
490
|
|
|
* Convert dependencies from TER format to EM_CONF format |
|
491
|
|
|
* |
|
492
|
|
|
* @param string $dependencies serialized dependency array |
|
493
|
|
|
* @return string |
|
494
|
|
|
*/ |
|
495
|
|
|
protected function convertDependencies($dependencies) |
|
496
|
|
|
{ |
|
497
|
|
|
$newDependencies = []; |
|
498
|
|
|
$dependenciesArray = unserialize($dependencies, ['allowed_classes' => false]); |
|
499
|
|
|
if (is_array($dependenciesArray)) { |
|
500
|
|
|
foreach ($dependenciesArray as $version) { |
|
501
|
|
|
if (!empty($version['kind']) && !empty($version['extensionKey'])) { |
|
502
|
|
|
$newDependencies[$version['kind']][$version['extensionKey']] = $version['versionRange']; |
|
503
|
|
|
} |
|
504
|
|
|
} |
|
505
|
|
|
} |
|
506
|
|
|
return serialize($newDependencies); |
|
507
|
|
|
} |
|
508
|
|
|
} |
|
509
|
|
|
|