[TASK] Get rid of ObjectManager in install tool
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Configuration / AbstractPreset.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 use TYPO3\CMS\Core\Configuration\ConfigurationManager;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * Abstract preset class implements common preset code
22 */
23 abstract class AbstractPreset implements PresetInterface
24 {
25 /**
26 * @var \TYPO3\CMS\Core\Configuration\ConfigurationManager
27 */
28 protected $configurationManager = null;
29
30 /**
31 * @var string Name of preset, must be set by extending classes
32 */
33 protected $name = '';
34
35 /**
36 * @var int Default priority of preset
37 */
38 protected $priority = 50;
39
40 /**
41 * @var array Configuration values handled by this preset
42 */
43 protected $configurationValues = array();
44
45 /**
46 * @var array List of $POST values
47 */
48 protected $postValues = array();
49
50 /**
51 * @param \TYPO3\CMS\Core\Configuration\ConfigurationManager $configurationManager
52 */
53 public function __construct(ConfigurationManager $configurationManager = null)
54 {
55 $this->configurationManager = $configurationManager ?: GeneralUtility::makeInstance(ConfigurationManager::class);
56 }
57
58 /**
59 * Set POST values
60 *
61 * @param array $postValues Post values of feature
62 * @return mixed
63 */
64 public function setPostValues(array $postValues)
65 {
66 $this->postValues = $postValues;
67 }
68
69 /**
70 * Wrapper for isAvailable, used in fluid
71 *
72 * @return bool TRUE if preset is available
73 */
74 public function getIsAvailable()
75 {
76 return $this->isAvailable();
77 }
78
79 /**
80 * Check is preset is currently active on the system
81 *
82 * @return bool TRUE if preset is active
83 */
84 public function isActive()
85 {
86 $isActive = true;
87 foreach ($this->configurationValues as $configurationKey => $configurationValue) {
88 try {
89 $currentValue = $this->configurationManager->getConfigurationValueByPath($configurationKey);
90 } catch (\RuntimeException $e) {
91 $currentValue = null;
92 }
93 if ($currentValue !== $configurationValue) {
94 $isActive = false;
95 break;
96 }
97 }
98 return $isActive;
99 }
100
101 /**
102 * Wrapper for isActive, used in fluid
103 *
104 * @return bool TRUE if preset is active
105 */
106 public function getIsActive()
107 {
108 return $this->isActive();
109 }
110
111 /**
112 * Get name of preset
113 *
114 * @return string Name
115 */
116 public function getName()
117 {
118 return $this->name;
119 }
120
121 /**
122 * Get priority of preset
123 *
124 * @return int Priority, usually between 0 and 100
125 */
126 public function getPriority()
127 {
128 return $this->priority;
129 }
130
131 /**
132 * Get configuration values to activate prefix
133 *
134 * @return array Configuration values needed to activate prefix
135 */
136 public function getConfigurationValues()
137 {
138 return $this->configurationValues;
139 }
140 }