TYPO3 CMS  TYPO3_7-6
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 
21 {
25  protected $objectManager = null;
26 
30  public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManager $objectManager)
31  {
32  $this->objectManager = $objectManager;
33  }
34 
38  protected $featureRegistry = [
39  \TYPO3\CMS\Install\Configuration\Charset\CharsetFeature::class,
40  \TYPO3\CMS\Install\Configuration\Context\ContextFeature::class,
41  \TYPO3\CMS\Install\Configuration\Image\ImageFeature::class,
42  \TYPO3\CMS\Install\Configuration\ExtbaseObjectCache\ExtbaseObjectCacheFeature::class,
43  \TYPO3\CMS\Install\Configuration\Mail\MailFeature::class,
44  ];
45 
53  public function getInitializedFeatures(array $postValues)
54  {
55  $features = [];
56  foreach ($this->featureRegistry as $featureClass) {
58  $featureInstance = $this->objectManager->get($featureClass);
59  if (!($featureInstance instanceof FeatureInterface)) {
60  throw new Exception(
61  'Feature ' . $featureClass . ' does not implement FeatureInterface',
62  1378644593
63  );
64  }
65  $featureInstance->initializePresets($postValues);
66  $features[] = $featureInstance;
67  }
68  return $features;
69  }
70 
78  public function getConfigurationForSelectedFeaturePresets(array $postValues)
79  {
80  $localConfigurationValuesToSet = [];
81  $features = $this->getInitializedFeatures($postValues);
82  foreach ($features as $feature) {
84  $featureName = $feature->getName();
85  $presets = $feature->getPresetsOrderedByPriority();
86  foreach ($presets as $preset) {
88  $presetName = $preset->getName();
89  if (!empty($postValues[$featureName]['enable'])
90  && $postValues[$featureName]['enable'] === $presetName
91  && (!$preset->isActive() || $preset instanceof CustomPresetInterface)
92  ) {
93  $localConfigurationValuesToSet = array_merge(
94  $localConfigurationValuesToSet,
95  $preset->getConfigurationValues()
96  );
97  }
98  }
99  }
100  return $localConfigurationValuesToSet;
101  }
102 
109  public function getBestMatchingConfigurationForAllFeatures()
110  {
111  $localConfigurationValuesToSet = [];
112  $features = $this->getInitializedFeatures([]);
113  foreach ($features as $feature) {
115  $presets = $feature->getPresetsOrderedByPriority();
116  foreach ($presets as $preset) {
117  // Only choose "normal" presets, no custom presets
118  if ($preset instanceof CustomPresetInterface) {
119  break;
120  }
121 
123  if ($preset->isAvailable()) {
124  $localConfigurationValuesToSet = array_merge(
125  $localConfigurationValuesToSet,
126  $preset->getConfigurationValues()
127  );
128  // Setting for this feature done, go to next feature
129  break;
130  }
131  }
132  }
133  return $localConfigurationValuesToSet;
134  }
135 }
injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManager $objectManager)