‪TYPO3CMS  11.5
Dependency.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
22 
28 {
32  protected ‪$identifier = '';
33 
37  protected ‪$lowestVersion = '';
38 
42  protected ‪$highestVersion = '';
43 
47  protected ‪$type = '';
48 
52  protected static ‪$dependencyTypes = [
53  'depends',
54  'conflicts',
55  'suggests',
56  ];
57 
61  public static ‪$specialDependencies = [
62  'typo3',
63  'php',
64  ];
65 
66  private function ‪__construct(string ‪$identifier, string ‪$type, string ‪$lowestVersion, string ‪$highestVersion)
67  {
68  $this->identifier = ‪$identifier;
69  $this->type = ‪$type;
70  $this->lowestVersion = ‪$lowestVersion;
71  $this->highestVersion = ‪$highestVersion;
72  }
73 
83  public static function ‪createFromEmConf(
84  string ‪$identifier,
85  string $versionConstraint = '',
86  string $dependencyType = 'depends'
87  ): self {
88  $versionNumbers = ‪VersionNumberUtility::convertVersionsStringToVersionNumbers($versionConstraint);
89  $lowest = $versionNumbers[0];
90  if (count($versionNumbers) === 2) {
91  $highest = $versionNumbers[1];
92  } else {
93  $highest = '';
94  }
95  if (!in_array($dependencyType, self::$dependencyTypes, true)) {
96  throw new ExtensionManagerException($dependencyType . ' was not a valid dependency type.', 1476122402);
97  }
98  // dynamically migrate 'cms' dependency to 'core' dependency
99  // see also \TYPO3\CMS\Core\Package\Package::getPackageMetaData
100  ‪$identifier = strtolower(‪$identifier);
101  ‪$identifier = ‪$identifier === 'cms' ? 'core' : ‪$identifier;
102  return new self(‪$identifier, $dependencyType, (string)$lowest, (string)$highest);
103  }
104 
105  public function ‪getHighestVersion(): string
106  {
108  }
109 
110  public function ‪getIdentifier(): string
111  {
112  return ‪$this->identifier;
113  }
114 
115  public function ‪getLowestVersion(): string
116  {
118  }
119 
120  public function ‪getType(): string
121  {
122  return ‪$this->type;
123  }
124 
133  public function ‪isVersionCompatible(string $version): bool
134  {
135  if ($this->lowestVersion !== '' && version_compare($version, $this->lowestVersion) === -1) {
136  return false;
137  }
138  if ($this->highestVersion !== '' && version_compare($this->highestVersion, $version) === -1) {
139  return false;
140  }
141  return true;
142  }
143 
144  public function ‪getLowestVersionAsInteger(): int
145  {
146  if ($this->lowestVersion) {
147  return ‪VersionNumberUtility::convertVersionNumberToInteger($this->lowestVersion);
148  }
149  return 0;
150  }
151 
152  public function ‪getHighestVersionAsInteger(): int
153  {
154  if ($this->highestVersion) {
155  return ‪VersionNumberUtility::convertVersionNumberToInteger($this->highestVersion);
156  }
157  return 0;
158  }
159 }
‪TYPO3\CMS\Extensionmanager\Domain\Model\Dependency\getHighestVersion
‪getHighestVersion()
Definition: Dependency.php:99
‪TYPO3\CMS\Core\Utility\VersionNumberUtility
Definition: VersionNumberUtility.php:24
‪TYPO3\CMS\Extensionmanager\Domain\Model\Dependency
Definition: Dependency.php:28
‪TYPO3\CMS\Extensionmanager\Domain\Model\Dependency\getType
‪getType()
Definition: Dependency.php:114
‪TYPO3\CMS\Extensionmanager\Domain\Model\Dependency\getLowestVersion
‪getLowestVersion()
Definition: Dependency.php:109
‪TYPO3\CMS\Extensionmanager\Domain\Model\Dependency\$dependencyTypes
‪static array $dependencyTypes
Definition: Dependency.php:47
‪TYPO3\CMS\Extensionmanager\Domain\Model\Dependency\getHighestVersionAsInteger
‪getHighestVersionAsInteger()
Definition: Dependency.php:146
‪TYPO3\CMS\Extensionmanager\Domain\Model\Dependency\createFromEmConf
‪static self createFromEmConf(string $identifier, string $versionConstraint='', string $dependencyType='depends')
Definition: Dependency.php:77
‪TYPO3\CMS\Extensionmanager\Domain\Model\Dependency\getIdentifier
‪getIdentifier()
Definition: Dependency.php:104
‪TYPO3\CMS\Core\Utility\VersionNumberUtility\convertVersionNumberToInteger
‪static int convertVersionNumberToInteger($versionNumber)
Definition: VersionNumberUtility.php:31
‪TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
Definition: ExtensionManagerException.php:23
‪TYPO3\CMS\Extensionmanager\Domain\Model\Dependency\$highestVersion
‪string $highestVersion
Definition: Dependency.php:39
‪TYPO3\CMS\Extensionmanager\Domain\Model\Dependency\__construct
‪__construct(string $identifier, string $type, string $lowestVersion, string $highestVersion)
Definition: Dependency.php:60
‪TYPO3\CMS\Extensionmanager\Domain\Model\Dependency\$type
‪string $type
Definition: Dependency.php:43
‪TYPO3\CMS\Extensionmanager\Domain\Model\Dependency\$specialDependencies
‪static array $specialDependencies
Definition: Dependency.php:55
‪TYPO3\CMS\Extensionmanager\Domain\Model
Definition: Dependency.php:18
‪TYPO3\CMS\Extensionmanager\Domain\Model\Dependency\isVersionCompatible
‪bool isVersionCompatible(string $version)
Definition: Dependency.php:127
‪TYPO3\CMS\Extensionmanager\Domain\Model\Dependency\getLowestVersionAsInteger
‪getLowestVersionAsInteger()
Definition: Dependency.php:138
‪TYPO3\CMS\Core\Utility\VersionNumberUtility\convertVersionsStringToVersionNumbers
‪static array convertVersionsStringToVersionNumbers($versionsString)
Definition: VersionNumberUtility.php:81
‪TYPO3\CMS\Extensionmanager\Domain\Model\Dependency\$identifier
‪string $identifier
Definition: Dependency.php:31
‪TYPO3\CMS\Extensionmanager\Domain\Model\Dependency\$lowestVersion
‪string $lowestVersion
Definition: Dependency.php:35