72ce4be0d53b2e55c53e413c92e15983e3c13afd
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Utility / ExtensionModelUtility.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Utility;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2013 Susanne Moog <susanne.moog@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * Utility for dealing with extension model related helper functions
32 *
33 * @author Susanne Moog <susanne.moog@typo3.org>
34 */
35 class ExtensionModelUtility {
36
37 /**
38 * @var \TYPO3\CMS\Extbase\Object\ObjectManager
39 * @inject
40 */
41 protected $objectManager;
42
43 /**
44 * Map a legacy extension array to an object
45 *
46 * @param array $extensionArray
47 * @return \TYPO3\CMS\Extensionmanager\Domain\Model\Extension
48 */
49 public function mapExtensionArrayToModel(array $extensionArray) {
50 /** @var \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension */
51 $extension = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
52 $extension->setExtensionKey($extensionArray['key']);
53 if (isset($extensionArray['version'])) {
54 $extension->setVersion($extensionArray['version']);
55 }
56 if (isset($extensionArray['constraints'])) {
57 $extension->setDependencies($this->convertDependenciesToObjects(serialize($extensionArray['constraints'])));
58 }
59 return $extension;
60 }
61
62 /**
63 * Converts string dependencies to an object storage of dependencies
64 *
65 * @param string $dependencies
66 * @return \SplObjectStorage
67 */
68 public function convertDependenciesToObjects($dependencies) {
69 $dependenciesObject = new \SplObjectStorage();
70 $unserializedDependencies = unserialize($dependencies);
71 if (!is_array($unserializedDependencies)) {
72 return $dependenciesObject;
73 }
74 foreach ($unserializedDependencies as $dependencyType => $dependencyValues) {
75 // Dependencies might be given as empty string, e.g. conflicts => ''
76 if (!is_array($dependencyValues)) {
77 continue;
78 }
79 foreach ($dependencyValues as $dependency => $versions) {
80 if ($dependencyType && $dependency) {
81 $versionNumbers = \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionsStringToVersionNumbers($versions);
82 $lowest = $versionNumbers[0];
83 if (count($versionNumbers) === 2) {
84 $highest = $versionNumbers[1];
85 } else {
86 $highest = '';
87 }
88 /** @var $dependencyObject \TYPO3\CMS\Extensionmanager\Domain\Model\Dependency */
89 $dependencyObject = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency');
90 $dependencyObject->setType($dependencyType);
91 $dependencyObject->setIdentifier($dependency);
92 $dependencyObject->setLowestVersion($lowest);
93 $dependencyObject->setHighestVersion($highest);
94 $dependenciesObject->attach($dependencyObject);
95 unset($dependencyObject);
96 }
97 }
98 }
99 return $dependenciesObject;
100 }
101 }