Created
April 29, 2013 11:07
-
-
Save johnsardine/5480978 to your computer and use it in GitHub Desktop.
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 | |
| class Input | |
| { | |
| public static function get($key = null, $default = null) | |
| { | |
| if (!$key) | |
| return $_GET; | |
| if (!is_array($key)) | |
| $key = array($key); | |
| $str = '$_GET'; | |
| foreach ($key as $sub_key) { | |
| $str .= '["'.$sub_key.'"]'; | |
| } | |
| return eval('return (isset('.$str.')) ? '.$str.' : $default ;'); | |
| } | |
| public static function post($key = null, $default = null) | |
| { | |
| if (!$key) | |
| return $_POST; | |
| if (!is_array($key)) | |
| $key = array($key); | |
| $str = '$_POST'; | |
| foreach ($key as $sub_key) { | |
| $str .= '["'.$sub_key.'"]'; | |
| } | |
| return eval('return (isset('.$str.')) ? '.$str.' : $default ;'); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample
Input::get()// Returns $_GETInput::post()// Returns $_POSTInput::post('name', 'default')// Returns $_POST['name'], if not set, returns defaultInput::post(array('name', 'first'), 'default')// Returns $_POST['name']['first'], if not set, returns defaultIf using PHP > 5.4 you may write arrays with
[]Input::post(['name', 'first'], 'default')// Returns $_POST['name']['first'], if not set, returns default