<commit_before><?php

class Router
{
    private $actionName;
    private $controllerName;
    private $params;
    private $routes;


    public function getRoutes()
    {
        return $this->routes;
    }

    public function setRoutes($routes)
    {
        $this->routes = $routes;
    }

    public function getParams()
    {
        return $this->params;
    }

    public function setParams($params)
    {
        $this->params = $params;
    }

    public function getControllerName()
    {
        return $this->controllerName;
    }

    public function setControllerName($controllerName)
    {
        $this->controllerName = $controllerName;
    }

    public function getActionName()
    {
        return $this->actionName;
    }

    public function setActionName($actionName)
    {
        $this->actionName = $actionName;
    }

    public function initRoutes()
    {
        $routes = Config::get('route');


        if (isset($routes))
            $this->routes = $routes;
    }

    public function getActiveRoute()
    {

        $url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : "";

        var_dump($url); //die();

        $routeName = $this->checkActiveRoute($url);

        if(!array_key_exists($routeName,$this->routes))
        {
            $this->controllerName = 'Home';
            $this->actionName = 'index';
        }





        return [$this->controllerName, $this->actionName, $this->params];

    }

    public function checkActiveRoute($uri)
    {
        trim($uri);

        if ($uri != '/') {

            $activeRoute = null;
            foreach ($this->routes as $name => $routeSettings) {
                if (!$routeSettings['template']) {

                    continue;
                }
                if (preg_match('@' . $routeSettings['template'] . '@
                ', $uri, $matches)) { //matched and parsed

                    if ($routeSettings['controller'][0] == "{") { //if controoler name is dynamic
                        $this->controllerName = $matches[$routeSettings['controller'][1]];
                    } else {
                        $this->controllerName = $routeSettings['controller'];
                    }
                    if ($routeSettings['action'][0] == "{") { //if action name is dynamic
                        $this->actionName = $matches[$routeSettings['action'][1]];
                    } else {
                        $this->actionName = $routeSettings['action'];
                    }
                    if (isset($routeSettings['params'])) {
                        $this->params = array();
                        foreach ($routeSettings['params'] as $paramName => $param) {
                            if ($param[0] == "{") {//if $param is dynamic
                                $this->params[$paramName] = $matches[$param[1]];
                            } else {
                                $this->params[$paramName] = $param;
                            }
                        }
                    }

                    $activeRoute = $name;
                    return $activeRoute;

                }

            }
        } else
        {
            $activeRoute = 'main';
            return $activeRoute;
        }

    }


}

<commit_msg>Added static routes for user friendly url<commit_after><?php

class Router
{
    private $actionName;
    private $controllerName;
    private $params;
    private $routes;


    public function getRoutes()
    {
        return $this->routes;
    }

    public function setRoutes($routes)
    {
        $this->routes = $routes;
    }

    public function getParams()
    {
        return $this->params;
    }

    public function setParams($params)
    {
        $this->params = $params;
    }

    public function getControllerName()
    {
        return $this->controllerName;
    }

    public function setControllerName($controllerName)
    {
        $this->controllerName = $controllerName;
    }

    public function getActionName()
    {
        return $this->actionName;
    }

    public function setActionName($actionName)
    {
        $this->actionName = $actionName;
    }

    public function initRoutes()
    {
        $routes = Config::get('route');


        if (isset($routes))
            $this->routes = $routes;
    }

    public function getActiveRoute()
    {

        $url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : "";


        $aliases = Config::get('route','static');

        if($aliases && array_key_exists($url,$aliases))
        {
            $url = $aliases[$url];
        }

        $routeName = $this->checkActiveRoute($url);

        if(!array_key_exists($routeName,$this->routes))
        {
            $this->controllerName = 'Home';
            $this->actionName = 'index';
        }

        return [$this->controllerName, $this->actionName, $this->params];

    }

    public function checkActiveRoute($uri)
    {
        trim($uri);

            $activeRoute = null;
            foreach ($this->routes as $name => $routeSettings) {
                if (!$routeSettings['template']) {

                    continue;
                }
                if (preg_match('@' . $routeSettings['template'] . '@
                ', $uri, $matches)) { //matched and parsed

                    if ($routeSettings['controller'][0] == "{") { //if controoler name is dynamic
                        $this->controllerName = $matches[$routeSettings['controller'][1]];
                    } else {
                        $this->controllerName = $routeSettings['controller'];
                    }
                    if ($routeSettings['action'][0] == "{") { //if action name is dynamic
                        $this->actionName = $matches[$routeSettings['action'][1]];
                    } else {
                        $this->actionName = $routeSettings['action'];
                    }
                    if (isset($routeSettings['params'])) {
                        $this->params = array();
                        foreach ($routeSettings['params'] as $paramName => $param) {
                            if ($param[0] == "{") {//if $param is dynamic
                                $this->params[$paramName] = $matches[$param[1]];
                            } else {
                                $this->params[$paramName] = $param;
                            }
                        }
                    }

                    $activeRoute = $name;
                    return $activeRoute;

                }

            }

    }


}


{'fraction_non_alphanumeric': 0.13480578827113482, 'fraction_numerical': 0.0018278750952018278, 'mean_word_length': 1.448173005219985, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 55, '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': '4304865', 'n_tokens_mistral': 1733, 'n_tokens_neox': 1647, 'n_words': 315}