1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73:
<?php
class UrlControllerMapper extends AbstractUrlMapper
{
private $classname;
private $parameters_names;
public function __construct($classname, $capture_regex = '`^/?$`u', $parameters_names = array())
{
$this->classname =& $classname;
$this->parameters_names = $parameters_names;
parent::__construct($capture_regex);
}
public function call()
{
$this->build_parameters();
$this->do_call();
}
private function build_parameters()
{
$captured_parameters = $this->get_captured_parameters();
$i = 1;
foreach ($this->parameters_names as $parameter_name)
{
$value = null;
if (isset($captured_parameters[$i]))
{
$value = $captured_parameters[$i];
}
AppContext::get_request()->set_getvalue($parameter_name, $value);
$i++;
}
}
private function do_call()
{
$controller = new $this->classname();
if (!($controller instanceof Controller))
{
throw new NoSuchControllerException($this->classname);
}
$controller_to_execute = $controller->get_right_controller_regarding_authorizations();
$response = $controller_to_execute->execute(AppContext::get_request());
$response->send();
}
}
?>