Created
July 29, 2018 22:13
-
-
Save apertaoxis/a71302c415c6b49537fcaa4f61ba4ee9 to your computer and use it in GitHub Desktop.
Funções uteis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| if (!function_exists('filter')) { | |
| /** | |
| * @param int $source | |
| * @param string $index | |
| * @return mixed | |
| */ | |
| function filter($source, $index) | |
| { | |
| return filter_input($source, $index); | |
| } | |
| } | |
| if (!function_exists('parse')) { | |
| /** | |
| * @param mixed $value | |
| * @return string | |
| */ | |
| function parse($value) | |
| { | |
| switch (gettype($value)) { | |
| case TYPE_BOOLEAN: | |
| return $value ? 'true' : 'false'; | |
| break; | |
| case TYPE_INTEGER: | |
| case TYPE_FLOAT: | |
| case TYPE_STRING: | |
| return trim($value); | |
| break; | |
| case TYPE_ARRAY: | |
| case TYPE_OBJECT: | |
| case TYPE_RESOURCE: | |
| return json_encode($value); | |
| // case TYPE_NULL: | |
| // case TYPE_UNKNOWN_TYPE: | |
| default: | |
| return ''; | |
| } | |
| } | |
| } | |
| if (!function_exists('get')) { | |
| /** | |
| * @param mixed $index | |
| * @param string $filter (FILTER_DEFAULT) | |
| * @return mixed | |
| */ | |
| function get($index, $filter = FILTER_DEFAULT) | |
| { | |
| return filter_input(INPUT_GET, $index, $filter); | |
| } | |
| } | |
| if (!function_exists('post')) { | |
| /** | |
| * @param mixed $index | |
| * @param string $filter (FILTER_DEFAULT) | |
| * @return mixed | |
| */ | |
| function post($index, $filter = FILTER_DEFAULT) | |
| { | |
| return filter_input(INPUT_POST, $index, $filter); | |
| } | |
| } | |
| if (!function_exists('server')) { | |
| /** | |
| * @param string $index | |
| * @return mixed | |
| */ | |
| function server($index) | |
| { | |
| return filter(INPUT_SERVER, $index); | |
| } | |
| } | |
| if (!function_exists('cookie')) { | |
| /** | |
| * @param string $index | |
| * @return mixed | |
| */ | |
| function cookie($index) | |
| { | |
| return filter(INPUT_COOKIE, $index); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment