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: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111:
<?php
class DispatchManager
{
public static function dispatch($url_controller_mappers)
{
try
{
$dispatcher = new Dispatcher($url_controller_mappers);
$dispatcher->dispatch();
}
catch (NoUrlMatchException $ex)
{
self::handle_dispatch_exception($ex);
}
}
public static function redirect(Controller $controller)
{
AppContext::get_response()->clean_output();
Environment::init_output_bufferization();
$request = AppContext::get_request();
$response = $controller->execute($request);
$response->send();
Environment::destroy();
exit;
}
public static function get_url($path, $url, $not_rewriting_url_forced = false)
{
$dispatcher_url = new Url(rtrim($path, '/'));
$url = ltrim($url, '/');
if (ServerEnvironmentConfig::load()->is_url_rewriting_enabled() && !$not_rewriting_url_forced)
{
return new Url(self::get_dispatcher_path($dispatcher_url->relative()) . '/' . $url);
}
else
{
$dispatcher = $dispatcher_url->relative();
if (!preg_match('`(?:\.php)|/$`u', $dispatcher))
{
$dispatcher .= '/';
}
if (TextHelper::strpos($url, '?') !== false)
{
$exploded = explode('?', $url, 2);
$exploded[1] = str_replace('?', '&', $exploded[1]);
return new Url($dispatcher . '?' . Dispatcher::URL_PARAM_NAME .
'=/' . $exploded[0] . '&' . $exploded[1]);
}
else
{
return new Url($dispatcher . '?' . Dispatcher::URL_PARAM_NAME .
'=/' . $url);
}
}
}
private static function get_dispatcher_path($dispatcher_name)
{
return preg_replace('`(.*/)[a-z0-9]+\.php`u','$1', $dispatcher_name);
}
private static function handle_dispatch_exception($exception)
{
if (Debug::is_debug_mode_enabled())
{
self::show_error($exception);
}
else
{
$error_controller = PHPBoostErrors::unexisting_page();
DispatchManager::redirect($error_controller);
}
}
private static function show_error($exception)
{
Debug::fatal($exception);
}
}
?>