<commit_before><?php
/**
 * @author    <NAME> <<EMAIL>>
 * @license   http://opensource.org/licenses/mit-license.php MIT
 * @copyright Digiflex Development
 * @package   Helper
 * @link      www.ppiframework.com
 */
class PPI_Helper {

	/**
	 *
	 *
	 * @var null
	 */
	private static $_instance = null;

	/**
	 * The initialise function to create the instance
	 * @return void
	 */
	protected static function init() {
		self::setInstance(new PPI_Helper());
	}


	/**
	 * The function used to initially set the instance
	 *
	 * @param PPI_Helper $instance
	 * @throws PPI_Exception
	 * @return void
	 */
	static function setInstance(PPI_Helper $instance) {
		if (self::$_instance !== null) {
			throw new PPI_Exception('PPI_Helper is already initialised');
		}
		self::$_instance = $instance;
	}

	/**
	 * Obtain the instance if it exists, if not create it
	 *
	 * @return PPI_Helper
	 */
	static function getInstance() {
		if (self::$_instance === null) {
			self::init();
		}
		return self::$_instance;
	}

	/**
	 * Function to recursively trim strings
	 *
	 * @param mixed $input The input to be trimmed
	 * @return mixed
	 */
	function arrayTrim($input){
		if (!is_array($input)) {
			return trim($input);
		}
		return array_map(array($this, 'arrayTrim'), $input);
	}

	/**
	 * Get the config object
	 *
	 * @return object
	 */
	static function getConfig() {
		return PPI_Registry::getInstance()->get('PPI_Config');
	}

	/**
	 * Get the dispatcher object
	 *
	 * @return object
	 */
	static function getDispatcher() {
		return PPI_Registry::getInstance()->get('PPI_Dispatch');
	}

	/**
	 * Get the dispatcher object
	 *
	 * @return object
	 */
	static function getInput() {
		return self::getObjectFromRegistry('PPI_Input');
	}

	/**
	 * Get the session object
	 *
	 * @param mixed $p_mOptions The information to get a different cache object
	 * @return PPI_Session
	 */
	static function getSession($p_mOptions = null) {
		if (!is_array($p_mOptions)) {
			$config  = self::getConfig();
			$options = isset($config->session) ? $config->session->toArray() : array();
			$p_mOptions = $options;
		}
		return new PPI_Session($p_mOptions);
	}

	/**
	 * Get the cache object
	 *
	 * @param mixed $p_mOptions The information to get a different cache object
	 * @return PPI_Cache
	 */
	static function getCache($p_mOptions = null) {
		if (!is_array($p_mOptions)) {
			$config  = self::getConfig();
			$options = isset($config->cache) ? $config->cache->toArray() : array();
			if (is_string($p_mOptions) && $p_mOptions !== '') {
				$options['handler'] = $p_mOptions;
			}
			$p_mOptions = $options;
		}
		return new PPI_Cache($p_mOptions);
	}

	/**
	 * Get the router object
	 *
	 * @return object
	 */
	static function getRouter() {
		return self::getObjectFromRegistry('PPI_Router');
	}

	/**
	 * Get the router object
	 *
	 * @return object
	 */
	static function getSecurity() {
		return self::getObjectFromRegistry('PPI_Security');
	}

	static function getObjectFromRegistry($p_sClass) {
		$registry = PPI_Registry::getInstance();
		if(!$registry->exists($p_sClass)) {
		    $oClass = new $p_sClass();
			$registry->set($p_sClass, $oClass);
			return $oClass;
		}
		return $registry->get($p_sClass);
	}

	/**
	 * Get the registry object
	 *
	 * @return object
	 */
	static function getRegistry() {
		return PPI_Registry::getInstance();
	}

	/**
	 * Obtain the extension from a filename
     * @todo Move to PPI_File
	 * @param string $fileName The file's filename
	 * @return string
	 */
	static function getFileExtension($fileName, $includeDot = false) {
		$i = strrpos($fileName,".");
		if ($i === false) { return ''; }
		$l = strlen($fileName) - $i;
		return strtolower((($includeDot === true) ? '.' : '') . substr($fileName, $i+1, $l));
	}

	/**
	 * Check if a file has a particular extension. If it does not have the extension then we add it.
     *
	 * @todo Make this look for the last "." then take it from there so we're not vulnerable to file.php.txt
	 * @param string $p_sTemplateFile Filename
	 * @param string $p_sExtension Extension
	 * @return string
	 */<commit_msg>Adding in PPI_Helper as we now have PPI_Helper::getRequest()<commit_after><?php
/**
 * @author    <NAME> <<EMAIL>>
 * @license   http://opensource.org/licenses/mit-license.php MIT
 * @copyright Digiflex Development
 * @package   Helper
 * @link      www.ppiframework.com
 */
class PPI_Helper {

	/**
	 *
	 *
	 * @var null
	 */
	private static $_instance = null;

	/**
	 * The initialise function to create the instance
	 * @return void
	 */
	protected static function init() {
		self::setInstance(new PPI_Helper());
	}


	/**
	 * The function used to initially set the instance
	 *
	 * @param PPI_Helper $instance
	 * @throws PPI_Exception
	 * @return void
	 */
	static function setInstance(PPI_Helper $instance) {
		if (self::$_instance !== null) {
			throw new PPI_Exception('PPI_Helper is already initialised');
		}
		self::$_instance = $instance;
	}

	/**
	 * Obtain the instance if it exists, if not create it
	 *
	 * @return PPI_Helper
	 */
	static function getInstance() {
		if (self::$_instance === null) {
			self::init();
		}
		return self::$_instance;
	}

	/**
	 * Function to recursively trim strings
	 *
	 * @param mixed $input The input to be trimmed
	 * @return mixed
	 */
	function arrayTrim($input){
		if (!is_array($input)) {
			return trim($input);
		}
		return array_map(array($this, 'arrayTrim'), $input);
	}

	/**
	 * Get the config object
	 *
	 * @return object
	 */
	static function getConfig() {
		return PPI_Registry::getInstance()->get('PPI_Config');
	}

	/**
	 * Get the dispatcher object
	 *
	 * @return object
	 */
	static function getDispatcher() {
		return PPI_Registry::getInstance()->get('PPI_Dispatch');
	}

	/**
	 * Get the session object
	 *
	 * @param mixed $p_mOptions The information to get a different cache object
	 * @return PPI_Session
	 */
	static function getSession($p_mOptions = null) {
		if (!is_array($p_mOptions)) {
			$config  = self::getConfig();
			$options = isset($config->session) ? $config->session->toArray() : array();
			$p_mOptions = $options;
		}
		return new PPI_Session($p_mOptions);
	}

	/**
	 * Get the cache object
	 *
	 * @param mixed $p_mOptions The information to get a different cache object
	 * @return PPI_Cache
	 */
	static function getCache($p_mOptions = null) {
		if (!is_array($p_mOptions)) {
			$config  = self::getConfig();
			$options = isset($config->cache) ? $config->cache->toArray() : array();
			if (is_string($p_mOptions) && $p_mOptions !== '') {
				$options['handler'] = $p_mOptions;
			}
			$p_mOptions = $options;
		}
		return new PPI_Cache($p_mOptions);
	}

	/**
	 * Get the router object
	 *
	 * @return object
	 */
	static function getRouter() {
		return self::getObjectFromRegistry('PPI_Router');
	}

	/**
	 * Get the router object
	 *
	 * @return object
	 */
	static function getSecurity() {
		return self::getObjectFromRegistry('PPI_Security');
	}

	static function getObjectFromRegistry($p_sClass) {
		$registry = PPI_Registry::getInstance();
		if(!$registry->exists($p_sClass)) {
		    $oClass = new $p_sClass();
			$registry->set($p_sClass, $oClass);
			return $oClass;
		}
		return $registry->get($p_sClass);
	}

	/**
	 * Get the registry object
	 *
	 * @static
	 * @return object
	 */
	static function getRegistry() {
		return PPI_Registry::getInstance();
	}

	/**
	 * Get the PPI_Request object cached from the registry
	 *
	 * @static
	 * @return mixed
	 */
	static function getRequest() {
		return self::getObjectFromRegistry('PPI_Request');

	}

	/**
	 * Obtain the extension from a filename
     * @todo Move to PPI_File
	 * @param string $fileName The file's filename
	 * @return string
	 */
	static function getFileExtension($fileName, $includeDot = false) {
		$i = strrpos($fileName,".");
		if ($i === false) { return ''; }
		$l = strlen($fileName) - $i;
		return strtolower((($includeDot === true) ? '.' : '') . substr($fileName, $i+1, $l));
	}

	/**
	 * Check if a file has a particular extension. If it does not have the extension then we add it.
     *
	 * @todo Make this look for the last "." then take it from there so we're not vulnerable to file.php.txt
	 * @param string $p_sTemplateFile Filename
	 * @param string $p_sExtension Extension
	 * @return string
	 */
{'fraction_non_alphanumeric': 0.14619387631610795, 'fraction_numerical': 0.00024204284158296018, 'mean_word_length': 3.47428262046562, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1810492', 'n_tokens_mistral': 2906, 'n_tokens_neox': 2582, 'n_words': 717}