[TASK] Re-work/simplify copyright header in PHP files - Part 9
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Utility / ExtensionModelUtility.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Utility;
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 * Utility for dealing with extension model related helper functions
19 *
20 * @author Susanne Moog <susanne.moog@typo3.org>
21 */
22 class ExtensionModelUtility {
23
24 /**
25 * @var \TYPO3\CMS\Extbase\Object\ObjectManager
26 * @inject
27 */
28 protected $objectManager;
29
30 /**
31 * Map a legacy extension array to an object
32 *
33 * @param array $extensionArray
34 * @return \TYPO3\CMS\Extensionmanager\Domain\Model\Extension
35 */
36 public function mapExtensionArrayToModel(array $extensionArray) {
37 /** @var \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension */
38 $extension = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
39 $extension->setExtensionKey($extensionArray['key']);
40 if (isset($extensionArray['version'])) {
41 $extension->setVersion($extensionArray['version']);
42 }
43 if (isset($extensionArray['constraints'])) {
44 $extension->setDependencies($this->convertDependenciesToObjects(serialize($extensionArray['constraints'])));
45 }
46 return $extension;
47 }
48
49 /**
50 * Converts string dependencies to an object storage of dependencies
51 *
52 * @param string $dependencies
53 * @return \SplObjectStorage
54 */
55 public function convertDependenciesToObjects($dependencies) {
56 $dependenciesObject = new \SplObjectStorage();
57 $unserializedDependencies = unserialize($dependencies);
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 = \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionsStringToVersionNumbers($versions);
69 $lowest = $versionNumbers[0];
70 if (count($versionNumbers) === 2) {
71 $highest = $versionNumbers[1];
72 } else {
73 $highest = '';
74 }
75 /** @var $dependencyObject \TYPO3\CMS\Extensionmanager\Domain\Model\Dependency */
76 $dependencyObject = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency');
77 $dependencyObject->setType($dependencyType);
78 $dependencyObject->setIdentifier($dependency);
79 $dependencyObject->setLowestVersion($lowest);
80 $dependencyObject->setHighestVersion($highest);
81 $dependenciesObject->attach($dependencyObject);
82 unset($dependencyObject);
83 }
84 }
85 }
86 return $dependenciesObject;
87 }
88 }