-
-
Save gcatlin/4288934 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class BaseDecorator { | |
private $component; | |
private $methods = array(); | |
private $properties = array(); | |
public function __construct($component) { | |
$this->component = $component; | |
} | |
public function __call($name, $args) { | |
if (!isset($this->methods[$name])) { | |
$this->methods[$name] = method_exists($this->component, $name); | |
} | |
if ($this->methods[$name]) { | |
return call_user_func_array(array($this->component, $name), $args); | |
} | |
} | |
public function __get($name) { | |
if (!isset($this->properties[$name])) { | |
$this->properties[$name] = property_exists($this->component, $name); | |
} | |
if ($this->properties[$name]) { | |
return $this->component->$name; | |
} | |
} | |
public function __set($name, $value) { | |
if (!isset($this->properties[$name])) { | |
$this->properties[$name] = property_exists($this->component, $name); | |
} | |
if ($this->properties[$name]) { | |
$this->component->$name = $value; | |
} else { | |
$this->$name = $value; | |
} | |
} | |
public function __isset($name) { | |
if (!isset($this->properties[$name])) { | |
$this->properties[$name] = property_exists($this->component, $name); | |
} | |
if ($this->properties[$name]) { | |
return isset($this->component->$name); | |
} | |
} | |
public function __unset($name) { | |
if (!isset($this->properties[$name])) { | |
$this->properties[$name] = property_exists($this->component, $name); | |
} | |
if ($this->properties[$name]) { | |
unset($this->component->$name); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment