ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
Context.php
Go to the documentation of this file.
1 <?php
2 
11 {
12 
16  private $_storage = array();
17 
23  public function register($name, &$ref) {
24  if (isset($this->_storage[$name])) {
25  trigger_error("Name $name produces collision, cannot re-register",
26  E_USER_ERROR);
27  return;
28  }
29  $this->_storage[$name] =& $ref;
30  }
31 
37  public function &get($name, $ignore_error = false) {
38  if (!isset($this->_storage[$name])) {
39  if (!$ignore_error) {
40  trigger_error("Attempted to retrieve non-existent variable $name",
41  E_USER_ERROR);
42  }
43  $var = null; // so we can return by reference
44  return $var;
45  }
46  return $this->_storage[$name];
47  }
48 
53  public function destroy($name) {
54  if (!isset($this->_storage[$name])) {
55  trigger_error("Attempted to destroy non-existent variable $name",
56  E_USER_ERROR);
57  return;
58  }
59  unset($this->_storage[$name]);
60  }
61 
66  public function exists($name) {
67  return isset($this->_storage[$name]);
68  }
69 
74  public function loadArray($context_array) {
75  foreach ($context_array as $key => $discard) {
76  $this->register($key, $context_array[$key]);
77  }
78  }
79 
80 }
81 
82 // vim: et sw=4 sts=4