[!!!][TASK] Replace ClassInfo with ClassSchema
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Configuration / FeatureManager.php
index c20273b..567b883 100644 (file)
@@ -14,118 +14,112 @@ namespace TYPO3\CMS\Install\Configuration;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Install\Configuration\Context\ContextFeature;
+use TYPO3\CMS\Install\Configuration\Image\ImageFeature;
+use TYPO3\CMS\Install\Configuration\Mail\MailFeature;
+
 /**
  * Instantiate and configure all known features and presets
  */
-class FeatureManager {
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Object\ObjectManager
-        */
-       protected $objectManager = NULL;
-
-       /**
-        * @param \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager
-        */
-       public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManager $objectManager) {
-               $this->objectManager = $objectManager;
-       }
-
-       /**
-        * @var array List of feature class names
-        */
-       protected $featureRegistry = array(
-               \TYPO3\CMS\Install\Configuration\Charset\CharsetFeature::class,
-               \TYPO3\CMS\Install\Configuration\Context\ContextFeature::class,
-               \TYPO3\CMS\Install\Configuration\Image\ImageFeature::class,
-               \TYPO3\CMS\Install\Configuration\ExtbaseObjectCache\ExtbaseObjectCacheFeature::class,
-       );
-
-       /**
-        * Get initialized list of features with possible presets
-        *
-        * @param array $postValues List of $POST values
-        * @return array<FeatureInterface>
-        * @throws Exception
-        */
-       public function getInitializedFeatures(array $postValues) {
-               $features = array();
-               foreach ($this->featureRegistry as $featureClass) {
-                       /** @var FeatureInterface $featureInstance */
-                       $featureInstance = $this->objectManager->get($featureClass);
-                       if (!($featureInstance instanceof FeatureInterface)) {
-                               throw new Exception(
-                                       'Feature ' . $featureClass . ' does not implement FeatureInterface',
-                                       1378644593
-                               );
-                       }
-                       $featureInstance->initializePresets($postValues);
-                       $features[] = $featureInstance;
-               }
-               return $features;
-       }
+class FeatureManager
+{
+    /**
+     * @var array List of feature class names
+     */
+    protected $featureRegistry = [
+        ContextFeature::class,
+        ImageFeature::class,
+        MailFeature::class,
+    ];
 
-       /**
-        * Get configuration values to be set to LocalConfiguration from
-        * list of selected $POST feature presets
-        *
-        * @param array $postValues List of $POST values
-        * @return array List of configuration values
-        */
-       public function getConfigurationForSelectedFeaturePresets(array $postValues) {
-               $localConfigurationValuesToSet = array();
-               $features = $this->getInitializedFeatures($postValues);
-               foreach ($features as $feature) {
-                       /** @var FeatureInterface $feature */
-                       $featureName = $feature->getName();
-                       $presets = $feature->getPresetsOrderedByPriority();
-                       foreach ($presets as $preset) {
-                               /** @var PresetInterface $preset */
-                               $presetName = $preset->getName();
-                               if (!empty($postValues[$featureName]['enable'])
-                                       && $postValues[$featureName]['enable'] === $presetName
-                                       && (!$preset->isActive() || $preset instanceof CustomPresetInterface)
-                               ) {
-                                       $localConfigurationValuesToSet = array_merge(
-                                               $localConfigurationValuesToSet,
-                                               $preset->getConfigurationValues()
-                                       );
-                               }
-                       }
-               }
-               return $localConfigurationValuesToSet;
-       }
+    /**
+     * Get initialized list of features with possible presets
+     *
+     * @param array $postValues List of $POST values
+     * @return FeatureInterface[]
+     * @throws Exception
+     */
+    public function getInitializedFeatures(array $postValues = [])
+    {
+        $features = [];
+        foreach ($this->featureRegistry as $featureClass) {
+            /** @var FeatureInterface $featureInstance */
+            $featureInstance = GeneralUtility::makeInstance($featureClass);
+            if (!($featureInstance instanceof FeatureInterface)) {
+                throw new Exception(
+                    'Feature ' . $featureClass . ' does not implement FeatureInterface',
+                    1378644593
+                );
+            }
+            $featureInstance->initializePresets($postValues);
+            $features[] = $featureInstance;
+        }
+        return $features;
+    }
 
-       /**
-        * Cycle through features and get settings. First matching
-        * preset (highest priority) will be selected.
-        *
-        * @return array Configuration settings
-        */
-       public function getBestMatchingConfigurationForAllFeatures() {
-               $localConfigurationValuesToSet = array();
-               $features = $this->getInitializedFeatures(array());
-               foreach ($features as $feature) {
-                       /** @var FeatureInterface $feature */
-                       $presets = $feature->getPresetsOrderedByPriority();
-                       foreach ($presets as $preset) {
-                               // Only choose "normal" presets, no custom presets
-                               if ($preset instanceof CustomPresetInterface) {
-                                       break;
-                               }
+    /**
+     * Get configuration values to be set to LocalConfiguration from
+     * list of selected $POST feature presets
+     *
+     * @param array $postValues List of $POST values
+     * @return array List of configuration values
+     */
+    public function getConfigurationForSelectedFeaturePresets(array $postValues)
+    {
+        $localConfigurationValuesToSet = [];
+        $features = $this->getInitializedFeatures($postValues);
+        foreach ($features as $feature) {
+            /** @var FeatureInterface $feature */
+            $featureName = $feature->getName();
+            $presets = $feature->getPresetsOrderedByPriority();
+            foreach ($presets as $preset) {
+                /** @var PresetInterface $preset */
+                $presetName = $preset->getName();
+                if (!empty($postValues[$featureName]['enable'])
+                    && $postValues[$featureName]['enable'] === $presetName
+                    && (!$preset->isActive() || $preset instanceof CustomPresetInterface)
+                ) {
+                    $localConfigurationValuesToSet = array_merge(
+                        $localConfigurationValuesToSet,
+                        $preset->getConfigurationValues()
+                    );
+                }
+            }
+        }
+        return $localConfigurationValuesToSet;
+    }
 
-                               /** @var PresetInterface $preset */
-                               if ($preset->isAvailable()) {
-                                       $localConfigurationValuesToSet = array_merge(
-                                               $localConfigurationValuesToSet,
-                                               $preset->getConfigurationValues()
-                                       );
-                                       // Setting for this feature done, go to next feature
-                                       break;
-                               }
-                       }
-               }
-               return $localConfigurationValuesToSet;
-       }
+    /**
+     * Cycle through features and get settings. First matching
+     * preset (highest priority) will be selected.
+     *
+     * @return array Configuration settings
+     */
+    public function getBestMatchingConfigurationForAllFeatures()
+    {
+        $localConfigurationValuesToSet = [];
+        $features = $this->getInitializedFeatures([]);
+        foreach ($features as $feature) {
+            /** @var FeatureInterface $feature */
+            $presets = $feature->getPresetsOrderedByPriority();
+            foreach ($presets as $preset) {
+                // Only choose "normal" presets, no custom presets
+                if ($preset instanceof CustomPresetInterface) {
+                    break;
+                }
 
+                /** @var PresetInterface $preset */
+                if ($preset->isAvailable()) {
+                    $localConfigurationValuesToSet = array_merge(
+                        $localConfigurationValuesToSet,
+                        $preset->getConfigurationValues()
+                    );
+                    // Setting for this feature done, go to next feature
+                    break;
+                }
+            }
+        }
+        return $localConfigurationValuesToSet;
+    }
 }