<commit_before><?php namespace System;

class Request {

	/**
	 * The route handling the current request.
	 *
	 * @var Route
	 */
	public static $route;

	/**
	 * Get the request URI.
	 *
	 * The server PATH_INFO will be used if available. Otherwise, the REQUEST_URI will be used.
	 * The application URL and index will be removed from the URI.
	 *
	 * If the request is to the root of application, a single forward slash will be returned.
	 *
	 * @return string
	 */
	public static function uri()
	{
		if (isset($_SERVER['PATH_INFO']))
		{
			$uri = $_SERVER['PATH_INFO'];
		}
		elseif (isset($_SERVER['REQUEST_URI']))
		{
			$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
		}
		else
		{
			throw new \Exception('Unable to determine the request URI.');
		}

		if ($uri === false)
		{
			throw new \Exception("Malformed request URI. Request terminated.");
		}

		// Remove the application URL from the URI.
		if (strpos($uri, $base = parse_url(Config::get('application.url'), PHP_URL_PATH)) === 0)
		{
			$uri = substr($uri, strlen($base));
		}

		// Remove the application index page from the URI.
		if (strpos($uri, $index = '/index.php') === 0)
		{
			$uri = substr($uri, strlen($index));
		}

		return (($uri = trim($uri, '/')) == '') ? '/' : $uri;
	}

	/**
	 * Get the request method.
	 *
	 * @return string
	 */
	public static function method()
	{
		return (static::spoofed()) ? $_POST['REQUEST_METHOD'] : $_SERVER['REQUEST_METHOD'];
	}

	/**
	 * Determine if the request method is being spoofed by a hidden Form element.
	 *
	 * Hidden form elements are used to spoof PUT and DELETE requests since
	 * they are not supported by HTML forms.
	 *
	 * @return bool
	 */
	public static function spoofed()
	{<commit_msg>Cache the URI, and added Request::segment method.<commit_after><?php namespace System;

class Request {

	/**
	 * The route handling the current request.
	 *
	 * @var Route
	 */
	public static $route;

	/**
	 * The request URI.
	 *
	 * @var string
	 */
	public static $uri;

	/**
	 * The request URI segments.
	 *
	 * @var array
	 */
	public static $segments;

	/**
	 * Get the request URI.
	 *
	 * The server PATH_INFO will be used if available. Otherwise, the REQUEST_URI will be used.
	 * The application URL and index will be removed from the URI.
	 *
	 * If the request is to the root of application, a single forward slash will be returned.
	 *
	 * @return string
	 */
	public static function uri()
	{
		if ( ! is_null(static::$uri)) return static::$uri;

		if (isset($_SERVER['PATH_INFO']))
		{
			$uri = $_SERVER['PATH_INFO'];
		}
		elseif (isset($_SERVER['REQUEST_URI']))
		{
			$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
		}
		else
		{
			throw new \Exception('Unable to determine the request URI.');
		}

		if ($uri === false)
		{
			throw new \Exception("Malformed request URI. Request terminated.");
		}

		if (strpos($uri, $base = parse_url(Config::get('application.url'), PHP_URL_PATH)) === 0)
		{
			$uri = substr($uri, strlen($base));
		}

		if (strpos($uri, $index = '/index.php') === 0)
		{
			$uri = substr($uri, strlen($index));
		}

		return static::$uri = (($uri = trim($uri, '/')) == '') ? '/' : $uri;
	}

	/**
	 * Get a segment of the request URI.
	 *
	 * @param  int     $segment
	 * @return string
	 */
	public static function segment($segment)
	{
		if (is_null(static::$segments)) static::$segments = explode('/', static::uri());

		return (isset(static::$segments[$index = $segment - 1])) ? static::$segments[$index] : null;
	}

	/**
	 * Get the request method.
	 *
	 * @return string
	 */
	public static function method()
	{
		return (static::spoofed()) ? $_POST['REQUEST_METHOD'] : $_SERVER['REQUEST_METHOD'];
	}

	/**
	 * Determine if the request method is being spoofed by a hidden Form element.
	 *
	 * Hidden form elements are used to spoof PUT and DELETE requests since
	 * they are not supported by HTML forms.
	 *
	 * @return bool
	 */
	public static function spoofed()
	{
{'fraction_non_alphanumeric': 0.15170670037926676, 'fraction_numerical': 0.0012642225031605564, 'mean_word_length': 3.1951219512195124, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '5173115', 'n_tokens_mistral': 1381, 'n_tokens_neox': 1223, 'n_words': 406}