TYPO3 CMS  TYPO3_8-7
Package.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Package;
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 
18 
23 class Package implements PackageInterface
24 {
29 
36  protected $partOfFactoryDefault = false;
37 
44  protected $partOfMinimalUsableSystem = false;
45 
50  protected $packageKey;
51 
56  protected $packagePath;
57 
62  protected $protected = false;
63 
67  protected $composerManifest;
68 
73  protected $packageMetaData;
74 
78  protected $packageManager;
79 
91  {
92  if (!$packageManager->isPackageKeyValid($packageKey)) {
93  throw new Exception\InvalidPackageKeyException('"' . $packageKey . '" is not a valid package key.', 1217959511);
94  }
95  if (!(@is_dir($packagePath) || (is_link($packagePath) && is_dir($packagePath)))) {
96  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);
97  }
98  if (substr($packagePath, -1, 1) !== '/') {
99  throw new Exception\InvalidPackagePathException(sprintf('The package path "%s" provided for package "%s" has no trailing forward slash.', $packagePath, $packageKey), 1166633722);
100  }
101  $this->packageManager = $packageManager;
102  $this->packageKey = $packageKey;
103  $this->packagePath = $packagePath;
104  $this->composerManifest = $packageManager->getComposerManifest($this->packagePath);
106  }
107 
112  protected function loadFlagsFromComposerManifest()
113  {
114  $extraFlags = $this->getValueFromComposerManifest('extra');
115  if ($extraFlags !== null && isset($extraFlags->{'typo3/cms'}->{'Package'})) {
116  foreach ($extraFlags->{'typo3/cms'}->{'Package'} as $flagName => $flagValue) {
117  if (property_exists($this, $flagName)) {
118  $this->{$flagName} = $flagValue;
119  }
120  }
121  }
122  }
123 
127  public function isPartOfFactoryDefault()
128  {
130  }
131 
135  public function isPartOfMinimalUsableSystem()
136  {
138  }
139 
146  public function getPackageKey()
147  {
148  return $this->packageKey;
149  }
150 
157  public function isProtected()
158  {
159  return $this->protected;
160  }
161 
168  public function setProtected($protected)
169  {
170  $this->protected = (bool)$protected;
171  }
172 
179  public function getPackagePath()
180  {
181  return $this->packagePath;
182  }
183 
189  public function getPackageMetaData()
190  {
191  if ($this->packageMetaData === null) {
192  $this->packageMetaData = new MetaData($this->getPackageKey());
193  $this->packageMetaData->setDescription($this->getValueFromComposerManifest('description'));
194  $this->packageMetaData->setVersion($this->getValueFromComposerManifest('version'));
195  $requirements = $this->getValueFromComposerManifest('require');
196  if ($requirements !== null) {
197  foreach ($requirements as $requirement => $version) {
198  $packageKey = $this->packageManager->getPackageKeyFromComposerName($requirement);
199  // dynamically migrate 'cms' dependency to 'core' dependency
200  // see also \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::convertDependenciesToObjects
201  if ($packageKey === 'cms') {
202  GeneralUtility::deprecationLog('Extension "' . $this->packageKey . '" defines a dependency on ext:cms, which has been removed. Please remove the dependency.');
203  $packageKey = 'core';
204  }
205  $constraint = new MetaData\PackageConstraint(MetaData::CONSTRAINT_TYPE_DEPENDS, $packageKey);
206  $this->packageMetaData->addConstraint($constraint);
207  }
208  }
209  $suggestions = $this->getValueFromComposerManifest('suggest');
210  if ($suggestions !== null) {
211  foreach ($suggestions as $suggestion => $version) {
212  $packageKey = $this->packageManager->getPackageKeyFromComposerName($suggestion);
213  $constraint = new MetaData\PackageConstraint(MetaData::CONSTRAINT_TYPE_SUGGESTS, $packageKey);
214  $this->packageMetaData->addConstraint($constraint);
215  }
216  }
217  }
218  return $this->packageMetaData;
219  }
220 
226  public function getPackageReplacementKeys()
227  {
228  // The cast to array is required since the manifest returns data with type mixed
229  return (array)$this->getValueFromComposerManifest('replace') ?: [];
230  }
231 
239  public function getValueFromComposerManifest($key = null)
240  {
241  if ($key === null) {
243  }
244 
245  if (isset($this->composerManifest->{$key})) {
246  $value = $this->composerManifest->{$key};
247  } else {
248  $value = null;
249  }
250  return $value;
251  }
252 
265  public function __sleep()
266  {
267  $properties = get_class_vars(get_class($this));
268  unset($properties['packageManager']);
269  return array_keys($properties);
270  }
271 
282  public function __wakeup()
283  {
284  if (isset($GLOBALS['TYPO3_currentPackageManager'])) {
285  $this->packageManager = $GLOBALS['TYPO3_currentPackageManager'];
286  }
287  }
288 }
getValueFromComposerManifest($key=null)
Definition: Package.php:239
__construct(PackageManager $packageManager, $packageKey, $packagePath)
Definition: Package.php:90
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']