TYPO3 CMS  TYPO3_6-2
FeatureManager.php
Go to the documentation of this file.
1 <?php
3 
21 
26  protected $objectManager = NULL;
27 
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 
45  public function getInitializedFeatures(array $postValues) {
46  $features = array();
47  foreach ($this->featureRegistry as $featureClass) {
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 
69  public function getConfigurationForSelectedFeaturePresets(array $postValues) {
70  $localConfigurationValuesToSet = array();
71  $features = $this->getInitializedFeatures($postValues);
72  foreach ($features as $feature) {
74  $featureName = $feature->getName();
75  $presets = $feature->getPresetsOrderedByPriority();
76  foreach ($presets as $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 
99  public function getBestMatchingConfigurationForAllFeatures() {
100  $localConfigurationValuesToSet = array();
101  $features = $this->getInitializedFeatures(array());
102  foreach ($features as $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 
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 }