Skip to content

Instantly share code, notes, and snippets.

@jridgewell
Created January 20, 2015 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jridgewell/5b90660ebf601a5243b5 to your computer and use it in GitHub Desktop.
Save jridgewell/5b90660ebf601a5243b5 to your computer and use it in GitHub Desktop.
A Delegator Class to extend from
<?php
class Delegator {
private $obj;
public static function from($array) {
return array_map(function($obj) {
return new Delegator($obj);
}, $array);
}
public function __construct($obj) {
$this->__setObj($obj);
}
public function __call($name, $arguments) {
return call_user_func_array(array($this->obj, $name), $arguments);
}
public function __get($name) {
return $this->obj->$name;
}
public function __isset($name) {
return isset($this->obj->$name);
}
public function __unset($name) {
unset($this->obj->$name);
}
public function __set($name, $value) {
return $this->obj->$name = $value;
}
public function __toString() {
return $this->obj->__toString();
}
public function __clone() {
$this->obj = clone $this->obj;
}
public function __getObj() {
return $this->obj;
}
public function __setObj($obj) {
$this->obj = obj;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment