TYPO3 CMS  TYPO3_8-7
ExtensionModelUtility.php
Go to the documentation of this file.
1 <?php
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 
21 {
25  protected $objectManager;
26 
30  public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManager $objectManager)
31  {
32  $this->objectManager = $objectManager;
33  }
34 
41  public function mapExtensionArrayToModel(array $extensionArray)
42  {
44  $extension = $this->objectManager->get(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
45  $extension->setExtensionKey($extensionArray['key']);
46  if (isset($extensionArray['version'])) {
47  $extension->setVersion($extensionArray['version']);
48  }
49  if (isset($extensionArray['constraints'])) {
50  $extension->setDependencies($this->convertDependenciesToObjects(serialize($extensionArray['constraints'])));
51  }
52  return $extension;
53  }
54 
61  public function convertDependenciesToObjects($dependencies)
62  {
63  $dependenciesObject = new \SplObjectStorage();
64  $unserializedDependencies = unserialize($dependencies, ['allowed_classes' => false]);
65  if (!is_array($unserializedDependencies)) {
66  return $dependenciesObject;
67  }
68  foreach ($unserializedDependencies as $dependencyType => $dependencyValues) {
69  // Dependencies might be given as empty string, e.g. conflicts => ''
70  if (!is_array($dependencyValues)) {
71  continue;
72  }
73  foreach ($dependencyValues as $dependency => $versions) {
74  if ($dependencyType && $dependency) {
76  $lowest = $versionNumbers[0];
77  if (count($versionNumbers) === 2) {
78  $highest = $versionNumbers[1];
79  } else {
80  $highest = '';
81  }
83  $dependencyObject = $this->objectManager->get(\TYPO3\CMS\Extensionmanager\Domain\Model\Dependency::class);
84  $dependencyObject->setType($dependencyType);
85  // dynamically migrate 'cms' dependency to 'core' dependency
86  // see also \TYPO3\CMS\Core\Package\Package::getPackageMetaData
87  $dependencyObject->setIdentifier($dependency === 'cms' ? 'core' : $dependency);
88  $dependencyObject->setLowestVersion($lowest);
89  $dependencyObject->setHighestVersion($highest);
90  $dependenciesObject->attach($dependencyObject);
91  unset($dependencyObject);
92  }
93  }
94  }
95  return $dependenciesObject;
96  }
97 }
static convertVersionsStringToVersionNumbers($versionsString)
injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManager $objectManager)