‪TYPO3CMS  10.4
ExtensionModelUtility.php
Go to the documentation of this file.
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 
17 
22 
28 {
32  protected ‪$objectManager;
33 
38  {
39  $this->objectManager = ‪$objectManager;
40  }
41 
48  public function ‪mapExtensionArrayToModel(array $extensionArray)
49  {
50  $extension = $this->objectManager->get(Extension::class);
51  $extension->‪setExtensionKey($extensionArray['key']);
52  if (isset($extensionArray['version'])) {
53  $extension->setVersion($extensionArray['version']);
54  }
55  if (isset($extensionArray['constraints'])) {
56  $extension->setDependencies($this->‪convertDependenciesToObjects(serialize($extensionArray['constraints'])));
57  }
58  return $extension;
59  }
60 
67  public function ‪convertDependenciesToObjects($dependencies)
68  {
69  $dependenciesObject = new \SplObjectStorage();
70  $unserializedDependencies = unserialize($dependencies, ['allowed_classes' => false]);
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) {
82  $lowest = $versionNumbers[0];
83  if (count($versionNumbers) === 2) {
84  $highest = $versionNumbers[1];
85  } else {
86  $highest = '';
87  }
88  $dependencyObject = $this->objectManager->get(Dependency::class);
89  $dependencyObject->setType($dependencyType);
90  // dynamically migrate 'cms' dependency to 'core' dependency
91  // see also \TYPO3\CMS\Core\Package\Package::getPackageMetaData
92  $dependencyObject->setIdentifier($dependency === 'cms' ? 'core' : $dependency);
93  $dependencyObject->setLowestVersion($lowest);
94  $dependencyObject->setHighestVersion($highest);
95  $dependenciesObject->attach($dependencyObject);
96  unset($dependencyObject);
97  }
98  }
99  }
100  return $dependenciesObject;
101  }
102 }
‪TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility\convertDependenciesToObjects
‪SplObjectStorage convertDependenciesToObjects($dependencies)
Definition: ExtensionModelUtility.php:66
‪TYPO3\CMS\Core\Utility\VersionNumberUtility
Definition: VersionNumberUtility.php:25
‪TYPO3\CMS\Extensionmanager\Domain\Model\Dependency
Definition: Dependency.php:26
‪TYPO3\CMS\Extensionmanager\Utility
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension
Definition: Extension.php:29
‪TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility
Definition: ExtensionModelUtility.php:28
‪TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility\$objectManager
‪ObjectManager $objectManager
Definition: ExtensionModelUtility.php:31
‪TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility\injectObjectManager
‪injectObjectManager(ObjectManager $objectManager)
Definition: ExtensionModelUtility.php:36
‪TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility\mapExtensionArrayToModel
‪Extension mapExtensionArrayToModel(array $extensionArray)
Definition: ExtensionModelUtility.php:47
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension\setExtensionKey
‪setExtensionKey($extensionKey)
Definition: Extension.php:262
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:28
‪TYPO3\CMS\Core\Utility\VersionNumberUtility\convertVersionsStringToVersionNumbers
‪static array convertVersionsStringToVersionNumbers($versionsString)
Definition: VersionNumberUtility.php:137