public function run()
{
if (($cb = $this->getCallback()) === null) {
throw new RouteException('callback attribute is not defined or empty.', $this->route);
}
/** constructor arguments **/
$args = $this->route['args'];
// validation action method prototype
$vars = $this->getVars();
// reflection parameters of the function or method
$rps = $this->initCallback($cb, $args);
// check callback function
if (!is_callable($cb)) {
throw new RouteException('This route callback is not a valid callback.', $this->route);
}
// get relection method parameter prototype for checking...
// and create arguments array
$arguments = array();
foreach ($rps as $param) {
$n = $param->getName();
if (isset($vars[$n])) {
$arguments[] = $vars[$n];
} else {
if (isset($this->route['default'][$n]) && ($default = $this->route['default'][$n])) {
$arguments[] = $default;
} else {
if (!$param->isOptional() && !$param->allowsNull) {
throw new RouteException('parameter is not defined.', $this->route);
}
}
}
}
if ($this->controller && is_a($this->controller, 'Roller\\Controller')) {
$this->controller->route = $this;
$this->controller->router = $this->router;
// runWrapper method runs: before, run, after, finalize method
return $this->controller->runWrapper($cb, $arguments);
} else {
return call_user_func_array($cb, $arguments);
}
}