<commit_before><?php
class router extends base {
    public $routes;
    public $errors;
    public $with;
    
    function __construct(&$main) {
        parent::__construct($main);
        $this->error(404, function() {
            echo "The requested page could not be found";
		});
        $this->error(405, function() {
            echo "The requested method isn't available for the requested page.";
        });
        $this->with("/");
        if(isset($_SERVER["PATH_INFO"]))
            $this->setUrl($_SERVER["PATH_INFO"]);
    }
	function route($method, $path, $function) {
		if(substr($path, 0, strlen($this->with)) != $this->with)
			$path = $this->with.$path;
		$path = "/^".str_replace('/', '\/', $path)."$/";
		$this->routes[$path][strtoupper($method)] = $function;
		return $this;
	}
	function get($path, $function) {
		return $this->route("GET", $path, $function);
	}
	function post($path, $function) {
		return $this->route("POST", $path, $function);
	}
	function put($path, $function) {
		return $this->route("PUT", $path, $function);
	}
	function delete($path, $function) {
		return $this->route("DELETE", $path, $function);
	}
    function head($path, $function) {
        return $this->route("HEAD", $path, $function);
    }
	function all($path, $function) {
		return $this->route("ALL", $path, $function);
	}
	function setURL($u) {
		$this->url = $u;
        return $this;
	}
    function with($namespace) {
        if(substr($namespace, 0, 1) != "/")
            $namespace = "/".$namespace;
        $this->with = $namespace;
        return $this;
    }
    function error($code = 200, $function = null) {
        if(is_null($function)) {
            if(isset($this->errors[$code]))
                return $this->errors[$code];
            else
                return null;
        }else
            return $this->errors[$code] = $function;
    }
	function getMethod() {
		return strtoupper(
			isset($_REQUEST["__method__"]) ? $_REQUEST["__method__"] : (
				isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']) ? $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] : (
					isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET'
				)
			)
		);
	}
	function __destruct() {
        parent::__destruct();
		$url = isset($this->url) ? $this->url : "/";
		uksort($this->routes, function($a, $b) {
			return strlen($a) > strlen($b) ? $a : $b;<commit_msg>Fixes #35<commit_after><?php
class router extends base {
    public $routes;
    public $errors;
    public $with;
    
    function __construct(&$main) {
        parent::__construct($main);
        $this->error(404, function() {
            echo "The requested page could not be found";
		});
        $this->error(405, function() {
            echo "The requested method isn't available for the requested page.";
        });
        $this->with("/");
        if(isset($_SERVER["PATH_INFO"]))
            $this->setUrl($_SERVER["PATH_INFO"]);
    }
	function route($method, $path, $function) {
		if(substr($path, 0, strlen($this->with)) != $this->with)
			$path = $this->with.$path;
		$path = "/^".str_replace('/', '\/', $path)."$/";
		$this->routes[$path][strtoupper($method)] = $function;
		return $this;
	}
	function get($path, $function) {
		return $this->route("GET", $path, $function);
	}
	function post($path, $function) {
		return $this->route("POST", $path, $function);
	}
	function put($path, $function) {
		return $this->route("PUT", $path, $function);
	}
	function delete($path, $function) {
		return $this->route("DELETE", $path, $function);
	}
    function head($path, $function) {
        return $this->route("HEAD", $path, $function);
    }
	function all($path, $function) {
		return $this->route("ALL", $path, $function);
	}
	function setURL($u) {
		$this->url = $u;
        return $this;
	}
    function with($namespace) {
        if(substr($namespace, 0, 1) != "/")
            $namespace = "/".$namespace;
        $this->with = $namespace;
        return $this;
    }
    function withfile($namespace, $file) {
        $before = $this->with;
        $this->with($namespace);
        include $file;
        $this->with($before);
        return $this;
    }
    function error($code = 200, $function = null) {
        if(is_null($function)) {
            if(isset($this->errors[$code]))
                return $this->errors[$code];
            else
                return null;
        }else
            return $this->errors[$code] = $function;
    }
	function getMethod() {
		return strtoupper(
			isset($_REQUEST["__method__"]) ? $_REQUEST["__method__"] : (
				isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']) ? $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] : (
					isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET'
				)
			)
		);
	}
	function __destruct() {
        parent::__destruct();
		$url = isset($this->url) ? $this->url : "/";
		uksort($this->routes, function($a, $b) {
			return strlen($a) > strlen($b) ? $a : $b;
{'fraction_non_alphanumeric': 0.19416295095257396, 'fraction_numerical': 0.00526955816781516, 'mean_word_length': 2.8766692851531817, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 52, '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': '3053187', 'n_tokens_mistral': 1684, 'n_tokens_neox': 1585, 'n_words': 323}