ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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';
29  protected $activated_components = array();
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 
85  public function addActivatedComponent($component) {
86  $this->activated_components[] = $component;
87  $this->activated_components = array_unique($this->activated_components);
88  }
89 
90 
91  public function resetActivatedComponents() {
92  $this->activated_components = array();
93  }
94 
95 
101  public function isComponentActivated($component) {
102  return in_array($component, $this->activated_components);
103  }
104 
105 
109  public function getService() {
110  return $this->service;
111  }
112 
113 
117  public function setService($service) {
118  $this->service = $service;
119  }
120 
121 
125  public function getActivatedComponents() {
127  }
128 
129 
134  $this->activated_components = $activated_components;
135  }
136 
137 
141  public function isActive() {
142  return $this->active;
143  }
144 
145 
149  public function setActive($active) {
150  $this->active = $active;
151  }
152 
153 
157  protected function checkIniHeader(ilIniFile $ilIniFile) {
158  if (! $ilIniFile->readGroup(self::INI_HEADER_CACHE)) {
159  $ilIniFile->addGroup(self::INI_HEADER_CACHE);
160  }
161  if (! $ilIniFile->readGroup(self::INI_HEADER_CACHE_ACTIVATED_COMPONENTS)) {
162  $ilIniFile->addGroup(self::INI_HEADER_CACHE_ACTIVATED_COMPONENTS);
163  }
164  }
165 
166 
170  public function getLogLevel() {
171  return $this->log_level;
172  }
173 
174 
178  public function setLogLevel($log_level) {
179  $this->log_level = $log_level;
180  }
181 
182 
183  public function __toString() {
184  $service = 'Service: ' . ($this->getService() > 0 ? ilGlobalCache::lookupServiceClassName($this->getService()) : 'none');
185  $activated = 'Activated Components: ' . implode(', ', $this->getActivatedComponents());
186  $log_level = 'Log Level: ' . $this->getLogLevelName();
187 
188  return implode("\n", array( '', '', $service, $activated, $log_level, '' ));
189  }
190 
191 
195  protected function getLogLevelName() {
196  return $this->lookupLogLevelName($this->getLogLevel());
197  }
198 
199 
205  protected function lookupLogLevelName($level) {
206  $r = new ReflectionClass($this);
207  foreach ($r->getConstants() as $k => $v) {
208  if (strpos($k, 'LOG_LEVEL') === 0 AND $v == $level) {
209  return $k;
210  }
211  }
212 
213  return '';
214  }
215 }
216 
217 ?>
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)
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