Elgg  Version 2.2
DeprecationWrapper.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg;
25 class DeprecationWrapper implements \ArrayAccess {
27  protected $object;
28 
30  protected $string;
31 
33  protected $message;
34 
36  protected $version;
37 
39  protected $reporter;
40 
49  public function __construct($object, $message, $version, $reporter = 'elgg_deprecated_notice') {
50  if (is_object($object)) {
51  $this->object = $object;
52  } else {
53  $this->string = $object;
54  }
55  $this->message = $message;
56  $this->version = $version;
57  $this->reporter = $reporter;
58  }
59 
66  public function __get($name) {
67  $this->displayWarning();
68  return $this->object->$name;
69  }
70 
78  public function __set($name, $value) {
79  $this->displayWarning();
80  $this->object->$name = $value;
81  }
82 
90  public function __call($name, $arguments) {
91  $this->displayWarning();
92  return call_user_func_array(array($this->object, $name), $arguments);
93  }
94 
100  public function __toString() {
101  $this->displayWarning();
102  if (isset($this->string)) {
103  return $this->string;
104  } else {
105  return (string) $this->object;
106  }
107  }
108 
114  protected function displayWarning() {
115  // display 3 levels in the function stack to get back to original use
116  // 1 for __get/__call/__toString()
117  // 1 for displayWarning()
118  // 1 for call_user_func()
119  call_user_func($this->reporter, $this->message, $this->version, 3);
120  }
121 
132  public function offsetSet($key, $value) {
133  $this->displayWarning();
134  if (is_object($this->object) && !$this->object instanceof \ArrayAccess) {
135  $this->object->$key = $value;
136  } else {
137  if ($key === null) {
138  // Yes this is necessary. Otherwise $key will be interpreted as empty string
139  $this->object[] = $value;
140  } else {
141  $this->object[$key] = $value;
142  }
143  }
144  }
145 
155  public function offsetGet($key) {
156  $this->displayWarning();
157  if (is_object($this->object) && !$this->object instanceof \ArrayAccess) {
158  return $this->object->$key;
159  } else {
160  return $this->object[$key];
161  }
162  }
163 
173  public function offsetUnset($key) {
174  $this->displayWarning();
175  if (is_object($this->object) && !$this->object instanceof \ArrayAccess) {
176  unset($this->object->$key);
177  } else {
178  unset($this->object[$key]);
179  }
180  }
181 
191  public function offsetExists($offset) {
192  $this->displayWarning();
193  if (is_object($this->object) && !$this->object instanceof \ArrayAccess) {
194  return isset($this->object->$offset);
195  } else {
196  return array_key_exists($offset, $this->object);
197  }
198  }
199 }
200 
offsetGet($key)
Array access interface.
$object
These two snippets demonstrates triggering an event and how to register for that event.
Definition: trigger.php:7
__get($name)
Get a property on the object.
offsetUnset($key)
Array access interface.
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
$value
Definition: longtext.php:26
if(!$count) $offset
Definition: pagination.php:26
__toString()
Get the object as string.
offsetExists($offset)
Array access interface.
displayWarning()
Display a warning.
__set($name, $value)
Set a property on the object.
$string
offsetSet($key, $value)
Array access interface.
__call($name, $arguments)
Call a method on the object.
__construct($object, $message, $version, $reporter= 'elgg_deprecated_notice')
Create the wrapper.
Save menu items.
$key
Definition: summary.php:34
it is up to the author donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License If the distribution and or use of the Program is restricted in certain countries either by patents or by copyrighted the original copyright holder who places the Program under this License may add an geographical distribution limitation excluding those so that distribution is permitted only in or among countries not thus excluded In such this License incorporates the limitation as if written in the body of this License The Free Software Foundation may publish revised and or new versions of the General Public License from time to time Such new versions will be similar in spirit to the present version
elgg message
Definition: admin.css.php:240
$version
Definition: version.php:14