‪TYPO3CMS  9.5
Package.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 ‪$extensionManagerConfiguration = [];
26 
33  protected ‪$partOfFactoryDefault = false;
34 
41  protected ‪$partOfMinimalUsableSystem = false;
42 
47  protected ‪$packageKey;
48 
53  protected ‪$packagePath;
54 
59  protected ‪$protected = false;
60 
64  protected ‪$composerManifest;
65 
70  protected ‪$packageMetaData;
71 
82  public function ‪__construct(PackageManager $packageManager, ‪$packageKey, ‪$packagePath)
83  {
84  if (!$packageManager->isPackageKeyValid(‪$packageKey)) {
85  throw new Exception\InvalidPackageKeyException('"' . ‪$packageKey . '" is not a valid package key.', 1217959511);
86  }
87  if (!(@is_dir(‪$packagePath) || (is_link(‪$packagePath) && is_dir(‪$packagePath)))) {
88  throw new Exception\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);
89  }
90  if (substr(‪$packagePath, -1, 1) !== '/') {
91  throw new Exception\InvalidPackagePathException(sprintf('The package path "%s" provided for package "%s" has no trailing forward slash.', ‪$packagePath, ‪$packageKey), 1166633722);
92  }
93  $this->packageKey = ‪$packageKey;
94  $this->packagePath = ‪$packagePath;
95  $this->composerManifest = $packageManager->getComposerManifest($this->packagePath);
97  $this->createPackageMetadata($packageManager);
98  }
99 
104  protected function ‪loadFlagsFromComposerManifest()
105  {
106  $extraFlags = $this->‪getValueFromComposerManifest('extra');
107  if ($extraFlags !== null && isset($extraFlags->{'typo3/cms'}->{'Package'})) {
108  foreach ($extraFlags->{'typo3/cms'}->{'Package'} as $flagName => $flagValue) {
109  if (property_exists($this, $flagName)) {
110  $this->{$flagName} = $flagValue;
111  }
112  }
113  }
114  }
115 
121  protected function createPackageMetaData(PackageManager $packageManager)
122  {
123  $this->packageMetaData = new MetaData($this->getPackageKey());
124  $this->packageMetaData->setDescription($this->getValueFromComposerManifest('description'));
125  $this->packageMetaData->setVersion($this->getValueFromComposerManifest('version'));
126  $requirements = $this->getValueFromComposerManifest('require');
127  if ($requirements !== null) {
128  foreach ($requirements as $requirement => $version) {
129  $packageKey = $packageManager->getPackageKeyFromComposerName($requirement);
130  // dynamically migrate 'cms' dependency to 'core' dependency
131  // see also \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::convertDependenciesToObjects
132  if ($packageKey === 'cms') {
133  trigger_error('Extension "' . $this->packageKey . '" defines a dependency on ext:cms, which has been removed. Please remove the dependency.', E_USER_DEPRECATED);
134  $packageKey = 'core';
135  }
136  $constraint = new MetaData\PackageConstraint(MetaData::CONSTRAINT_TYPE_DEPENDS, $packageKey);
137  $this->packageMetaData->addConstraint($constraint);
138  }
139  }
140  $suggestions = $this->getValueFromComposerManifest('suggest');
141  if ($suggestions !== null) {
142  foreach ($suggestions as $suggestion => $version) {
143  $packageKey = $packageManager->getPackageKeyFromComposerName($suggestion);
144  $constraint = new MetaData\PackageConstraint(MetaData::CONSTRAINT_TYPE_SUGGESTS, $packageKey);
145  $this->packageMetaData->addConstraint($constraint);
146  }
147  }
148  }
149 
154  public function isPartOfFactoryDefault()
155  {
156  return $this->partOfFactoryDefault;
157  }
158 
163  public function isPartOfMinimalUsableSystem()
164  {
165  return $this->partOfMinimalUsableSystem;
166  }
167 
173  public function getPackageKey()
174  {
175  return $this->packageKey;
176  }
177 
183  public function isProtected()
184  {
185  return $this->protected;
186  }
187 
193  public function setProtected($protected)
194  {
195  $this->protected = (bool)$protected;
196  }
197 
203  public function getPackagePath()
204  {
205  return $this->packagePath;
206  }
207 
214  public function getPackageMetaData()
215  {
216  return $this->packageMetaData;
217  }
218 
225  public function getPackageReplacementKeys()
226  {
227  // The cast to array is required since the manifest returns data with type mixed
228  return (array)$this->getValueFromComposerManifest('replace') ?: [];
229  }
230 
239  public function getValueFromComposerManifest($key = null)
240  {
241  if ($key === null) {
242  return $this->composerManifest;
243  }
244 
245  if (isset($this->composerManifest->{$key})) {
246  $value = $this->composerManifest->{$key};
247  } else {
248  $value = null;
249  }
250  return $value;
251  }
252 }
‪TYPO3\CMS\Core\Package\Package\getPackageMetaData
‪MetaData getPackageMetaData()
Definition: Package.php:206
‪TYPO3\CMS\Core\Package\Package\isProtected
‪bool isProtected()
Definition: Package.php:175
‪TYPO3\CMS\Core\Package\Package\getPackagePath
‪string getPackagePath()
Definition: Package.php:195
‪TYPO3\CMS\Core\Package\Package\setProtected
‪setProtected($protected)
Definition: Package.php:185
‪TYPO3\CMS\Core\Package\Package\__construct
‪__construct(PackageManager $packageManager, $packageKey, $packagePath)
Definition: Package.php:74
‪TYPO3\CMS\Core\Package\Package\$extensionManagerConfiguration
‪array $extensionManagerConfiguration
Definition: Package.php:24
‪TYPO3\CMS\Core\Package\Package\$packageKey
‪string $packageKey
Definition: Package.php:43
‪TYPO3\CMS\Core\Package\Package\$packagePath
‪string $packagePath
Definition: Package.php:48
‪TYPO3\CMS\Core\Package\Package\getPackageKey
‪string getPackageKey()
Definition: Package.php:165
‪TYPO3\CMS\Core\Package\PackageInterface
Definition: PackageInterface.php:21
‪TYPO3\CMS\Core\Package\Package\getValueFromComposerManifest
‪mixed null getValueFromComposerManifest($key=null)
Definition: Package.php:231
‪TYPO3\CMS\Core\Package\Package\$packageMetaData
‪MetaData $packageMetaData
Definition: Package.php:62
‪TYPO3\CMS\Core\Package\Package
Definition: Package.php:21
‪TYPO3\CMS\Core\Package\Package\isPartOfMinimalUsableSystem
‪bool isPartOfMinimalUsableSystem()
Definition: Package.php:155
‪TYPO3\CMS\Core\Package\Package\createPackageMetaData
‪createPackageMetaData(PackageManager $packageManager)
Definition: Package.php:113
‪TYPO3\CMS\Core\Package\Package\$partOfFactoryDefault
‪bool $partOfFactoryDefault
Definition: Package.php:31
‪TYPO3\CMS\Core\Package\Package\isPartOfFactoryDefault
‪bool isPartOfFactoryDefault()
Definition: Package.php:146
‪TYPO3\CMS\Core\Package\Package\getPackageReplacementKeys
‪array getPackageReplacementKeys()
Definition: Package.php:217
‪TYPO3\CMS\Core\Package\Package\$partOfMinimalUsableSystem
‪bool $partOfMinimalUsableSystem
Definition: Package.php:38
‪TYPO3\CMS\Core\Package\Package\loadFlagsFromComposerManifest
‪loadFlagsFromComposerManifest()
Definition: Package.php:96
‪TYPO3\CMS\Core\Package\Package\$protected
‪bool $protected
Definition: Package.php:53
‪TYPO3\CMS\Core\Package
Definition: DependencyResolver.php:2
‪TYPO3\CMS\Core\Package\MetaData
Definition: MetaData.php:21
‪TYPO3\CMS\Core\Package\Package\$composerManifest
‪stdClass $composerManifest
Definition: Package.php:57