Elgg  Version 3.0
DeprecationWrapper.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg;
4 
27 class DeprecationWrapper implements \ArrayAccess {
29  protected $object;
30 
32  protected $string;
33 
35  protected $message;
36 
38  protected $version;
39 
41  protected $reporter;
42 
51  public function __construct($object, $message, $version, $reporter = 'elgg_deprecated_notice') {
52  if (is_object($object)) {
53  $this->object = $object;
54  } else {
55  $this->string = $object;
56  }
57  $this->message = $message;
58  $this->version = $version;
59  $this->reporter = $reporter;
60  }
61 
68  public function __get($name) {
69  $this->displayWarning();
70  return $this->object->$name;
71  }
72 
80  public function __set($name, $value) {
81  $this->displayWarning();
82  $this->object->$name = $value;
83  }
84 
91  public function __isset($name) {
92  $this->displayWarning();
93  return isset($this->object->$name);
94  }
95 
103  public function __call($name, $arguments) {
104  $this->displayWarning();
105  return call_user_func_array([$this->object, $name], $arguments);
106  }
107 
113  public function __toString() {
114  $this->displayWarning();
115  if (isset($this->string)) {
116  return $this->string;
117  } else {
118  return (string) $this->object;
119  }
120  }
121 
127  protected function displayWarning() {
128  // display 3 levels in the function stack to get back to original use
129  // 1 for __get/__call/__toString()
130  // 1 for displayWarning()
131  // 1 for call_user_func()
132  call_user_func($this->reporter, $this->message, $this->version, 3);
133  }
134 
145  public function offsetSet($key, $value) {
146  $this->displayWarning();
147  if (is_object($this->object) && !$this->object instanceof \ArrayAccess) {
148  $this->object->$key = $value;
149  } else {
150  if ($key === null) {
151  // Yes this is necessary. Otherwise $key will be interpreted as empty string
152  $this->object[] = $value;
153  } else {
154  $this->object[$key] = $value;
155  }
156  }
157  }
158 
168  public function offsetGet($key) {
169  $this->displayWarning();
170  if (is_object($this->object) && !$this->object instanceof \ArrayAccess) {
171  return $this->object->$key;
172  } else {
173  return $this->object[$key];
174  }
175  }
176 
186  public function offsetUnset($key) {
187  $this->displayWarning();
188  if (is_object($this->object) && !$this->object instanceof \ArrayAccess) {
189  unset($this->object->$key);
190  } else {
191  unset($this->object[$key]);
192  }
193  }
194 
204  public function offsetExists($offset) {
205  $this->displayWarning();
206  if (is_object($this->object) && !$this->object instanceof \ArrayAccess) {
207  return isset($this->object->$offset);
208  } else {
209  return array_key_exists($offset, $this->object);
210  }
211  }
212 }
offsetGet($key)
Array access interface.
if(!$item instanceof ElggRiverItem) $object
Definition: responses.php:23
__get($name)
Get a property on the object.
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
offsetUnset($key)
Array access interface.
if(!$count) $offset
Definition: pagination.php:26
__toString()
Get the object as string.
offsetExists($offset)
Array access interface.
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
Definition: LICENSE.txt:283
displayWarning()
Display a warning.
__set($name, $value)
Set a property on the object.
offsetSet($key, $value)
Array access interface.
__isset($name)
Is a property set?
Wrap an object and display warnings whenever the object&#39;s variables are accessed or a method is used...
__call($name, $arguments)
Call a method on the object.
__construct($object, $message, $version, $reporter= 'elgg_deprecated_notice')
Create the wrapper.
Configuration exception.
$result message
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:55
$value
Definition: debugging.php:7
$version
Definition: version.php:14