<commit_before><?php

namespace Tipsy;

class Request {
	private $_properties;
	private $_rawRequest;
	private $_content;
	private $_headers;

	public function __construct($args = []) {
		$this->_properties = [];

		if ($args['tipsy']) {
			$this->_tipsy = $args['tipsy'];
		}

		if ($this->method()) {
			switch ($this->method()) {
				case 'GET':
					if ($this->_contentType() === 'application/x-www-form-urlencoded' || !$this->_contentType()) {
						$this->_properties = $_GET;
					} elseif ($this->_contentType() === 'application/json') {
						$this->_properties = $this->_getRawRequest();
					}
					break;

				case 'POST':
					if ($this->_contentType() === 'application/json') {
						$this->_properties = json_decode($this->_getContent(), 'array');
						// } elseif ($_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded') {
					} else  {
						$this->_properties = $_POST;
					}
					break;

				case 'PUT':
				case 'DELETE':
				default:
					if ($this->_contentType() === 'application/x-www-form-urlencoded') {
						parse_str($this->_getContent(), $this->_properties);

					} elseif ($this->_contentType() === 'application/json') {
						$content = $this->_getContent();
						$request = json_decode($content,'array');
						if (!$request) {
							$this->_properties = false;
						} else {
							$this->_properties = $request;
						}
					}
					break;

			}
		}

	}

	private function _contentType() {
		if (!isset($this->_contentType)) {
			$this->_contentType = explode(';',$_SERVER['CONTENT_TYPE'])[0];
		}
		return $this->_contentType;
	}

	public function base() {
		return $this->_base;
	}

	public function loc($piece = 0) {
		$paths = explode('/', $this->path());
		return $paths[$piece];
	}

	public function host() {
		return 'http://'.$_SERVER['HTTP_HOST'];
	}

	public function url() {
		return $this->host().$_SERVER['REQUEST_URI'];
	}

	public function path($url = null) {

		if (!isset($this->_path)) {
			if (!$url) {
				if ($_REQUEST['__url']) {
					$url = $_REQUEST['__url'];
				} else {

					$request = explode('?', $_SERVER['REQUEST_URI'], 2)[0];

					$dir = $_SERVER['SCRIPT_NAME'];
					$url = preg_replace('/^'.str_replace('/','\\/',''.$dir).'/','',$request);

					$dir = dirname($_SERVER['SCRIPT_NAME']);
					$url = preg_replace('/^'.str_replace('/','\\/',''.$dir).'/','',$url);

					$url = substr($url, 0, 1) == '/' ? $url : '/'.$url;
					$this->_base = substr($dir, -1) == '/' ? $dir : $dir.'/';
				}
			}

			while (strpos($url, '//') !== false) {
				$url = str_replace('//', '/', $url);
			}

			if ($url{0} == '/') {
				$url = substr($url, 1);<commit_msg>fixed request url not returning when overwriting uri<commit_after><?php

namespace Tipsy;

class Request {
	private $_properties;
	private $_rawRequest;
	private $_content;
	private $_headers;

	public function __construct($args = []) {
		$this->_properties = [];

		/** dont think this is needed, but leaving here just in case
		if ($args['tipsy']) {
			$this->_tipsy = $args['tipsy'];
		}
		**/

		if ($this->method()) {
			switch ($this->method()) {
				case 'GET':
					if ($this->_contentType() === 'application/x-www-form-urlencoded' || !$this->_contentType()) {
						$this->_properties = $_GET;
					} elseif ($this->_contentType() === 'application/json') {
						$this->_properties = $this->_getRawRequest();
					}
					break;

				case 'POST':
					if ($this->_contentType() === 'application/json') {
						$this->_properties = json_decode($this->_getContent(), 'array');
						// } elseif ($_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded') {
					} else  {
						$this->_properties = $_POST;
					}
					break;

				case 'PUT':
				case 'DELETE':
				default:
					if ($this->_contentType() === 'application/x-www-form-urlencoded') {
						parse_str($this->_getContent(), $this->_properties);

					} elseif ($this->_contentType() === 'application/json') {
						$content = $this->_getContent();
						$request = json_decode($content,'array');
						if (!$request) {
							$this->_properties = false;
						} else {
							$this->_properties = $request;
						}
					}
					break;

			}
		}

	}

	private function _contentType() {
		if (!isset($this->_contentType)) {
			$this->_contentType = explode(';',$_SERVER['CONTENT_TYPE'])[0];
		}
		return $this->_contentType;
	}

	public function base() {
		return $this->_base;
	}

	public function loc($piece = 0) {
		$paths = explode('/', $this->path());
		return $paths[$piece];
	}

	public function host() {
		return 'http://'.$_SERVER['HTTP_HOST'];
	}

	public function url() {
		return $this->host().'/'.$this->path();
	}

	public function path($url = null) {

		if (!isset($this->_path)) {
			if (!$url) {
				if ($_REQUEST['__url']) {
					$url = $_REQUEST['__url'];
				} else {

					$request = explode('?', $_SERVER['REQUEST_URI'], 2)[0];

					$dir = $_SERVER['SCRIPT_NAME'];
					$url = preg_replace('/^'.str_replace('/','\\/',''.$dir).'/','',$request);

					$dir = dirname($_SERVER['SCRIPT_NAME']);
					$url = preg_replace('/^'.str_replace('/','\\/',''.$dir).'/','',$url);

					$url = substr($url, 0, 1) == '/' ? $url : '/'.$url;
					$this->_base = substr($dir, -1) == '/' ? $dir : $dir.'/';
				}
			}

			while (strpos($url, '//') !== false) {
				$url = str_replace('//', '/', $url);
			}

			if ($url{0} == '/') {
				$url = substr($url, 1);
{'fraction_non_alphanumeric': 0.2314711359404097, 'fraction_numerical': 0.0033519553072625698, 'mean_word_length': 3.014200298953662, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 62, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '4367081', 'n_tokens_mistral': 2249, 'n_tokens_neox': 1787, 'n_words': 335}