[FEATURE] Retrieve sendmail command from PHP configuration
[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 $this->objectManager = $objectManager;
32 }
33
34 /**
35 * @var array List of feature class names
36 */
37 protected $featureRegistry = array(
38 \TYPO3\CMS\Install\Configuration\Charset\CharsetFeature::class,
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 $features = array();
54 foreach ($this->featureRegistry as $featureClass) {
55 /** @var FeatureInterface $featureInstance */
56 $featureInstance = $this->objectManager->get($featureClass);
57 if (!($featureInstance instanceof FeatureInterface)) {
58 throw new Exception(
59 'Feature ' . $featureClass . ' does not implement FeatureInterface',
60 1378644593
61 );
62 }
63 $featureInstance->initializePresets($postValues);
64 $features[] = $featureInstance;
65 }
66 return $features;
67 }
68
69 /**
70 * Get configuration values to be set to LocalConfiguration from
71 * list of selected $POST feature presets
72 *
73 * @param array $postValues List of $POST values
74 * @return array List of configuration values
75 */
76 public function getConfigurationForSelectedFeaturePresets(array $postValues) {
77 $localConfigurationValuesToSet = array();
78 $features = $this->getInitializedFeatures($postValues);
79 foreach ($features as $feature) {
80 /** @var FeatureInterface $feature */
81 $featureName = $feature->getName();
82 $presets = $feature->getPresetsOrderedByPriority();
83 foreach ($presets as $preset) {
84 /** @var PresetInterface $preset */
85 $presetName = $preset->getName();
86 if (!empty($postValues[$featureName]['enable'])
87 && $postValues[$featureName]['enable'] === $presetName
88 && (!$preset->isActive() || $preset instanceof CustomPresetInterface)
89 ) {
90 $localConfigurationValuesToSet = array_merge(
91 $localConfigurationValuesToSet,
92 $preset->getConfigurationValues()
93 );
94 }
95 }
96 }
97 return $localConfigurationValuesToSet;
98 }
99
100 /**
101 * Cycle through features and get settings. First matching
102 * preset (highest priority) will be selected.
103 *
104 * @return array Configuration settings
105 */
106 public function getBestMatchingConfigurationForAllFeatures() {
107 $localConfigurationValuesToSet = array();
108 $features = $this->getInitializedFeatures(array());
109 foreach ($features as $feature) {
110 /** @var FeatureInterface $feature */
111 $presets = $feature->getPresetsOrderedByPriority();
112 foreach ($presets as $preset) {
113 // Only choose "normal" presets, no custom presets
114 if ($preset instanceof CustomPresetInterface) {
115 break;
116 }
117
118 /** @var PresetInterface $preset */
119 if ($preset->isAvailable()) {
120 $localConfigurationValuesToSet = array_merge(
121 $localConfigurationValuesToSet,
122 $preset->getConfigurationValues()
123 );
124 // Setting for this feature done, go to next feature
125 break;
126 }
127 }
128 }
129 return $localConfigurationValuesToSet;
130 }
131
132 }