<commit_before><?php

/**
 * Http Request class for providing global vars to class for improved
 * encapsulation
 *
 * @name      ElkArte Forum
 * @copyright ElkArte Forum contributors
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
 *
 * @version 1.1
 *
 */

/**
 * Class used to interact with super globals, POST, GET, SERVER, COOKIES, SESSION
 *
 * - Currently only a 'getter' of values
 * - Can be passed DataValidation sanitation values to return sanitized values
 * - Fetch raw values as $instance->post->keyname
 *     - $this->-req->post->filename
 *     - $this->_req->query->sa
 * - Fetch cleaned values with $instance->getPost('keyname', 'sanitation needs', 'default value')
 *     - $this->-req->getPost('filename', 'trim|strval', '');
 *     - $this->-req->getQuery('filename', 'intval', 0);
 */
class HttpReq
{
	/**
	 * The returned POST values
	 * @var object
	 */
	public $post;

	/**
	 * The compiled post values (json and cleaned from request)
	 * @var array
	 */
	private $_derived_post;

	/**
	 * The returned GET values
	 * @var object
	 */
	public $query;

	/**
	 * The returned COOKIE values
	 * @var object
	 */
	public $cookie;

	/**
	 * The returned SESSION values
	 * @var object
	 */
	public $session;

	/**
	 * The returned SERVER values
	 * @var object
	 */
	public $server;

	/**
	 * Sole private HttpReq instance
	 * @var HttpReq
	 */
	private static $_req = null;

	/**
	 * Used to hold processed (sanitised) values
	 * @var array
	 */
	private $_param;

	/**
	 * holds instance of the validator
	 * @var Data_Validator
	 */
	protected $_dataValidator;

	/**
	 * Class constructor, sets PHP globals to class members
	 *
	 * @param $dataValidator Data_Validator|null Instance of the data validator
	 */
	public function __construct($dataValidator = null)
	{
		// Make sure the validator is initiated
		$this->_dataValidator = $dataValidator === null ? new Data_Validator : $dataValidator;

		// Make the superglobals available as R/W properties
		$this->cookie = new ArrayObject($_COOKIE, ArrayObject::ARRAY_AS_PROPS);
		if (isset($_SESSION))
		{
			$this->session = new ArrayObject($_SESSION, ArrayObject::ARRAY_AS_PROPS);
		}
		else
		{
			$this->session = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
		}

		$this->server = detectServer();

		// Get will be in ->query, Post in ->post
		$this->_loadParsed();
	}

	/**
	 * Certain variables are born in Request, others are sanitized, and stored in<commit_msg>Revert "PHP 5.3 Friendly >_>"<commit_after><?php

/**
 * Http Request class for providing global vars to class for improved
 * encapsulation
 *
 * @name      ElkArte Forum
 * @copyright ElkArte Forum contributors
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause
 *
 * @version 1.1
 *
 */

/**
 * Class used to interact with super globals, POST, GET, SERVER, COOKIES, SESSION
 *
 * - Currently only a 'getter' of values
 * - Can be passed DataValidation sanitation values to return sanitized values
 * - Fetch raw values as $instance->post->keyname
 *     - $this->-req->post->filename
 *     - $this->_req->query->sa
 * - Fetch cleaned values with $instance->getPost('keyname', 'sanitation needs', 'default value')
 *     - $this->-req->getPost('filename', 'trim|strval', '');
 *     - $this->-req->getQuery('filename', 'intval', 0);
 */
class HttpReq
{
	/**
	 * The returned POST values
	 * @var object
	 */
	public $post;

	/**
	 * The compiled post values (json and cleaned from request)
	 * @var array
	 */
	private $_derived_post;

	/**
	 * The returned GET values
	 * @var object
	 */
	public $query;

	/**
	 * The returned COOKIE values
	 * @var object
	 */
	public $cookie;

	/**
	 * The returned SESSION values
	 * @var object
	 */
	public $session;

	/**
	 * The returned SERVER values
	 * @var object
	 */
	public $server;

	/**
	 * Sole private HttpReq instance
	 * @var HttpReq
	 */
	private static $_req = null;

	/**
	 * Used to hold processed (sanitised) values
	 * @var array
	 */
	private $_param;

	/**
	 * holds instance of the validator
	 * @var Data_Validator
	 */
	protected $_dataValidator;

	/**
	 * Class constructor, sets PHP globals to class members
	 *
	 * @param $dataValidator Data_Validator|null Instance of the data validator
	 */
	public function __construct($dataValidator = null)
	{
		// Make sure the validator is initiated
		$this->_dataValidator = $dataValidator === null ? new Data_Validator : $dataValidator;

		// Make the superglobals available as R/W properties
		$this->cookie = new ArrayObject($_COOKIE, ArrayObject::ARRAY_AS_PROPS);
		if (session_status() === PHP_SESSION_ACTIVE)
		{
			$this->session = new ArrayObject($_SESSION, ArrayObject::ARRAY_AS_PROPS);
		}
		else
		{
			$this->session = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
		}

		$this->server = detectServer();

		// Get will be in ->query, Post in ->post
		$this->_loadParsed();
	}

	/**
	 * Certain variables are born in Request, others are sanitized, and stored in
{'fraction_non_alphanumeric': 0.1333199276090891, 'fraction_numerical': 0.0020108586366378444, 'mean_word_length': 3.2658662092624358, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, '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': '7034202', 'n_tokens_mistral': 1635, 'n_tokens_neox': 1500, 'n_words': 474}