mako\Input


Description


Input filtering and helpers.


Class methods


Toggle source

public __construct(&$input)


Class constructor.


Parameters

Type Description
array Array to validate
Return value

NULL

public function __construct(array & $input)
{
	$this->input = & $input;
}

Toggle source

public static factory(&$input)


Factory method making method chaining possible right off the bat.


Parameters

Type Description
array Array to validate
Return value

mako\Validate

public static function factory(array & $input)
{
	return new static($input);
}

Toggle source

public filter($field, $function)


Adds a filter to the list of callbacks.


Parameters

Type Description
mixed Field name
callback Filter function
Return value

mako\Validate

public function filter($field, $function)
{
	!is_array($function) && $function = array($function);

	$callback['function'] = $function[0];
	$callback['params']   = isset($function[1]) ? $function[1] : array();
	
	if($field === '*')
	{
		foreach(array_keys($this->input) as $field)
		{
			$this->filters[$field][] = $callback;
		}
	}
	else
	{
		$this->filters[$field][] = $callback;
	}
	
	return $this;
}

Toggle source

public process()


Runs all input filters.

Return value

array

public function process()
{
	foreach($this->filters as $field => $filters)
	{
		foreach($filters as $callback)
		{
			$params = array_merge(array($this->input[$field]), $callback['params']);
							
			$this->input[$field] = call_user_func_array($callback['function'], $params);
		}
	}
}

Toggle source

public static get($key = NULL, $default = NULL)


Fetch data from the $_GET array.


Parameters

Type Description
string (optional) Array key
mixed (optional) Default value
Return value

mixed

public static function get($key = null, $default = null)
{
	return $key === null ? $_GET : Arr::get($_GET, $key, $default);
}

Toggle source

public static post($key = NULL, $default = NULL)


Fetch data from the $_POST array.


Parameters

Type Description
string (optional) Array key
mixed (optional) Default value
Return value

mixed

public static function post($key = null, $default = null)
{
	return $key === null ? $_POST : Arr::get($_POST, $key, $default);
}

Toggle source

public static cookie($key = NULL, $default = NULL)


Fetch data from the $_COOKIE array.


Parameters

Type Description
string (optional) Array key
mixed (optional) Default value
Return value

mixed

public static function cookie($key = null, $default = null)
{
	return $key === null ? $_COOKIE : Arr::get($_COOKIE, $key, $default);
}

Toggle source

public static files($key = NULL, $default = NULL)


Fetch data from the $_FILES array.


Parameters

Type Description
string (optional) Array key
mixed (optional) Default value
Return value

mixed

public static function files($key = null, $default = null)
{
	return $key === null ? $_FILES : Arr::get($_FILES, $key, $default);
}

Toggle source

public static server($key = NULL, $default = NULL)


Fetch data from the $_SERVER array.


Parameters

Type Description
string (optional) Array key
mixed (optional) Default value
Return value

mixed

public static function server($key = null, $default = null)
{
	return $key === null ? $_SERVER : Arr::get($_SERVER, $key, $default);
}

Toggle source

public static env($key = NULL, $default = NULL)


Fetch data from the $_ENV array.


Parameters

Type Description
string (optional) Array key
mixed (optional) Default value
Return value

mixed

public static function env($key = null, $default = null)
{
	return $key === null ? $_ENV : Arr::get($_ENV, $key, $default);
}

Toggle source

public static session($key = NULL, $default = NULL)


Fetch data from the $_SESSION array.


Parameters

Type Description
string (optional) Array key
mixed (optional) Default value
Return value

mixed

public static function session($key = null, $default = null)
{
	return $key === null ? $_SESSION : Arr::get($_SESSION, $key, $default);
}

Toggle source

public static put($default = NULL)


Returns PUT data.


Parameters

Type Description
mixed (optional) Default value
Return value

mixed

public static function put($default = null)
{
	$data = file_get_contents('php://input');

	return !empty($data) ? $data : $default;
}