ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilGlobalCacheSettings.php
Go to the documentation of this file.
1 <?php
2 require_once('./Services/GlobalCache/classes/class.ilGlobalCache.php');
3 
11 
12  const LOG_LEVEL_FORCED = - 1;
13  const LOG_LEVEL_NONE = 0;
14  const LOG_LEVEL_SHY = 1;
15  const LOG_LEVEL_NORMAL = 2;
16  const LOG_LEVEL_CHATTY = 3;
17  const INI_HEADER_CACHE = 'cache';
18  const INI_FIELD_ACTIVATE_GLOBAL_CACHE = 'activate_global_cache';
19  const INI_FIELD_GLOBAL_CACHE_SERVICE_TYPE = 'global_cache_service_type';
20  const INI_HEADER_CACHE_ACTIVATED_COMPONENTS = 'cache_activated_components';
21  const INI_FIELD_LOG_LEVEL = 'log_level';
33  protected $active = false;
37  protected $log_level = self::LOG_LEVEL_NONE;
38 
39 
43  public function readFromIniFile(ilIniFile $ilIniFile) {
44  $this->checkIniHeader($ilIniFile);
45  $this->setActive($ilIniFile->readVariable(self::INI_HEADER_CACHE, self::INI_FIELD_ACTIVATE_GLOBAL_CACHE));
46  $this->setService($ilIniFile->readVariable(self::INI_HEADER_CACHE, self::INI_FIELD_GLOBAL_CACHE_SERVICE_TYPE));
47  $this->setLogLevel($ilIniFile->readVariable(self::INI_HEADER_CACHE, self::INI_FIELD_LOG_LEVEL));
48  if (!$this->isActive()) {
49  $this->resetActivatedComponents();
50  } else {
51  $cache_components = $ilIniFile->readGroup(self::INI_HEADER_CACHE_ACTIVATED_COMPONENTS);
52  if (is_array($cache_components)) {
53  foreach ($cache_components as $comp => $v) {
54  if ($v) {
55  $this->addActivatedComponent($comp);
56  }
57  }
58  }
59  }
60  }
61 
62 
66  public function writeToIniFile(ilIniFile $ilIniFile) {
67  $ilIniFile->setVariable(self::INI_HEADER_CACHE, self::INI_FIELD_ACTIVATE_GLOBAL_CACHE, $this->isActive() ? '1' : '0');
68  $ilIniFile->setVariable(self::INI_HEADER_CACHE, self::INI_FIELD_GLOBAL_CACHE_SERVICE_TYPE, $this->getService());
69  $ilIniFile->setVariable(self::INI_HEADER_CACHE, self::INI_FIELD_LOG_LEVEL, $this->getLogLevel());
70 
71  $ilIniFile->removeGroup(self::INI_HEADER_CACHE_ACTIVATED_COMPONENTS);
72  $ilIniFile->addGroup(self::INI_HEADER_CACHE_ACTIVATED_COMPONENTS);
73  foreach (ilGlobalCache::getAvailableComponents() as $comp) {
74  $ilIniFile->setVariable(self::INI_HEADER_CACHE_ACTIVATED_COMPONENTS, $comp, $this->isComponentActivated($comp) ? '1' : '0');
75  }
76  if ($ilIniFile->write()) {
77  ilGlobalCache::log('saved new settings: ' . $this->__toString(), self::LOG_LEVEL_FORCED);
78  }
79  }
80 
81 
82  public function activateAll() {
83  foreach (ilGlobalCache::getAvailableComponents() as $comp) {
84  $this->addActivatedComponent($comp);
85  }
86  }
87 
88 
92  public function addActivatedComponent($component) {
93  $this->activated_components[] = $component;
94  $this->activated_components = array_unique($this->activated_components);
95  }
96 
97 
98  public function resetActivatedComponents() {
99  $this->activated_components = array();
100  }
101 
102 
108  public function isComponentActivated($component) {
109  return in_array($component, $this->activated_components);
110  }
111 
112 
116  public function areAllComponentActivated() {
117  return count($this->activated_components) == count(ilGlobalCache::getAvailableComponents());
118  }
119 
120 
124  public function getService() {
125  return $this->service;
126  }
127 
128 
132  public function setService($service) {
133  $this->service = $service;
134  }
135 
136 
140  public function getActivatedComponents() {
142  }
143 
144 
149  $this->activated_components = $activated_components;
150  }
151 
152 
156  public function isActive() {
157  return $this->active;
158  }
159 
160 
164  public function setActive($active) {
165  $this->active = $active;
166  }
167 
168 
172  protected function checkIniHeader(ilIniFile $ilIniFile) {
173  if (!$ilIniFile->readGroup(self::INI_HEADER_CACHE)) {
174  $ilIniFile->addGroup(self::INI_HEADER_CACHE);
175  }
176  if (!$ilIniFile->readGroup(self::INI_HEADER_CACHE_ACTIVATED_COMPONENTS)) {
177  $ilIniFile->addGroup(self::INI_HEADER_CACHE_ACTIVATED_COMPONENTS);
178  }
179  }
180 
181 
185  public function getLogLevel() {
186  return $this->log_level;
187  }
188 
189 
193  public function setLogLevel($log_level) {
194  $this->log_level = $log_level;
195  }
196 
197 
198  public function __toString() {
199  $service = 'Service: ' . ($this->getService() > 0 ? ilGlobalCache::lookupServiceClassName($this->getService()) : 'none');
200  $activated = 'Activated Components: ' . implode(', ', $this->getActivatedComponents());
201  $log_level = 'Log Level: ' . $this->getLogLevelName();
202 
203  return implode("\n", array( '', '', $service, $activated, $log_level, '' ));
204  }
205 
206 
210  protected function getLogLevelName() {
211  return $this->lookupLogLevelName($this->getLogLevel());
212  }
213 
214 
220  protected function lookupLogLevelName($level) {
221  $r = new ReflectionClass($this);
222  foreach ($r->getConstants() as $k => $v) {
223  if (strpos($k, 'LOG_LEVEL') === 0 AND $v == $level) {
224  return $k;
225  }
226  }
227 
228  return '';
229  }
230 }
231 
232 ?>
checkIniHeader(ilIniFile $ilIniFile)
writeToIniFile(ilIniFile $ilIniFile)
setVariable($a_group_name, $a_var_name, $a_var_value)
sets a variable in a group public
write()
save ini-file-data to filesystem private
readVariable($a_group, $a_var_name)
reads a single variable from a group public
Class ilGlobalCacheSettings.
readFromIniFile(ilIniFile $ilIniFile)
static lookupServiceClassName($service_type)
removeGroup($a_group_name)
removes a group public
$r
Definition: example_031.php:79
static getAvailableComponents()
setActivatedComponents($activated_components)
Create styles array
The data for the language used.
static log($message, $log_level)
INIFile Parser.
addGroup($a_group_name)
adds a new group public
readGroup($a_group_name)
returns an associative array of the variables in one group public