<commit_before><?php

class Zigra_Router
{

    protected static $_controller;
    protected static $_action;
    protected static $_args;
    protected static $_compiledRouteCollection;
    protected static $_routeCollection;
    private static $_instance;

    private function __construct()
    {
        self::$_routeCollection = new Zigra_Route_Collection();
        self::$_compiledRouteCollection = new Zigra_Route_Collection();
    }

    public static function singleton()
    {
        if (!isset(self::$_instance)) {
            $className = __CLASS__;
            self::$_instance = new $className;
        }
        return self::$_instance;
    }

    public static function route(Zigra_Request $request, $resetProperties = false)
    {
        self::singleton();

        $routefound = self::_Process($request, $resetProperties);
        if ($routefound) {
            $className = self::$_controller;
            $classFileName = '../app/controller/' . $className . 'Controller.php';
            if (file_exists($classFileName)) {
                include_once $classFileName;

                $fullClassName = ucfirst($className) . 'Controller';
                self::$_controller = new $fullClassName($request, self::$_args);
                if (is_callable(array(self::$_controller, self::$_action))) {
                    $registry = Zigra_Registry::getInstance();
                    $registry->set('controller', $className);
                    $registry->set('action', self::$_action);

                    call_user_func_array(array(self::$_controller, 'preExecute'), array($request));
                    call_user_func_array(array(self::$_controller, self::$_action), array($request));
                    call_user_func_array(array(self::$_controller, 'postExecute'), array($request));

                    return;
                } else {
                    throw new Zigra_Exception('Impossibile richiamare il modulo: ' . $className . '->' . self::$_action);
                }
            } else {
                throw new Zigra_Exception('Impossibile trovare la classe ' . $className . ' (' . $classFileName . ')');

                //self::route(new Zigra_Request('error'), true);
            }
        } else {
            // 404 route not found
            // TODO: make this contruct indipendent from app
            $classFileName = 'app/controller/errorController.php';<commit_msg>catch exception in router<commit_after><?php

class Zigra_Router
{

    protected static $_controller;
    protected static $_action;
    protected static $_args;
    protected static $_compiledRouteCollection;
    protected static $_routeCollection;
    private static $_instance;

    private function __construct()
    {
        self::$_routeCollection = new Zigra_Route_Collection();
        self::$_compiledRouteCollection = new Zigra_Route_Collection();
    }

    public static function singleton()
    {
        if (!isset(self::$_instance)) {
            $className = __CLASS__;
            self::$_instance = new $className;
        }
        return self::$_instance;
    }

    public static function route(Zigra_Request $request, $resetProperties = false)
    {
        self::singleton();

        $routefound = self::_Process($request, $resetProperties);
        if ($routefound) {
            $className = self::$_controller;
            $classFileName = '../app/controller/' . $className . 'Controller.php';
            try {
                if (file_exists($classFileName)) {
                    include_once $classFileName;

                    $fullClassName = ucfirst($className) . 'Controller';
                    self::$_controller = new $fullClassName($request, self::$_args);
                    if (is_callable(array(self::$_controller, self::$_action))) {
                        $registry = Zigra_Registry::getInstance();
                        $registry->set('controller', $className);
                        $registry->set('action', self::$_action);

                        call_user_func_array(array(self::$_controller, 'preExecute'), array($request));
                        call_user_func_array(array(self::$_controller, self::$_action), array($request));
                        call_user_func_array(array(self::$_controller, 'postExecute'), array($request));

                        return;
                    } else {
                        throw new Zigra_Exception('Impossibile richiamare il modulo: ' . $className . '->' . self::$_action);
                    }
                } else {
                    throw new Zigra_Exception('Impossibile trovare la classe ' . $className . ' (' . $classFileName . ')');

                    //self::route(new Zigra_Request('error'), true);
                }
            } catch (Zigra_Exception $e) {
                Zigra_Exception::renderError($e->getCode(), $e->getMessage());
            }
        } else {
            // 404 route not found
            // TODO: make this contruct indipendent from app
            $classFileName = 'app/controller/errorController.php';
{'fraction_non_alphanumeric': 0.12194641449960598, 'fraction_numerical': 0.001182033096926714, 'mean_word_length': 2.091961023142509, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1264801', 'n_tokens_mistral': 1302, 'n_tokens_neox': 1230, 'n_words': 262}