<commit_before><?php

namespace aurora\http;


class controller
{
	private static function checkMethod($class, $method, $argc)
	{
		if (!method_exists($class, $method))
			return false;

		$rm = new \ReflectionMethod($class, $method);

		if (!$rm->isPublic())
			return false;

		if ($argc < $rm->getNumberOfRequiredParameters() ||
		    $argc > $rm->getNumberOfParameters())
			return false;

		return true;
	}


	private static function reply($class, $method, $args)
	{
		$resp = call_user_func_array(array(new $class, $method), $args);
		if (!isset($resp))
			$resp = new response("", 204, array("Content-Type:"));

		header("HTTP/1.1 " . $resp->status);

		foreach ($resp->headers as $value)
			header($value);

		$resp->sendContent();
	}


	private static function expand(&$val, &$args, $index)
	{
		$val .= str_replace(array("-", "/"), array("_", "\\"), $args[$index]);

		unset($args[$index]);
	}


	public static function handleRequest($routes)
	{
		$req = new request();

		foreach ($routes as $rt) {

                        if (!preg_match($rt["path"], $req->path, $args))
				continue;

			$class   = $rt["ctrl"];
			$method  = $req->method;
			$args[0] = $req;

			if (isset($rt["class"]))
				self::expand($class, $args, $rt["class"]);

			if (isset($rt["method"]))
				self::expand($method, $args, $rt["method"]);

			if (!self::checkMethod($class, $method, count($args)))
				continue;

			self::reply($class, $method, $args);

			return true;
		}

		return false;
	}


	public static function request($routes)
	{
		if (!self::handleRequest($routes))
			throw new \Exception("not found", 404);
	}
}<commit_msg>controller: url decode path before route lookup<commit_after><?php

namespace aurora\http;


class controller
{
	private static function checkMethod($class, $method, $argc)
	{
		if (!method_exists($class, $method))
			return false;

		$rm = new \ReflectionMethod($class, $method);

		if (!$rm->isPublic())
			return false;

		if ($argc < $rm->getNumberOfRequiredParameters() ||
		    $argc > $rm->getNumberOfParameters())
			return false;

		return true;
	}


	private static function reply($class, $method, $args)
	{
		$resp = call_user_func_array(array(new $class, $method), $args);
		if (!isset($resp))
			$resp = new response("", 204, array("Content-Type:"));

		header("HTTP/1.1 " . $resp->status);

		foreach ($resp->headers as $value)
			header($value);

		$resp->sendContent();
	}


	private static function expand(&$val, &$args, $index)
	{
		$val .= str_replace(array("-", "/"), array("_", "\\"), $args[$index]);

		unset($args[$index]);
	}


	public static function handleRequest($routes)
	{
		$req = new request();

		$path = rawurldecode($req->path);

		foreach ($routes as $rt) {

                        if (!preg_match($rt["path"], $path, $args))
				continue;

			$class   = $rt["ctrl"];
			$method  = $req->method;
			$args[0] = $req;

			if (isset($rt["class"]))
				self::expand($class, $args, $rt["class"]);

			if (isset($rt["method"]))
				self::expand($method, $args, $rt["method"]);

			if (!self::checkMethod($class, $method, count($args)))
				continue;

			self::reply($class, $method, $args);

			return true;
		}

		return false;
	}


	public static function request($routes)
	{
		if (!self::handleRequest($routes))
			throw new \Exception("not found", 404);
	}
}
{'fraction_non_alphanumeric': 0.19981916817359854, 'fraction_numerical': 0.0054249547920434, 'mean_word_length': 3.775539568345324, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '2086798', 'n_tokens_mistral': 1285, 'n_tokens_neox': 1113, 'n_words': 258}