ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  {
45  $this->checkIniHeader($ilIniFile);
46  $this->setActive($ilIniFile->readVariable(self::INI_HEADER_CACHE, self::INI_FIELD_ACTIVATE_GLOBAL_CACHE));
47  $this->setService($ilIniFile->readVariable(self::INI_HEADER_CACHE, self::INI_FIELD_GLOBAL_CACHE_SERVICE_TYPE));
48  $this->setLogLevel($ilIniFile->readVariable(self::INI_HEADER_CACHE, self::INI_FIELD_LOG_LEVEL));
49  if (!$this->isActive()) {
50  $this->resetActivatedComponents();
51  } else {
52  $cache_components = $ilIniFile->readGroup(self::INI_HEADER_CACHE_ACTIVATED_COMPONENTS);
53  if (is_array($cache_components)) {
54  foreach ($cache_components as $comp => $v) {
55  if ($v) {
56  $this->addActivatedComponent($comp);
57  }
58  }
59  }
60  }
61  }
62 
63 
67  public function writeToIniFile(ilIniFile $ilIniFile)
68  {
69  $ilIniFile->setVariable(self::INI_HEADER_CACHE, self::INI_FIELD_ACTIVATE_GLOBAL_CACHE, $this->isActive() ? '1' : '0');
70  $ilIniFile->setVariable(self::INI_HEADER_CACHE, self::INI_FIELD_GLOBAL_CACHE_SERVICE_TYPE, $this->getService());
71  $ilIniFile->setVariable(self::INI_HEADER_CACHE, self::INI_FIELD_LOG_LEVEL, $this->getLogLevel());
72 
73  $ilIniFile->removeGroup(self::INI_HEADER_CACHE_ACTIVATED_COMPONENTS);
74  $ilIniFile->addGroup(self::INI_HEADER_CACHE_ACTIVATED_COMPONENTS);
75  foreach (ilGlobalCache::getAvailableComponents() as $comp) {
76  $ilIniFile->setVariable(self::INI_HEADER_CACHE_ACTIVATED_COMPONENTS, $comp, $this->isComponentActivated($comp) ? '1' : '0');
77  }
78  if ($ilIniFile->write()) {
79  ilGlobalCache::log('saved new settings: ' . $this->__toString(), self::LOG_LEVEL_FORCED);
80  }
81  }
82 
83 
84  public function activateAll()
85  {
86  foreach (ilGlobalCache::getAvailableComponents() as $comp) {
87  $this->addActivatedComponent($comp);
88  }
89  }
90 
91 
95  public function addActivatedComponent($component)
96  {
97  $this->activated_components[] = $component;
98  $this->activated_components = array_unique($this->activated_components);
99  }
100 
101 
102  public function resetActivatedComponents()
103  {
104  $this->activated_components = array();
105  }
106 
107 
113  public function isComponentActivated($component)
114  {
115  return in_array($component, $this->activated_components);
116  }
117 
118 
122  public function areAllComponentActivated()
123  {
124  return count($this->activated_components) == count(ilGlobalCache::getAvailableComponents());
125  }
126 
127 
131  public function getService()
132  {
133  return $this->service;
134  }
135 
136 
140  public function setService($service)
141  {
142  $this->service = $service;
143  }
144 
145 
149  public function getActivatedComponents()
150  {
152  }
153 
154 
159  {
160  $this->activated_components = $activated_components;
161  }
162 
163 
167  public function isActive()
168  {
169  return $this->active;
170  }
171 
172 
176  public function setActive($active)
177  {
178  $this->active = $active;
179  }
180 
181 
185  protected function checkIniHeader(ilIniFile $ilIniFile)
186  {
187  if (!$ilIniFile->readGroup(self::INI_HEADER_CACHE)) {
188  $ilIniFile->addGroup(self::INI_HEADER_CACHE);
189  }
190  if (!$ilIniFile->readGroup(self::INI_HEADER_CACHE_ACTIVATED_COMPONENTS)) {
191  $ilIniFile->addGroup(self::INI_HEADER_CACHE_ACTIVATED_COMPONENTS);
192  }
193  }
194 
195 
199  public function getLogLevel()
200  {
201  return $this->log_level;
202  }
203 
204 
208  public function setLogLevel($log_level)
209  {
210  $this->log_level = $log_level;
211  }
212 
213 
214  public function __toString()
215  {
216  $service = 'Service: ' . ($this->getService() > 0 ? ilGlobalCache::lookupServiceClassName($this->getService()) : 'none');
217  $activated = 'Activated Components: ' . implode(', ', $this->getActivatedComponents());
218  $log_level = 'Log Level: ' . $this->getLogLevelName();
219 
220  return implode("\n", array( '', '', $service, $activated, $log_level, '' ));
221  }
222 
223 
227  protected function getLogLevelName()
228  {
229  return $this->lookupLogLevelName($this->getLogLevel());
230  }
231 
232 
238  protected function lookupLogLevelName($level)
239  {
240  $r = new ReflectionClass($this);
241  foreach ($r->getConstants() as $k => $v) {
242  if (strpos($k, 'LOG_LEVEL') === 0 and $v == $level) {
243  return $k;
244  }
245  }
246 
247  return '';
248  }
249 }
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