[TASK] Re-work/simplify copyright header in PHP files - Part 1
[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',
33 'TYPO3\\CMS\\Install\\Configuration\\Context\\ContextFeature',
34 'TYPO3\\CMS\\Install\\Configuration\\Image\\ImageFeature',
35 'TYPO3\\CMS\\Install\\Configuration\\ExtbaseObjectCache\\ExtbaseObjectCacheFeature',
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 . ' doen 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 $featureName = $feature->getName();
105 $presets = $feature->getPresetsOrderedByPriority();
106 foreach ($presets as $preset) {
107 // Only choose "normal" presets, no custom presets
108 if ($preset instanceof CustomPresetInterface) {
109 break;
110 }
111
112 /** @var PresetInterface $preset */
113 if ($preset->isAvailable()) {
114 $localConfigurationValuesToSet = array_merge(
115 $localConfigurationValuesToSet,
116 $preset->getConfigurationValues()
117 );
118 // Setting for this feature done, go to next feature
119 break;
120 }
121 }
122 }
123 return $localConfigurationValuesToSet;
124 }
125 }