<commit_before><?php
namespace AnhNhan\ModHub\Web;

use YamwLibs\Libs\Http\Request;
use YamwLibs\Libs\Routing\Router;

/**
 * @author <NAME> <<EMAIL>>
 */
final class AppRouting
{
    private $appList = array();
    private $appInstanceList = array();
    private $appRoutes = array();
    private $router;

    public function __construct(array $appList = array())
    {
        if ($appList) {
            $this->setAppList($appList);
        }
    }

    public function setAppList(array $appList)
    {
        $this->appList = $appList;
        $this->generateRouter();
        return $this;
    }

    private function generateRouter()
    {
        foreach ($this->appList as $class_name) {
            $this->appInstanceList[] = new $class_name;
        }

        assert_instances_of($this->appInstanceList, 'AnhNhan\ModHub\Web\Application\BaseApplication');

        $this->appRoutes = mpull($this->appInstanceList, "getRoutes");

        $router = new Router;
        foreach ($this->appRoutes as $routes) {
            foreach ($routes as $route) {
                $router->registerRoute($route);
            }
        }

        $this->router = $router;
    }

    /**
     * @return array The result dictionary from the router. The app is in $result["target"].
     */
    public function routeToApplication($uri)
    {
        if (!count($this->appRoutes)) {
            throw new \RuntimeException("We have no routes. Check your applications!");
        }

        return $this->router->route($uri);
    }

    public function routeToController(Request $request)
    {
        $routingResult = $this->routeToApplication($request->getValue("uri-action-string"));
        if ($routingResult) {
            $app = $routingResult["target"];
            // Remove the target app again. It ain't supposed to appear in the Request
            unset($routingResult["target"]);
            $request->populate($routingResult);
            $controller = $app->routeToController($request);
            return $controller;
        } else {
            // TODO: Get default/404 controller
            return null;
        }
    }
}<commit_msg>Including route name in request<commit_after><?php
namespace AnhNhan\ModHub\Web;

use YamwLibs\Libs\Http\Request;
use YamwLibs\Libs\Routing\Router;

/**
 * @author <NAME> <<EMAIL>>
 */
final class AppRouting
{
    private $appList = array();
    private $appInstanceList = array();
    private $appRoutes = array();
    private $router;

    public function __construct(array $appList = array())
    {
        if ($appList) {
            $this->setAppList($appList);
        }
    }

    public function setAppList(array $appList)
    {
        $this->appList = $appList;
        $this->generateRouter();
        return $this;
    }

    private function generateRouter()
    {
        foreach ($this->appList as $class_name) {
            $this->appInstanceList[] = new $class_name;
        }

        assert_instances_of($this->appInstanceList, 'AnhNhan\ModHub\Web\Application\BaseApplication');

        $this->appRoutes = mpull($this->appInstanceList, "getRoutes");

        $router = new Router;
        foreach ($this->appRoutes as $routes) {
            foreach ($routes as $route) {
                $router->registerRoute($route);
            }
        }

        $this->router = $router;
    }

    /**
     * @return array The result dictionary from the router. The app is in $result["target"].
     */
    public function routeToApplication($uri)
    {
        if (!count($this->appRoutes)) {
            throw new \RuntimeException("We have no routes. Check your applications!");
        }

        return $this->router->route($uri);
    }

    public function routeToController(Request $request)
    {
        $routingResult = $this->routeToApplication($request->getValue("uri-action-string"));
        if ($routingResult) {
            $app = $routingResult["target"];

            $routeName = $routingResult["route"]->getName();
            $routingResult["route-name"] = $routeName;

            // Remove the target app again. It ain't supposed to appear in the Request
            unset($routingResult["target"]);
            unset($routingResult["route"]);
            $request->populate($routingResult);
            $controller = $app->routeToController($request);
            return $controller;
        } else {
            // TODO: Get default/404 controller
            return null;
        }
    }
}
{'fraction_non_alphanumeric': 0.13221476510067115, 'fraction_numerical': 0.0013422818791946308, 'mean_word_length': 2.2492732558139537, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 46, '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': '1672674', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1248, 'n_words': 279}