91950f0881377eac02f196a89350806a0a57ba84
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Configuration / AbstractPreset.php
1 <?php
2 namespace TYPO3\CMS\Install\Configuration;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2013 Christian Kuhn <lolli@schwarzbu.ch>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 use TYPO3\CMS\Core\Utility\GeneralUtility;
28
29 /**
30 * Abstract preset class implements common preset code
31 */
32 abstract class AbstractPreset implements PresetInterface {
33
34 /**
35 * @var \TYPO3\CMS\Core\Configuration\ConfigurationManager
36 * @inject
37 */
38 protected $configurationManager = NULL;
39
40 /**
41 * @var string Name of preset, must be set by extending classes
42 */
43 protected $name = '';
44
45 /**
46 * @var integer Default priority of preset
47 */
48 protected $priority = 50;
49
50 /**
51 * @var array Configuration values handled by this preset
52 */
53 protected $configurationValues = array();
54
55 /**
56 * @var array List of $POST values
57 */
58 protected $postValues = array();
59
60 /**
61 * Set POST values
62 *
63 * @param array $postValues Post values of feature
64 * @return mixed
65 */
66 public function setPostValues(array $postValues) {
67 $this->postValues = $postValues;
68 }
69
70 /**
71 * Wrapper for isAvailable, used in fluid
72 *
73 * @return boolean TRUE if preset is available
74 */
75 public function getIsAvailable() {
76 return $this->isAvailable();
77 }
78
79 /**
80 * Check is preset is currently active on the system
81 *
82 * @return boolean TRUE if preset is active
83 */
84 public function isActive() {
85 $isActive = TRUE;
86 foreach ($this->configurationValues as $configurationKey => $configurationValue) {
87 try {
88 $currentValue = $this->configurationManager->getConfigurationValueByPath($configurationKey);
89 } catch (\RuntimeException $e) {
90 $currentValue = NULL;
91 }
92 if ($currentValue !== $configurationValue) {
93 $isActive = FALSE;
94 break;
95 }
96 }
97 return $isActive;
98 }
99
100 /**
101 * Wrapper for isActive, used in fluid
102 *
103 * @return boolean TRUE if preset is active
104 */
105 public function getIsActive() {
106 return $this->isActive();
107 }
108
109 /**
110 * Get name of preset
111 *
112 * @return string Name
113 */
114 public function getName() {
115 return $this->name;
116 }
117
118 /**
119 * Get priority of preset
120 *
121 * @return integer Priority, usually between 0 and 100
122 */
123 public function getPriority() {
124 return $this->priority;
125 }
126
127 /**
128 * Get configuration values to activate prefix
129 *
130 * @return array Configuration values needed to activate prefix
131 */
132 public function getConfigurationValues() {
133 return $this->configurationValues;
134 }
135 }