Created
September 29, 2010 18:53
-
-
Save hectormenendez/603312 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 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