Input filtering and helpers.
Class constructor.
| Type | Description |
|---|---|
| array | Array to validate |
NULL
public function __construct(array & $input)
{
$this->input = & $input;
}
Factory method making method chaining possible right off the bat.
| Type | Description |
|---|---|
| array | Array to validate |
mako\Validate
public static function factory(array & $input)
{
return new static($input);
}
Adds a filter to the list of callbacks.
| Type | Description |
|---|---|
| mixed | Field name |
| callback | Filter function |
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;
}
Runs all input filters.
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);
}
}
}
Fetch data from the $_GET array.
| Type | Description |
|---|---|
| string | (optional) Array key |
| mixed | (optional) Default value |
mixed
public static function get($key = null, $default = null)
{
return $key === null ? $_GET : Arr::get($_GET, $key, $default);
}
Fetch data from the $_POST array.
| Type | Description |
|---|---|
| string | (optional) Array key |
| mixed | (optional) Default value |
mixed
public static function post($key = null, $default = null)
{
return $key === null ? $_POST : Arr::get($_POST, $key, $default);
}
Fetch data from the $_COOKIE array.
| Type | Description |
|---|---|
| string | (optional) Array key |
| mixed | (optional) Default value |
mixed
public static function cookie($key = null, $default = null)
{
return $key === null ? $_COOKIE : Arr::get($_COOKIE, $key, $default);
}
Fetch data from the $_FILES array.
| Type | Description |
|---|---|
| string | (optional) Array key |
| mixed | (optional) Default value |
mixed
public static function files($key = null, $default = null)
{
return $key === null ? $_FILES : Arr::get($_FILES, $key, $default);
}
Fetch data from the $_SERVER array.
| Type | Description |
|---|---|
| string | (optional) Array key |
| mixed | (optional) Default value |
mixed
public static function server($key = null, $default = null)
{
return $key === null ? $_SERVER : Arr::get($_SERVER, $key, $default);
}
Fetch data from the $_ENV array.
| Type | Description |
|---|---|
| string | (optional) Array key |
| mixed | (optional) Default value |
mixed
public static function env($key = null, $default = null)
{
return $key === null ? $_ENV : Arr::get($_ENV, $key, $default);
}
Fetch data from the $_SESSION array.
| Type | Description |
|---|---|
| string | (optional) Array key |
| mixed | (optional) Default value |
mixed
public static function session($key = null, $default = null)
{
return $key === null ? $_SESSION : Arr::get($_SESSION, $key, $default);
}
Returns PUT data.
| Type | Description |
|---|---|
| mixed | (optional) Default value |
mixed
public static function put($default = null)
{
$data = file_get_contents('php://input');
return !empty($data) ? $data : $default;
}