ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilGlobalCacheSettings.php
Go to the documentation of this file.
1<?php
2require_once('./Services/GlobalCache/classes/class.ilGlobalCache.php');
3
5
13{
14 const LOG_LEVEL_FORCED = -1;
15 const LOG_LEVEL_NONE = 0;
16 const LOG_LEVEL_SHY = 1;
19 const INI_HEADER_CACHE = 'cache';
20 const INI_FIELD_ACTIVATE_GLOBAL_CACHE = 'activate_global_cache';
21 const INI_FIELD_GLOBAL_CACHE_SERVICE_TYPE = 'global_cache_service_type';
22 const INI_HEADER_CACHE_ACTIVATED_COMPONENTS = 'cache_activated_components';
23 const INI_FIELD_LOG_LEVEL = 'log_level';
31 protected $activated_components = array();
35 protected $active = false;
40
41
45 public function readFromIniFile(ilIniFile $ilIniFile)
46 {
47 $this->checkIniHeader($ilIniFile);
48 $this->setActive($ilIniFile->readVariable(self::INI_HEADER_CACHE, self::INI_FIELD_ACTIVATE_GLOBAL_CACHE));
49 $this->setService($ilIniFile->readVariable(self::INI_HEADER_CACHE, self::INI_FIELD_GLOBAL_CACHE_SERVICE_TYPE));
50 $this->setLogLevel($ilIniFile->readVariable(self::INI_HEADER_CACHE, self::INI_FIELD_LOG_LEVEL));
51 if (!$this->isActive()) {
53 } else {
54 $cache_components = $ilIniFile->readGroup(self::INI_HEADER_CACHE_ACTIVATED_COMPONENTS);
55 if (is_array($cache_components)) {
56 foreach ($cache_components as $comp => $v) {
57 if ($v) {
58 $this->addActivatedComponent($comp);
59 }
60 }
61 }
62 }
63 }
64
65
69 public function writeToIniFile(ilIniFile $ilIniFile)
70 {
71 $ilIniFile->setVariable(self::INI_HEADER_CACHE, self::INI_FIELD_ACTIVATE_GLOBAL_CACHE, $this->isActive() ? '1' : '0');
72 $ilIniFile->setVariable(self::INI_HEADER_CACHE, self::INI_FIELD_GLOBAL_CACHE_SERVICE_TYPE, $this->getService());
73 $ilIniFile->setVariable(self::INI_HEADER_CACHE, self::INI_FIELD_LOG_LEVEL, $this->getLogLevel());
74
75 $ilIniFile->removeGroup(self::INI_HEADER_CACHE_ACTIVATED_COMPONENTS);
76 $ilIniFile->addGroup(self::INI_HEADER_CACHE_ACTIVATED_COMPONENTS);
77 foreach (ilGlobalCache::getAvailableComponents() as $comp) {
78 $ilIniFile->setVariable(self::INI_HEADER_CACHE_ACTIVATED_COMPONENTS, $comp, $this->isComponentActivated($comp) ? '1' : '0');
79 }
80 if ($ilIniFile->write()) {
81 ilGlobalCache::log('saved new settings: ' . $this->__toString(), self::LOG_LEVEL_FORCED);
82 }
83 }
84
85
86 public function activateAll()
87 {
88 foreach (ilGlobalCache::getAvailableComponents() as $comp) {
89 $this->addActivatedComponent($comp);
90 }
91 }
92
93
97 public function addActivatedComponent($component)
98 {
99 $this->activated_components[] = $component;
100 $this->activated_components = array_unique($this->activated_components);
101 }
102
103
104 public function resetActivatedComponents()
105 {
106 $this->activated_components = array();
107 }
108
109
115 public function isComponentActivated($component)
116 {
117 return in_array($component, $this->activated_components);
118 }
119
120
124 public function areAllComponentActivated()
125 {
126 return count($this->activated_components) == count(ilGlobalCache::getAvailableComponents());
127 }
128
129
133 public function getService()
134 {
135 return $this->service;
136 }
137
138
142 public function setService($service)
143 {
144 $this->service = $service;
145 }
146
147
151 public function getActivatedComponents()
152 {
154 }
155
156
161 {
162 $this->activated_components = $activated_components;
163 }
164
165
169 public function isActive()
170 {
171 return $this->active;
172 }
173
174
178 public function setActive($active)
179 {
180 $this->active = $active;
181 }
182
183
187 protected function checkIniHeader(ilIniFile $ilIniFile)
188 {
189 if (!$ilIniFile->readGroup(self::INI_HEADER_CACHE)) {
190 $ilIniFile->addGroup(self::INI_HEADER_CACHE);
191 }
192 if (!$ilIniFile->readGroup(self::INI_HEADER_CACHE_ACTIVATED_COMPONENTS)) {
193 $ilIniFile->addGroup(self::INI_HEADER_CACHE_ACTIVATED_COMPONENTS);
194 }
195 }
196
197
201 public function getLogLevel()
202 {
203 return $this->log_level;
204 }
205
206
210 public function setLogLevel($log_level)
211 {
212 $this->log_level = $log_level;
213 }
214
215
216 public function __toString()
217 {
218 $service = 'Service: ' . ($this->getService() > 0 ? ilGlobalCache::lookupServiceClassName($this->getService()) : 'none');
219 $activated = 'Activated Components: ' . implode(', ', $this->getActivatedComponents());
220 $log_level = 'Log Level: ' . $this->getLogLevelName();
221
222 return implode("\n", array( '', '', $service, $activated, $log_level, '' ));
223 }
224
225
229 protected function getLogLevelName()
230 {
231 return $this->lookupLogLevelName($this->getLogLevel());
232 }
233
234
240 protected function lookupLogLevelName($level)
241 {
242 $r = new ReflectionClass($this);
243 foreach ($r->getConstants() as $k => $v) {
244 if (strpos($k, 'LOG_LEVEL') === 0 and $v == $level) {
245 return $k;
246 }
247 }
248
249 return '';
250 }
251}
An exception for terminatinating execution or to throw for unit testing.
Class ilGlobalCacheSettings.
writeToIniFile(ilIniFile $ilIniFile)
checkIniHeader(ilIniFile $ilIniFile)
setActivatedComponents($activated_components)
readFromIniFile(ilIniFile $ilIniFile)
static lookupServiceClassName($service_type)
static log($message, $log_level)
static getAvailableComponents()
INIFile Parser.
write()
save ini-file-data to filesystem @access private
A configuration for the setup.
Definition: Config.php:11