<commit_before><?php
namespace Pragma\Router;

class Request{
	protected $path = '';
	protected $method = '';
	protected $isXhr = false;
	protected $isSameOrigin = true;

	private static $request = null;//singleton

	public function __construct(){
		$this->path = parse_url(trim(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/'), PHP_URL_PATH);

		$this->method = strtolower($_SERVER['REQUEST_METHOD']);

		if(!empty($this->method) && $this->method == 'post'){//we need to check _METHOD
			if(!empty($_POST['_METHOD'])){
				$verb = strtolower($_POST['_METHOD']);
				switch($verb){
					case 'delete':
					case 'put':
					case 'patch':
						$this->method = $verb;
						break;
				}
			}
		}

		//isXhr ?
		$this->isXhr =
			  (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest')
			  || isset($_SERVER['CONTENT_TYPE']) && strtolower($_SERVER['CONTENT_TYPE']) == 'application/json'
			  || isset($_SERVER['CONTENT_TYPE']) && strtolower($_SERVER['CONTENT_TYPE']) == 'application/javascript';//jsonp

		//isSameOrigin ? HTTP_REFERER is not always given by the browser agent, HTTP_HOST too
		if(isset($_SERVER['HTTP_REFERER']) && isset($_SERVER['HTTP_HOST'])){
			$requestOrigin = parse_url(strtolower($_SERVER['HTTP_REFERER']), PHP_URL_HOST);
			if($requestOrigin != strtolower($_SERVER['HTTP_HOST'])){
				$this->isSameOrigin = false;
			}
		}
	}

	public static function getRequest(){
		if(is_null(self::$request)){
			self::$request = new Request();
		}

		return self::$request;
	}

	public function getPath(){
		return $this->path;
	}

	public function getMethod(){
		return $this->method;
	}

	public function isXhr(){
		return $this->isXhr;<commit_msg>Adding development key to emulate HTTP_REFERER<commit_after><?php
namespace Pragma\Router;

class Request{
	protected $path = '';
	protected $method = '';
	protected $isXhr = false;
	protected $isSameOrigin = true;

	private static $request = null;//singleton

	public function __construct(){
		$this->path = parse_url(trim(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/'), PHP_URL_PATH);

		$this->method = strtolower($_SERVER['REQUEST_METHOD']);

		if(!empty($this->method) && $this->method == 'post'){//we need to check _METHOD
			if(!empty($_POST['_METHOD'])){
				$verb = strtolower($_POST['_METHOD']);
				switch($verb){
					case 'delete':
					case 'put':
					case 'patch':
						$this->method = $verb;
						break;
				}
			}
		}

		//isXhr ?
		$this->isXhr =
			  (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest')
			  || isset($_SERVER['CONTENT_TYPE']) && strpos(strtolower($_SERVER['CONTENT_TYPE']), 'application/json') !== false
			  || isset($_SERVER['CONTENT_TYPE']) && strpos(strtolower($_SERVER['CONTENT_TYPE']), 'application/javascript') !== false;//jsonp

		//isSameOrigin ? HTTP_REFERER is not always given by the browser agent, HTTP_HOST too
		if(isset($_SERVER['HTTP_PRAGMA_REFERER']) || isset($_SERVER['HTTP_REFERER']) && isset($_SERVER['HTTP_HOST'])){
			$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $_SERVER['HTTP_PRAGMA_REFERER'];
			$requestOrigin = parse_url(strtolower($referer), PHP_URL_HOST);
			if($requestOrigin != strtolower($_SERVER['HTTP_HOST'])){
				$this->isSameOrigin = false;
			}
		}
	}

	public static function getRequest(){
		if(is_null(self::$request)){
			self::$request = new Request();
		}

		return self::$request;
	}

	public function getPath(){
		return $this->path;
	}

	public function getMethod(){
		return $this->method;
	}

	public function isXhr(){
		return $this->isXhr;
{'fraction_non_alphanumeric': 0.18288361951485418, 'fraction_numerical': 0.0, 'mean_word_length': 4.881410256410256, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '4706377', 'n_tokens_mistral': 1352, 'n_tokens_neox': 1203, 'n_words': 221}