[FEATURE] Auto-detect charset conversion
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Configuration / FeatureManager.php
1 <?php
2 namespace TYPO3\CMS\Install\Configuration;
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
17 /**
18 * Instantiate and configure all known features and presets
19 */
20 class FeatureManager
21 {
22 /**
23 * @var \TYPO3\CMS\Extbase\Object\ObjectManager
24 */
25 protected $objectManager = null;
26
27 /**
28 * @param \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager
29 */
30 public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManager $objectManager)
31 {
32 $this->objectManager = $objectManager;
33 }
34
35 /**
36 * @var array List of feature class names
37 */
38 protected $featureRegistry = array(
39 \TYPO3\CMS\Install\Configuration\Context\ContextFeature::class,
40 \TYPO3\CMS\Install\Configuration\Image\ImageFeature::class,
41 \TYPO3\CMS\Install\Configuration\ExtbaseObjectCache\ExtbaseObjectCacheFeature::class,
42 \TYPO3\CMS\Install\Configuration\Mail\MailFeature::class,
43 );
44
45 /**
46 * Get initialized list of features with possible presets
47 *
48 * @param array $postValues List of $POST values
49 * @return array<FeatureInterface>
50 * @throws Exception
51 */
52 public function getInitializedFeatures(array $postValues)
53 {
54 $features = array();
55 foreach ($this->featureRegistry as $featureClass) {
56 /** @var FeatureInterface $featureInstance */
57 $featureInstance = $this->objectManager->get($featureClass);
58 if (!($featureInstance instanceof FeatureInterface)) {
59 throw new Exception(
60 'Feature ' . $featureClass . ' does not implement FeatureInterface',
61 1378644593
62 );
63 }
64 $featureInstance->initializePresets($postValues);
65 $features[] = $featureInstance;
66 }
67 return $features;
68 }
69
70 /**
71 * Get configuration values to be set to LocalConfiguration from
72 * list of selected $POST feature presets
73 *
74 * @param array $postValues List of $POST values
75 * @return array List of configuration values
76 */
77 public function getConfigurationForSelectedFeaturePresets(array $postValues)
78 {
79 $localConfigurationValuesToSet = array();
80 $features = $this->getInitializedFeatures($postValues);
81 foreach ($features as $feature) {
82 /** @var FeatureInterface $feature */
83 $featureName = $feature->getName();
84 $presets = $feature->getPresetsOrderedByPriority();
85 foreach ($presets as $preset) {
86 /** @var PresetInterface $preset */
87 $presetName = $preset->getName();
88 if (!empty($postValues[$featureName]['enable'])
89 && $postValues[$featureName]['enable'] === $presetName
90 && (!$preset->isActive() || $preset instanceof CustomPresetInterface)
91 ) {
92 $localConfigurationValuesToSet = array_merge(
93 $localConfigurationValuesToSet,
94 $preset->getConfigurationValues()
95 );
96 }
97 }
98 }
99 return $localConfigurationValuesToSet;
100 }
101
102 /**
103 * Cycle through features and get settings. First matching
104 * preset (highest priority) will be selected.
105 *
106 * @return array Configuration settings
107 */
108 public function getBestMatchingConfigurationForAllFeatures()
109 {
110 $localConfigurationValuesToSet = array();
111 $features = $this->getInitializedFeatures(array());
112 foreach ($features as $feature) {
113 /** @var FeatureInterface $feature */
114 $presets = $feature->getPresetsOrderedByPriority();
115 foreach ($presets as $preset) {
116 // Only choose "normal" presets, no custom presets
117 if ($preset instanceof CustomPresetInterface) {
118 break;
119 }
120
121 /** @var PresetInterface $preset */
122 if ($preset->isAvailable()) {
123 $localConfigurationValuesToSet = array_merge(
124 $localConfigurationValuesToSet,
125 $preset->getConfigurationValues()
126 );
127 // Setting for this feature done, go to next feature
128 break;
129 }
130 }
131 }
132 return $localConfigurationValuesToSet;
133 }
134 }