[TASK] Remove closing PHP tags
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Configuration / FeatureManager.php
1 <?php
2 namespace TYPO3\CMS\Install\Configuration;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2013 Christian Kuhn <lolli@schwarzbu.ch>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Instantiate and configure all known features and presets
29 */
30 class FeatureManager {
31
32 /**
33 * @var \TYPO3\CMS\Extbase\Object\ObjectManager
34 * @inject
35 */
36 protected $objectManager = NULL;
37
38 /**
39 * @var array List of feature class names
40 */
41 protected $featureRegistry = array(
42 'TYPO3\\CMS\\Install\\Configuration\\Charset\\CharsetFeature',
43 'TYPO3\\CMS\\Install\\Configuration\\Context\\ContextFeature',
44 'TYPO3\\CMS\\Install\\Configuration\\Image\\ImageFeature',
45 'TYPO3\\CMS\\Install\\Configuration\\ExtbaseObjectCache\\ExtbaseObjectCacheFeature',
46 );
47
48 /**
49 * Get initialized list of features with possible presets
50 *
51 * @param array $postValues List of $POST values
52 * @return array<FeatureInterface>
53 * @throws Exception
54 */
55 public function getInitializedFeatures(array $postValues) {
56 $features = array();
57 foreach ($this->featureRegistry as $featureClass) {
58 /** @var FeatureInterface $featureInstance */
59 $featureInstance = $this->objectManager->get($featureClass);
60 if (!($featureInstance instanceof FeatureInterface)) {
61 throw new Exception(
62 'Feature ' . $featureClass . ' doen not implement FeatureInterface',
63 1378644593
64 );
65 }
66 $featureInstance->initializePresets($postValues);
67 $features[] = $featureInstance;
68 }
69 return $features;
70 }
71
72 /**
73 * Get configuration values to be set to LocalConfiguration from
74 * list of selected $POST feature presets
75 *
76 * @param array $postValues List of $POST values
77 * @return array List of configuration values
78 */
79 public function getConfigurationForSelectedFeaturePresets(array $postValues) {
80 $localConfigurationValuesToSet = array();
81 $features = $this->getInitializedFeatures($postValues);
82 foreach ($features as $feature) {
83 /** @var FeatureInterface $feature */
84 $featureName = $feature->getName();
85 $presets = $feature->getPresetsOrderedByPriority();
86 foreach ($presets as $preset) {
87 /** @var PresetInterface $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
103 /**
104 * Cycle through features and get settings. First matching
105 * preset (highest priority) will be selected.
106 *
107 * @return array Configuration settings
108 */
109 public function getBestMatchingConfigurationForAllFeatures() {
110 $localConfigurationValuesToSet = array();
111 $features = $this->getInitializedFeatures(array());
112 foreach ($features as $feature) {
113 /** @var FeatureInterface $feature */
114 $featureName = $feature->getName();
115 $presets = $feature->getPresetsOrderedByPriority();
116 foreach ($presets as $preset) {
117 // Only chose "normal" presets, no custom presets
118 if ($preset instanceof CustomPresetInterface) {
119 break;
120 }
121
122 /** @var PresetInterface $preset */
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 }