‪TYPO3CMS  10.4
AbstractFeature.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
19 
24 abstract class ‪AbstractFeature
25 {
29  protected ‪$name = '';
30 
34  protected ‪$presetRegistry = [];
35 
39  protected ‪$presetInstances = [];
40 
44  protected ‪$postValues = [];
45 
52  public function ‪initializePresets(array ‪$postValues)
53  {
54  // Give feature sub array of $POST values to preset and set to own property
55  $featurePostValues = [];
56  if (!empty(‪$postValues[$this->name])) {
57  $featurePostValues = ‪$postValues[‪$this->name];
58  }
59  $this->postValues = $featurePostValues;
60 
61  $isNonCustomPresetActive = false;
62  $customPresetFound = false;
63  foreach ($this->presetRegistry as $presetClass) {
65  $presetInstance = GeneralUtility::makeInstance($presetClass);
66  if (!($presetInstance instanceof ‪PresetInterface)) {
67  throw new ‪Exception(
68  'Preset ' . $presetClass . ' does not implement PresetInterface',
69  1378644821
70  );
71  }
72 
73  $presetInstance->setPostValues($featurePostValues);
74 
75  // Custom preset is set active if no preset before is active
76  if ($presetInstance->isActive()) {
77  $isNonCustomPresetActive = true;
78  }
79  if ($presetInstance instanceof ‪CustomPresetInterface
80  && !$isNonCustomPresetActive
81  ) {
82  // Throw Exception if two custom presets are registered
83  if ($customPresetFound === true) {
84  throw new ‪Exception(
85  'Preset ' . $presetClass . ' implements CustomPresetInterface, but another'
86  . ' custom preset is already registered',
87  1378645039
88  );
89  }
90 
92  $presetInstance->setActive();
93  $customPresetFound = true;
94  }
95 
96  $this->presetInstances[] = $presetInstance;
97  }
98  }
99 
106  public function ‪getPresetsOrderedByPriority()
107  {
108  if (empty($this->presetInstances)) {
109  throw new ‪Exception(
110  'Presets not initialized',
111  1378645155
112  );
113  }
114  $orderedPresets = [];
115  foreach ($this->presetInstances as $presetInstance) {
117  $orderedPresets[$presetInstance->getPriority()] = $presetInstance;
118  }
119  krsort($orderedPresets, SORT_NUMERIC);
120  return $orderedPresets;
121  }
122 
128  public function ‪getName()
129  {
130  return ‪$this->name;
131  }
132 }
‪TYPO3\CMS\Install\Configuration\AbstractFeature\getPresetsOrderedByPriority
‪array PresetInterface[] getPresetsOrderedByPriority()
Definition: AbstractFeature.php:102
‪TYPO3\CMS\Install\Configuration\AbstractFeature\$name
‪string $name
Definition: AbstractFeature.php:28
‪TYPO3\CMS\Install\Configuration\PresetInterface
Definition: PresetInterface.php:25
‪TYPO3\CMS\Install\Configuration\AbstractFeature\initializePresets
‪initializePresets(array $postValues)
Definition: AbstractFeature.php:48
‪TYPO3\CMS\Install\Configuration\Exception
Definition: Exception.php:22
‪TYPO3\CMS\Install\Configuration\CustomPresetInterface
Definition: CustomPresetInterface.php:27
‪TYPO3\CMS\Install\Configuration\AbstractFeature\$postValues
‪array $postValues
Definition: AbstractFeature.php:40
‪TYPO3\CMS\Install\Configuration\AbstractFeature\getName
‪string getName()
Definition: AbstractFeature.php:124
‪TYPO3\CMS\Install\Configuration
Definition: AbstractCustomPreset.php:16
‪TYPO3\CMS\Install\Configuration\AbstractFeature
Definition: AbstractFeature.php:25
‪TYPO3\CMS\Install\Configuration\AbstractFeature\$presetInstances
‪array $presetInstances
Definition: AbstractFeature.php:36
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Install\Configuration\AbstractFeature\$presetRegistry
‪array $presetRegistry
Definition: AbstractFeature.php:32