Created
June 24, 2009 13:57
-
-
Save biakaveron/135287 to your computer and use it in GitHub Desktop.
input helper
This file contains 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 defined('SYSPATH') or die('No direct script access.'); | |
class Kohana_Input { | |
protected static $user_agent = FALSE; | |
public static function get($key = NULL, $default = NULL) { | |
return self::find_key($_GET, $key, $default); | |
} | |
public static function post($key = NULL, $default = NULL) { | |
return self::find_key($_POST, $key, $default); | |
} | |
public static function cookie($key = NULL, $default = NULL) { | |
return self::find_key($_COOKIE, $key, $default); | |
} | |
public static function server($key = NULL, $default = NULL) { | |
return self::find_key($_SERVER, $key, $default); | |
} | |
public static function user_agent() { | |
if (self::$user_agent === FALSE) { | |
self::$user_agent = ( ! empty($_SERVER['HTTP_USER_AGENT']) ? trim($_SERVER['HTTP_USER_AGENT']) : ''); | |
} | |
return self::$user_agent; | |
} | |
protected static function find_key($array, $key = NULL, $default = NULL) { | |
if (is_null($key)) | |
return $array; | |
if (is_string($key) AND array_key_exists($key, $array)) | |
return $array[$key]; | |
return $default; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment