[CLEANUP] Use comments not PHPDoc style comments in copyright block
[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 * @inject
25 */
26 protected $objectManager = NULL;
27
28 /**
29 * @var array List of feature class names
30 */
31 protected $featureRegistry = array(
32 \TYPO3\CMS\Install\Configuration\Charset\CharsetFeature::class,
33 \TYPO3\CMS\Install\Configuration\Context\ContextFeature::class,
34 \TYPO3\CMS\Install\Configuration\Image\ImageFeature::class,
35 \TYPO3\CMS\Install\Configuration\ExtbaseObjectCache\ExtbaseObjectCacheFeature::class,
36 );
37
38 /**
39 * Get initialized list of features with possible presets
40 *
41 * @param array $postValues List of $POST values
42 * @return array<FeatureInterface>
43 * @throws Exception
44 */
45 public function getInitializedFeatures(array $postValues) {
46 $features = array();
47 foreach ($this->featureRegistry as $featureClass) {
48 /** @var FeatureInterface $featureInstance */
49 $featureInstance = $this->objectManager->get($featureClass);
50 if (!($featureInstance instanceof FeatureInterface)) {
51 throw new Exception(
52 'Feature ' . $featureClass . ' does not implement FeatureInterface',
53 1378644593
54 );
55 }
56 $featureInstance->initializePresets($postValues);
57 $features[] = $featureInstance;
58 }
59 return $features;
60 }
61
62 /**
63 * Get configuration values to be set to LocalConfiguration from
64 * list of selected $POST feature presets
65 *
66 * @param array $postValues List of $POST values
67 * @return array List of configuration values
68 */
69 public function getConfigurationForSelectedFeaturePresets(array $postValues) {
70 $localConfigurationValuesToSet = array();
71 $features = $this->getInitializedFeatures($postValues);
72 foreach ($features as $feature) {
73 /** @var FeatureInterface $feature */
74 $featureName = $feature->getName();
75 $presets = $feature->getPresetsOrderedByPriority();
76 foreach ($presets as $preset) {
77 /** @var PresetInterface $preset */
78 $presetName = $preset->getName();
79 if (!empty($postValues[$featureName]['enable'])
80 && $postValues[$featureName]['enable'] === $presetName
81 && (!$preset->isActive() || $preset instanceof CustomPresetInterface)
82 ) {
83 $localConfigurationValuesToSet = array_merge(
84 $localConfigurationValuesToSet,
85 $preset->getConfigurationValues()
86 );
87 }
88 }
89 }
90 return $localConfigurationValuesToSet;
91 }
92
93 /**
94 * Cycle through features and get settings. First matching
95 * preset (highest priority) will be selected.
96 *
97 * @return array Configuration settings
98 */
99 public function getBestMatchingConfigurationForAllFeatures() {
100 $localConfigurationValuesToSet = array();
101 $features = $this->getInitializedFeatures(array());
102 foreach ($features as $feature) {
103 /** @var FeatureInterface $feature */
104 $presets = $feature->getPresetsOrderedByPriority();
105 foreach ($presets as $preset) {
106 // Only choose "normal" presets, no custom presets
107 if ($preset instanceof CustomPresetInterface) {
108 break;
109 }
110
111 /** @var PresetInterface $preset */
112 if ($preset->isAvailable()) {
113 $localConfigurationValuesToSet = array_merge(
114 $localConfigurationValuesToSet,
115 $preset->getConfigurationValues()
116 );
117 // Setting for this feature done, go to next feature
118 break;
119 }
120 }
121 }
122 return $localConfigurationValuesToSet;
123 }
124 }