‪TYPO3CMS  10.4
Package.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 
21 
26 {
30  protected ‪$extensionManagerConfiguration = [];
31 
38  protected ‪$partOfFactoryDefault = false;
39 
46  protected ‪$partOfMinimalUsableSystem = false;
47 
55  protected ‪$serviceProvider;
56 
61  protected ‪$packageKey;
62 
67  protected ‪$packagePath;
68 
73  protected ‪$protected = false;
74 
78  protected ‪$composerManifest;
79 
84  protected ‪$packageMetaData;
85 
96  public function ‪__construct(PackageManager $packageManager, ‪$packageKey, ‪$packagePath)
97  {
98  if (!$packageManager->isPackageKeyValid(‪$packageKey)) {
99  throw new ‪InvalidPackageKeyException('"' . ‪$packageKey . '" is not a valid package key.', 1217959511);
100  }
101  if (!(@is_dir(‪$packagePath) || (is_link(‪$packagePath) && is_dir(‪$packagePath)))) {
102  throw new ‪InvalidPackagePathException(sprintf('Tried to instantiate a package object for package "%s" with a non-existing package path "%s". Either the package does not exist anymore, or the code creating this object contains an error.', ‪$packageKey, ‪$packagePath), 1166631890);
103  }
104  if (substr(‪$packagePath, -1, 1) !== '/') {
105  throw new ‪InvalidPackagePathException(sprintf('The package path "%s" provided for package "%s" has no trailing forward slash.', ‪$packagePath, ‪$packageKey), 1166633722);
106  }
107  $this->packageKey = ‪$packageKey;
108  $this->packagePath = ‪$packagePath;
109  $this->composerManifest = $packageManager->getComposerManifest($this->packagePath);
111  $this->‪createPackageMetaData($packageManager);
112  }
113 
118  protected function ‪loadFlagsFromComposerManifest()
119  {
120  $extraFlags = $this->‪getValueFromComposerManifest('extra');
121  if ($extraFlags !== null && isset($extraFlags->{'typo3/cms'}->{'Package'})) {
122  foreach ($extraFlags->{'typo3/cms'}->{'Package'} as $flagName => $flagValue) {
123  if (property_exists($this, $flagName)) {
124  $this->{$flagName} = $flagValue;
125  }
126  }
127  }
128  }
129 
135  protected function createPackageMetaData(PackageManager $packageManager)
136  {
137  $this->packageMetaData = new MetaData($this->getPackageKey());
138  $this->packageMetaData->setDescription($this->getValueFromComposerManifest('description'));
139  $this->packageMetaData->setVersion($this->getValueFromComposerManifest('version'));
140  $requirements = $this->getValueFromComposerManifest('require');
141  if ($requirements !== null) {
142  foreach ($requirements as $requirement => $version) {
143  $packageKey = $packageManager->getPackageKeyFromComposerName($requirement);
144  // dynamically migrate 'cms' dependency to 'core' dependency
145  // see also \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::convertDependenciesToObjects
146  if ($packageKey === 'cms') {
147  trigger_error('Extension "' . $this->packageKey . '" defines a dependency on ext:cms, which has been removed. Please remove the dependency.', E_USER_DEPRECATED);
148  $packageKey = 'core';
149  }
150  $constraint = new PackageConstraint(MetaData::CONSTRAINT_TYPE_DEPENDS, $packageKey);
151  $this->packageMetaData->addConstraint($constraint);
152  }
153  }
154  $suggestions = $this->getValueFromComposerManifest('suggest');
155  if ($suggestions !== null) {
156  foreach ($suggestions as $suggestion => $version) {
157  $packageKey = $packageManager->getPackageKeyFromComposerName($suggestion);
158  $constraint = new PackageConstraint(MetaData::CONSTRAINT_TYPE_SUGGESTS, $packageKey);
159  $this->packageMetaData->addConstraint($constraint);
160  }
161  }
162  }
163 
170  public function getServiceProvider(): string
171  {
172  return $this->serviceProvider ?? PseudoServiceProvider::class;
173  }
174 
179  public function isPartOfFactoryDefault()
180  {
181  return $this->partOfFactoryDefault;
182  }
183 
188  public function isPartOfMinimalUsableSystem()
189  {
190  return $this->partOfMinimalUsableSystem;
191  }
192 
198  public function getPackageKey()
199  {
200  return $this->packageKey;
201  }
202 
208  public function isProtected()
209  {
210  return $this->protected;
211  }
212 
218  public function setProtected($protected)
219  {
220  $this->protected = (bool)$protected;
221  }
222 
228  public function getPackagePath()
229  {
230  return $this->packagePath;
231  }
232 
239  public function getPackageMetaData()
240  {
241  return $this->packageMetaData;
242  }
243 
250  public function getPackageReplacementKeys()
251  {
252  // The cast to array is required since the manifest returns data with type mixed
253  return (array)$this->getValueFromComposerManifest('replace') ?: [];
254  }
255 
264  public function getValueFromComposerManifest($key = null)
265  {
266  if ($key === null) {
267  return $this->composerManifest;
268  }
269 
270  if (isset($this->composerManifest->{$key})) {
271  $value = $this->composerManifest->{$key};
272  } else {
273  $value = null;
274  }
275  return $value;
276  }
277 }
‪TYPO3\CMS\Core\Package\Package\getPackageMetaData
‪MetaData getPackageMetaData()
Definition: Package.php:230
‪TYPO3\CMS\Core\Package\Package\isProtected
‪bool isProtected()
Definition: Package.php:199
‪TYPO3\CMS\Core\Package\Package\getPackagePath
‪string getPackagePath()
Definition: Package.php:219
‪TYPO3\CMS\Core\Package\Package\setProtected
‪setProtected($protected)
Definition: Package.php:209
‪TYPO3\CMS\Core\Package\Exception\InvalidPackagePathException
Definition: InvalidPackagePathException.php:24
‪TYPO3\CMS\Core\Package\Package\__construct
‪__construct(PackageManager $packageManager, $packageKey, $packagePath)
Definition: Package.php:87
‪TYPO3\CMS\Core\Package\Package\$extensionManagerConfiguration
‪array $extensionManagerConfiguration
Definition: Package.php:29
‪TYPO3\CMS\Core\Package\Package\$packageKey
‪string $packageKey
Definition: Package.php:56
‪TYPO3\CMS\Core\Package\Package\$packagePath
‪string $packagePath
Definition: Package.php:61
‪TYPO3\CMS\Core\Package\Exception\InvalidPackageKeyException
Definition: InvalidPackageKeyException.php:24
‪TYPO3\CMS\Core\Package\Package\getPackageKey
‪string getPackageKey()
Definition: Package.php:189
‪TYPO3\CMS\Core\Package\PackageInterface
Definition: PackageInterface.php:22
‪TYPO3\CMS\Core\Package\Package\getValueFromComposerManifest
‪mixed null getValueFromComposerManifest($key=null)
Definition: Package.php:255
‪TYPO3\CMS\Core\Package\Package\$packageMetaData
‪MetaData $packageMetaData
Definition: Package.php:75
‪TYPO3\CMS\Core\Package\Package
Definition: Package.php:26
‪TYPO3\CMS\Core\Package\Package\isPartOfMinimalUsableSystem
‪bool isPartOfMinimalUsableSystem()
Definition: Package.php:179
‪TYPO3\CMS\Core\Package\Package\createPackageMetaData
‪createPackageMetaData(PackageManager $packageManager)
Definition: Package.php:126
‪TYPO3\CMS\Core\Package\MetaData\PackageConstraint
Definition: PackageConstraint.php:22
‪TYPO3\CMS\Core\Package\Package\$partOfFactoryDefault
‪bool $partOfFactoryDefault
Definition: Package.php:36
‪TYPO3\CMS\Core\Package\Package\isPartOfFactoryDefault
‪bool isPartOfFactoryDefault()
Definition: Package.php:170
‪TYPO3\CMS\Core\Package\Package\getServiceProvider
‪string getServiceProvider()
Definition: Package.php:161
‪TYPO3\CMS\Core\Package\Package\getPackageReplacementKeys
‪array getPackageReplacementKeys()
Definition: Package.php:241
‪TYPO3\CMS\Core\Package\Package\$partOfMinimalUsableSystem
‪bool $partOfMinimalUsableSystem
Definition: Package.php:43
‪TYPO3\CMS\Core\Package\Package\loadFlagsFromComposerManifest
‪loadFlagsFromComposerManifest()
Definition: Package.php:109
‪TYPO3\CMS\Core\Package\Package\$protected
‪bool $protected
Definition: Package.php:66
‪TYPO3\CMS\Core\Package\Package\$serviceProvider
‪string $serviceProvider
Definition: Package.php:51
‪TYPO3\CMS\Core\Package
Definition: AbstractServiceProvider.php:18
‪TYPO3\CMS\Core\Package\MetaData
Definition: MetaData.php:24
‪TYPO3\CMS\Core\Package\Package\$composerManifest
‪stdClass $composerManifest
Definition: Package.php:70