Elgg  Version 1.9
DeprecationWrapper.php
Go to the documentation of this file.
1 <?php
23 class Elgg_DeprecationWrapper implements ArrayAccess {
25  protected $object;
26 
28  protected $string;
29 
31  protected $message;
32 
34  protected $version;
35 
37  protected $reporter;
38 
47  public function __construct($object, $message, $version, $reporter = 'elgg_deprecated_notice') {
48  if (is_object($object)) {
49  $this->object = $object;
50  } else {
51  $this->string = $object;
52  }
53  $this->message = $message;
54  $this->version = $version;
55  $this->reporter = $reporter;
56  }
57 
64  public function __get($name) {
65  $this->displayWarning();
66  return $this->object->$name;
67  }
68 
76  public function __set($name, $value) {
77  $this->displayWarning();
78  $this->object->$name = $value;
79  }
80 
88  public function __call($name, $arguments) {
89  $this->displayWarning();
90  return call_user_func_array(array($this->object, $name), $arguments);
91  }
92 
98  public function __toString() {
99  $this->displayWarning();
100  if (isset($this->string)) {
101  return $this->string;
102  } else {
103  return (string) $this->object;
104  }
105  }
106 
112  protected function displayWarning() {
113  // display 3 levels in the function stack to get back to original use
114  // 1 for __get/__call/__toString()
115  // 1 for displayWarning()
116  // 1 for call_user_func()
117  call_user_func($this->reporter, $this->message, $this->version, 3);
118  }
119 
130  public function offsetSet($key, $value) {
131  $this->displayWarning();
132  if (is_object($this->object) && !$this->object instanceof ArrayAccess) {
133  $this->object->$key = $value;
134  } else {
135  if ($key === null) {
136  // Yes this is necessary. Otherwise $key will be interpreted as empty string
137  $this->object[] = $value;
138  } else {
139  $this->object[$key] = $value;
140  }
141  }
142  }
143 
153  public function offsetGet($key) {
154  $this->displayWarning();
155  if (is_object($this->object) && !$this->object instanceof ArrayAccess) {
156  return $this->object->$key;
157  } else {
158  return $this->object[$key];
159  }
160  }
161 
171  public function offsetUnset($key) {
172  $this->displayWarning();
173  if (is_object($this->object) && !$this->object instanceof ArrayAccess) {
174  unset($this->object->$key);
175  } else {
176  unset($this->object[$key]);
177  }
178  }
179 
189  public function offsetExists($offset) {
190  $this->displayWarning();
191  if (is_object($this->object) && !$this->object instanceof ArrayAccess) {
192  return isset($this->object->$offset);
193  } else {
194  return array_key_exists($offset, $this->object);
195  }
196  }
197 }
elgg message
Definition: admin.php:231
__construct($object, $message, $version, $reporter= 'elgg_deprecated_notice')
Create the wrapper.
offsetExists($offset)
Array access interface.
__set($name, $value)
Set a property on the object.
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
__toString()
Get the object as string.
if(elgg_in_context('widget')) $offset
Definition: pagination.php:20
$value
Definition: longtext.php:29
string version
Definition: conf.py:51
displayWarning()
Display a warning.
$key
Definition: summary.php:34
__call($name, $arguments)
Call a method on the object.
offsetGet($key)
Array access interface.
offsetUnset($key)
Array access interface.
__get($name)
Get a property on the object.
offsetSet($key, $value)
Array access interface.