TYPO3 CMS  TYPO3_8-7
FeatureManager.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 
18 
23 {
27  protected $featureRegistry = [
28  \TYPO3\CMS\Install\Configuration\Context\ContextFeature::class,
29  \TYPO3\CMS\Install\Configuration\Image\ImageFeature::class,
30  \TYPO3\CMS\Install\Configuration\ExtbaseObjectCache\ExtbaseObjectCacheFeature::class,
31  \TYPO3\CMS\Install\Configuration\Mail\MailFeature::class,
32  ];
33 
41  public function getInitializedFeatures(array $postValues)
42  {
43  $features = [];
44  foreach ($this->featureRegistry as $featureClass) {
46  $featureInstance = GeneralUtility::makeInstance($featureClass);
47  if (!($featureInstance instanceof FeatureInterface)) {
48  throw new Exception(
49  'Feature ' . $featureClass . ' does not implement FeatureInterface',
50  1378644593
51  );
52  }
53  $featureInstance->initializePresets($postValues);
54  $features[] = $featureInstance;
55  }
56  return $features;
57  }
58 
66  public function getConfigurationForSelectedFeaturePresets(array $postValues)
67  {
68  $localConfigurationValuesToSet = [];
69  $features = $this->getInitializedFeatures($postValues);
70  foreach ($features as $feature) {
72  $featureName = $feature->getName();
73  $presets = $feature->getPresetsOrderedByPriority();
74  foreach ($presets as $preset) {
76  $presetName = $preset->getName();
77  if (!empty($postValues[$featureName]['enable'])
78  && $postValues[$featureName]['enable'] === $presetName
79  && (!$preset->isActive() || $preset instanceof CustomPresetInterface)
80  ) {
81  $localConfigurationValuesToSet = array_merge(
82  $localConfigurationValuesToSet,
83  $preset->getConfigurationValues()
84  );
85  }
86  }
87  }
88  return $localConfigurationValuesToSet;
89  }
90 
97  public function getBestMatchingConfigurationForAllFeatures()
98  {
99  $localConfigurationValuesToSet = [];
100  $features = $this->getInitializedFeatures([]);
101  foreach ($features as $feature) {
103  $presets = $feature->getPresetsOrderedByPriority();
104  foreach ($presets as $preset) {
105  // Only choose "normal" presets, no custom presets
106  if ($preset instanceof CustomPresetInterface) {
107  break;
108  }
109 
111  if ($preset->isAvailable()) {
112  $localConfigurationValuesToSet = array_merge(
113  $localConfigurationValuesToSet,
114  $preset->getConfigurationValues()
115  );
116  // Setting for this feature done, go to next feature
117  break;
118  }
119  }
120  }
121  return $localConfigurationValuesToSet;
122  }
123 }
static makeInstance($className,... $constructorArguments)