Location: PHPKode > projects > Mocovie web framework > mocovi/library/Input.php
<?php

/**
 * Handles the GET parameter.
 *
 * The user can set some filter routines via the {@link filter()} method.
 *
 * Example for the filter pattern:
 * <code>
 * 		Input::filter(function($input) {
 * 			return htmlspecialchars($input); // escapes html special chars for every input
 * 		});
 *		$_GET['test'] = '<script type="text/javascript">';
 * 		var_dump(Input::get('test'));
 * </code>
 *
 * @author Kai Dorschner
 */
class Input
{
	protected static $instance;
	protected static $filter;

	/**
	 * Protected constructor because it is a singleton.
	 *
	 * @access protected
	 */
	protected function __construct()
	{}

	/**
	 * Returns a singelton instance.
	 *
	 * @access public
	 * @return Input
	 */
	public static function getInstance()
	{
		if(!self::$instance)
			self::$instance = new self();
		return self::$instance;
	}

	/**
	 * Adds a user-filter for the Input fields (like checking or filtering).
	 *
	 * @access public
	 * @return void
	 * @param Closure $filter Default: null
	 */
	public static function filter(Closure $filter = null)
	{
		self::$filter = $filter;
	}

	
	/**
	 * Returns a GET-value for the key.
	 *
	 * @access public
	 * @return mixed value
	 * @param string $key
	 */
	public static function get($key)
	{
		if(isset($_GET) && isset($_GET[$key]))
			if(!is_null(self::$filter))
			{
				$filter = self::$filter;
				return $filter($_GET[$key]);
			}
			else
				return $_GET[$key];
		return null;
	}
}
Return current item: Mocovie web framework