<commit_before><?php

/**
 * @package Ohara helper class
 * @version 1.1
 * @author <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2016, <NAME>
 * @license http://www.mozilla.org/MPL/2.0/
 */

namespace Suki;

class Data
{
	public function __construct($app)
	{
		$this->_app = $app;
	}

	/**
	 * Holds any sanitized data from $_REQUEST
	 * @access protected
	 * @var array
	 */
	protected $_request = array();

	/**
	 * Sets {@link $_request} with the value of the requested superglobal var
	 * can be called directly but its also called by Ohara::data()
	 * @param string $type request, post or get. The name of the superblogal you want to fetch, defaults to request
	 * @access public
	 * @return void
	 */
	public function setData($type = 'request')
	{
		$types = array('request' => $_REQUEST, 'get' => $_GET, 'post' => $_POST);

		$this->_request = (empty($type) || !isset($types[$type])) ? $_REQUEST : $types[$type];

		unset($types);
	}

	/**
	 * Sanitizes and returns the requested value.
	 * calls Ohara::sanitize() to properly clean up
	 * @param string $var the superglobal's key name you want to retrieve
	 * @access public
	 * @return mixed
	 */
	public function get($var)
	{
		// Forgot something?
		if (empty($this->_request))
			$this->setData();

		$r = $this->validate($var) ? $this->sanitize($this->_request[$var]) : false;

		unset($this->_request);

		return $r;
	}

	/**
	 * Checks the var against {@link $_request} to know if it exists and its defined or not.
	 * calls Ohara::setData() in case {@link $_request} is empty by the time this method its called
	 * @param string $var the superglobal's key name you want to check
	 * @access public
	 * @return boolean
	 */
	public function validate($var)
	{
		// $var should always be a string, it should be the name of the var you want to validate, not the actual var!<commit_msg>Adds putData() fixes #10<commit_after><?php

/**
 * @package Ohara helper class
 * @version 1.1
 * @author <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2016, <NAME>
 * @license http://www.mozilla.org/MPL/2.0/
 */

namespace Suki;

class Data
{
	public function __construct($app)
	{
		$this->_app = $app;
	}

	/**
	 * Holds any sanitized data from $_REQUEST
	 * @access protected
	 * @var array
	 */
	protected $_request = array();

	/**
	 * Sets {@link $_request} with the value of the requested superglobal var
	 * can be called directly but its also called by Ohara::data()
	 * @param string $type request, post or get. The name of the superblogal you want to fetch, defaults to request
	 * @access public
	 * @return void
	 */
	public function setData($type = 'request')
	{
		$types = array('request' => $_REQUEST, 'get' => $_GET, 'post' => $_POST);

		$this->_request = (empty($type) || !isset($types[$type])) ? $_REQUEST : $types[$type];

		unset($types);
	}

	/**
	 * Inserts a new value to {@link $_request}
	 * @param array $data an array of data to be added. Uses a name => value format.
	 * @access public
	 * @return mixed false on fail array.
	 */
	public function putData($data = array())
	{
		if (empty($data))
			return false;

		// Forgot something?
		if (empty($this->_request))
			$this->setData();

		$data = (array) $data;

		foreach ($data as $name => $value)
		{
			$this->_request[$name] = $_REQUEST[$name] = $this->sanitize($this->_request[$value]);
		}

		return $this->_request;
	}

	/**
	 * Sanitizes and returns the requested value.
	 * calls Ohara::sanitize() to properly clean up
	 * @param string $var the superglobal's key name you want to retrieve
	 * @access public
	 * @return mixed
	 */
	public function get($var)
	{
		// Forgot something?
		if (empty($this->_request))
			$this->setData();

		$r = $this->validate($var) ? $this->sanitize($this->_request[$var]) : false;

		unset($this->_request);

		return $r;
	}

	/**
	 * Checks the var against {@link $_request} to know if it exists and its defined or not.
	 * calls Ohara::setData() in case {@link $_request} is empty by the time this method its called
	 * @param string $var the superglobal's key name you want to check
	 * @access public
	 * @return boolean
	 */
	public function validate($var)
	{
		// $var should always be a string, it should be the name of the var you want to validate, not the actual var!
{'fraction_non_alphanumeric': 0.14732878324311602, 'fraction_numerical': 0.004236290891974582, 'mean_word_length': 3.5116772823779194, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3577736', 'n_tokens_mistral': 1430, 'n_tokens_neox': 1304, 'n_words': 484}