|
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; |
|
17
|
|
|
|
|
18
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
19
|
|
|
use TYPO3\CMS\Core\Utility\VersionNumberUtility; |
|
20
|
|
|
use TYPO3\CMS\Extensionmanager\Domain\Model\Dependency; |
|
21
|
|
|
use TYPO3\CMS\Extensionmanager\Domain\Model\Extension; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Utility for dealing with extension model related helper functions |
|
25
|
|
|
* @internal This class is a specific ExtensionManager implementation and is not part of the Public TYPO3 API. |
|
26
|
|
|
*/ |
|
27
|
|
|
class ExtensionModelUtility |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* Map a legacy extension array to an object |
|
31
|
|
|
* |
|
32
|
|
|
* @param array $extensionArray |
|
33
|
|
|
* @return Extension |
|
34
|
|
|
*/ |
|
35
|
|
|
public function mapExtensionArrayToModel(array $extensionArray) |
|
36
|
|
|
{ |
|
37
|
|
|
$extension = GeneralUtility::makeInstance(Extension::class); |
|
38
|
|
|
$extension->setExtensionKey($extensionArray['key']); |
|
39
|
|
|
if (isset($extensionArray['version'])) { |
|
40
|
|
|
$extension->setVersion($extensionArray['version']); |
|
41
|
|
|
} |
|
42
|
|
|
if (isset($extensionArray['constraints'])) { |
|
43
|
|
|
$extension->setDependencies($this->convertDependenciesToObjects(serialize($extensionArray['constraints']))); |
|
44
|
|
|
} |
|
45
|
|
|
return $extension; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Converts string dependencies to an object storage of dependencies |
|
50
|
|
|
* |
|
51
|
|
|
* @param string $dependencies |
|
52
|
|
|
* @return \SplObjectStorage |
|
53
|
|
|
*/ |
|
54
|
|
|
public function convertDependenciesToObjects($dependencies) |
|
55
|
|
|
{ |
|
56
|
|
|
$dependenciesObject = new \SplObjectStorage(); |
|
57
|
|
|
$unserializedDependencies = unserialize($dependencies, ['allowed_classes' => false]); |
|
58
|
|
|
if (!is_array($unserializedDependencies)) { |
|
59
|
|
|
return $dependenciesObject; |
|
60
|
|
|
} |
|
61
|
|
|
foreach ($unserializedDependencies as $dependencyType => $dependencyValues) { |
|
62
|
|
|
// Dependencies might be given as empty string, e.g. conflicts => '' |
|
63
|
|
|
if (!is_array($dependencyValues)) { |
|
64
|
|
|
continue; |
|
65
|
|
|
} |
|
66
|
|
|
foreach ($dependencyValues as $dependency => $versions) { |
|
67
|
|
|
if ($dependencyType && $dependency) { |
|
68
|
|
|
$versionNumbers = VersionNumberUtility::convertVersionsStringToVersionNumbers($versions); |
|
69
|
|
|
$lowest = $versionNumbers[0]; |
|
70
|
|
|
if (count($versionNumbers) === 2) { |
|
71
|
|
|
$highest = $versionNumbers[1]; |
|
72
|
|
|
} else { |
|
73
|
|
|
$highest = ''; |
|
74
|
|
|
} |
|
75
|
|
|
$dependencyObject = GeneralUtility::makeInstance(Dependency::class); |
|
76
|
|
|
$dependencyObject->setType($dependencyType); |
|
77
|
|
|
// dynamically migrate 'cms' dependency to 'core' dependency |
|
78
|
|
|
// see also \TYPO3\CMS\Core\Package\Package::getPackageMetaData |
|
79
|
|
|
$dependencyObject->setIdentifier($dependency === 'cms' ? 'core' : $dependency); |
|
80
|
|
|
$dependencyObject->setLowestVersion($lowest); |
|
81
|
|
|
$dependencyObject->setHighestVersion($highest); |
|
82
|
|
|
$dependenciesObject->attach($dependencyObject); |
|
83
|
|
|
unset($dependencyObject); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
return $dependenciesObject; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|