TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
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 
33  protected $classAliases;
34 
41  protected $partOfFactoryDefault = false;
42 
49  protected $partOfMinimalUsableSystem = false;
50 
55  protected $packageKey;
56 
61  protected $packagePath;
62 
67  protected $protected = false;
68 
72  protected $composerManifest;
73 
78  protected $packageMetaData;
79 
83  protected $packageManager;
84 
96  {
97  if (!$packageManager->isPackageKeyValid($packageKey)) {
98  throw new Exception\InvalidPackageKeyException('"' . $packageKey . '" is not a valid package key.', 1217959511);
99  }
100  if (!(@is_dir($packagePath) || (is_link($packagePath) && is_dir($packagePath)))) {
101  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);
102  }
103  if (substr($packagePath, -1, 1) !== '/') {
104  throw new Exception\InvalidPackagePathException(sprintf('The package path "%s" provided for package "%s" has no trailing forward slash.', $packagePath, $packageKey), 1166633722);
105  }
106  $this->packageManager = $packageManager;
107  $this->packageKey = $packageKey;
108  $this->packagePath = $packagePath;
109  $this->composerManifest = $packageManager->getComposerManifest($this->packagePath);
111  }
112 
119  protected function loadFlagsFromComposerManifest()
120  {
121  $extraFlags = $this->getValueFromComposerManifest('extra');
122  if ($extraFlags !== null && isset($extraFlags->{'typo3/cms'}->{'Package'})) {
123  foreach ($extraFlags->{'typo3/cms'}->{'Package'} as $flagName => $flagValue) {
124  if (property_exists($this, $flagName)) {
125  $this->{$flagName} = $flagValue;
126  }
127  }
128  }
129  }
130 
134  public function isPartOfFactoryDefault()
135  {
136  return $this->partOfFactoryDefault;
137  }
138 
142  public function isPartOfMinimalUsableSystem()
143  {
144  return $this->partOfMinimalUsableSystem;
145  }
146 
153  public function getPackageKey()
154  {
155  return $this->packageKey;
156  }
157 
164  public function isProtected()
165  {
166  return $this->protected;
167  }
168 
176  public function setProtected($protected)
177  {
178  $this->protected = (bool)$protected;
179  }
180 
187  public function getPackagePath()
188  {
189  return $this->packagePath;
190  }
191 
197  public function getPackageMetaData()
198  {
199  if ($this->packageMetaData === null) {
200  $this->packageMetaData = new MetaData($this->getPackageKey());
201  $this->packageMetaData->setDescription($this->getValueFromComposerManifest('description'));
202  $this->packageMetaData->setVersion($this->getValueFromComposerManifest('version'));
203  $requirements = $this->getValueFromComposerManifest('require');
204  if ($requirements !== null) {
205  foreach ($requirements as $requirement => $version) {
206  $packageKey = $this->packageManager->getPackageKeyFromComposerName($requirement);
207  // dynamically migrate 'cms' dependency to 'core' dependency
208  // see also \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::convertDependenciesToObjects
209  if ($packageKey === 'cms') {
210  GeneralUtility::deprecationLog('Extension "' . $this->packageKey . '" defines a dependency on ext:cms, which has been removed. Please remove the dependency.');
211  $packageKey = 'core';
212  }
213  $constraint = new MetaData\PackageConstraint(MetaData::CONSTRAINT_TYPE_DEPENDS, $packageKey);
214  $this->packageMetaData->addConstraint($constraint);
215  }
216  }
217  $suggestions = $this->getValueFromComposerManifest('suggest');
218  if ($suggestions !== null) {
219  foreach ($suggestions as $suggestion => $version) {
220  $packageKey = $this->packageManager->getPackageKeyFromComposerName($suggestion);
221  $constraint = new MetaData\PackageConstraint(MetaData::CONSTRAINT_TYPE_SUGGESTS, $packageKey);
222  $this->packageMetaData->addConstraint($constraint);
223  }
224  }
225  }
226  return $this->packageMetaData;
227  }
228 
234  public function getPackageReplacementKeys()
235  {
236  // The cast to array is required since the manifest returns data with type mixed
237  return (array)$this->getValueFromComposerManifest('replace') ?: [];
238  }
239 
247  public function getValueFromComposerManifest($key = null)
248  {
249  if ($key === null) {
250  return $this->composerManifest;
251  }
252 
253  if (isset($this->composerManifest->{$key})) {
254  $value = $this->composerManifest->{$key};
255  } else {
256  $value = null;
257  }
258  return $value;
259  }
260 
273  public function __sleep()
274  {
275  $properties = get_class_vars(get_class($this));
276  unset($properties['packageManager']);
277  return array_keys($properties);
278  }
279 
290  public function __wakeup()
291  {
292  if (isset($GLOBALS['TYPO3_currentPackageManager'])) {
293  $this->packageManager = $GLOBALS['TYPO3_currentPackageManager'];
294  }
295  }
296 }
__construct(PackageManager $packageManager, $packageKey, $packagePath)
Definition: Package.php:95
getValueFromComposerManifest($key=null)
Definition: Package.php:247
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']