Skip to content

Instantly share code, notes, and snippets.

@hectormenendez
Created September 29, 2010 18:53
Show Gist options
  • Save hectormenendez/603312 to your computer and use it in GitHub Desktop.
Save hectormenendez/603312 to your computer and use it in GitHub Desktop.
<?php
class DBControl {
private $__db = null;
private $__parent = null;
private function __appendDB($name,$args){
# Get method's declared parameters.
$params = $this->__parent->getMethod($name)->getParameters();
# Make sure all arguments are set.
for($i=0; $i<count($params);$i++) if (!isset($args[$i])) $args[$i] = $params[$i]->getDefaultValue();
# Appends Database object.
$args[] = $this->__db;
return $args;
}
final public function __call($name,$args){
if (!is_callable("DB::$name")) DB::error("invalid_method: '$name'");
return call_user_func_array("DB::$name",$this->__appendDB($name,$args));
}
public function __construct($db){
$this->__parent = new ReflectionClass('DB');
$this->__db = $db;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment