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