DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Object Filter

11.17.2008
| 4321 views |
  • submit to reddit
        
//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com

class ObjectFilter{
	protected $o;
	protected $filter;

	public function __construct($o, $filter){
		$this->o = $o;
		$this->filter = is_array($filter) ? $filter : array($filter);
	}
	public function __get($n){
		$s = $this->o->$n;
		foreach($this->filter as $f)
			$s = call_user_func($f, $s);
		return $s;
	}
	public function __set($n, $v){
		return $this->o->$n = $v;
	}
	public function __call($n, $a){
		return call_user_func_array(array($this->o, $n), $a);
	}
	public function getObject(){
		return $this->o;
	}
}

Example

$o = new ObjectFilter(new stdClass, 'strip_tags');
$o->blabla = '<b>lala</b>';
echo $o->blabla;