Ejemplo n.º 1
0
function execute_logic()
{
    $req_uri = $GLOBALS['req_uri'];
    $url = $GLOBALS['config']['urls'];
    // search for controller
    foreach ($url as $pattern => $controller) {
        $pattern = str_replace('/', '\\/', $pattern);
        if (preg_match('/^' . $pattern . '$/', $req_uri, $matches)) {
            // find!
            $find_controller = 1;
            break;
        }
    }
    if (!isset($find_controller)) {
        $controller = 'page404';
    }
    $GLOBALS['view'] = $GLOBALS['controller'] = $controller;
    $method = $_SERVER['REQUEST_METHOD'];
    $init_file = AppFile::controller('_init');
    if (file_exists($init_file)) {
        require_once $init_file;
        $init_func = '_init';
        if (function_exists($init_func)) {
            call_user_func($init_func);
        }
        $init_func .= '_' . $method;
        if (function_exists($init_func)) {
            call_user_func($init_func);
        }
    }
    if (isset($matches)) {
        array_shift($matches);
    }
    // build para list for function
    require_once AppFile::controller($controller);
    $init_func = $controller . '_init';
    if (function_exists($init_func)) {
        call_user_func($init_func);
    }
    if (function_exists($controller)) {
        call_user_func_array($controller, $matches);
    }
    $method_func = $controller . '_' . $method;
    if (function_exists($method_func)) {
        call_user_func_array($method_func, $matches);
    }
    $end_func = $controller . '_end';
    if (function_exists($end_func)) {
        call_user_func($end_func);
    }
}