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
Object Filter
//+ 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;





