‪TYPO3CMS  9.5
AbstractFeature.php
Go to the documentation of this file.
1 <?php
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 
18 
23 abstract class ‪AbstractFeature
24 {
28  protected ‪$name = '';
29 
33  protected ‪$presetRegistry = [];
34 
38  protected ‪$presetInstances = [];
39 
43  protected ‪$postValues = [];
44 
51  public function ‪initializePresets(array ‪$postValues)
52  {
53  // Give feature sub array of $POST values to preset and set to own property
54  $featurePostValues = [];
55  if (!empty(‪$postValues[$this->name])) {
56  $featurePostValues = ‪$postValues[‪$this->name];
57  }
58  $this->postValues = $featurePostValues;
59 
60  $isNonCustomPresetActive = false;
61  $customPresetFound = false;
62  foreach ($this->presetRegistry as $presetClass) {
64  $presetInstance = GeneralUtility::makeInstance($presetClass);
65  if (!($presetInstance instanceof ‪PresetInterface)) {
66  throw new ‪Exception(
67  'Preset ' . $presetClass . ' does not implement PresetInterface',
68  1378644821
69  );
70  }
71 
72  $presetInstance->setPostValues($featurePostValues);
73 
74  // Custom preset is set active if no preset before is active
75  if ($presetInstance->isActive()) {
76  $isNonCustomPresetActive = true;
77  }
78  if ($presetInstance instanceof ‪CustomPresetInterface
79  && !$isNonCustomPresetActive
80  ) {
81  // Throw Exception if two custom presets are registered
82  if ($customPresetFound === true) {
83  throw new ‪Exception(
84  'Preset ' . $presetClass . ' implements CustomPresetInterface, but another'
85  . ' custom preset is already registered',
86  1378645039
87  );
88  }
89 
91  $presetInstance->setActive();
92  $customPresetFound = true;
93  }
94 
95  $this->presetInstances[] = $presetInstance;
96  }
97  }
98 
105  public function ‪getPresetsOrderedByPriority()
106  {
107  if (empty($this->presetInstances)) {
108  throw new ‪Exception(
109  'Presets not initialized',
110  1378645155
111  );
112  }
113  $orderedPresets = [];
114  foreach ($this->presetInstances as $presetInstance) {
116  $orderedPresets[$presetInstance->getPriority()] = $presetInstance;
117  }
118  krsort($orderedPresets, SORT_NUMERIC);
119  return $orderedPresets;
120  }
121 
127  public function ‪getName()
128  {
129  return ‪$this->name;
130  }
131 }
‪TYPO3\CMS\Install\Configuration\AbstractFeature\$name
‪string $name
Definition: AbstractFeature.php:27
‪TYPO3\CMS\Install\Configuration\PresetInterface
Definition: PresetInterface.php:24
‪TYPO3\CMS\Install\Configuration\AbstractFeature\initializePresets
‪initializePresets(array $postValues)
Definition: AbstractFeature.php:47
‪TYPO3\CMS\Install\Configuration\Exception
Definition: Exception.php:21
‪TYPO3\CMS\Install\Configuration\CustomPresetInterface
Definition: CustomPresetInterface.php:26
‪TYPO3\CMS\Install\Configuration\AbstractFeature\$postValues
‪array $postValues
Definition: AbstractFeature.php:39
‪TYPO3\CMS\Install\Configuration\AbstractFeature\getPresetsOrderedByPriority
‪array< PresetInterface > getPresetsOrderedByPriority()
Definition: AbstractFeature.php:101
‪TYPO3\CMS\Install\Configuration\AbstractFeature\getName
‪string getName()
Definition: AbstractFeature.php:123
‪TYPO3\CMS\Install\Configuration
Definition: AbstractCustomPreset.php:2
‪TYPO3\CMS\Install\Configuration\AbstractFeature
Definition: AbstractFeature.php:24
‪TYPO3\CMS\Install\Configuration\AbstractFeature\$presetInstances
‪array $presetInstances
Definition: AbstractFeature.php:35
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Install\Configuration\AbstractFeature\$presetRegistry
‪array $presetRegistry
Definition: AbstractFeature.php:31