Skip to content

Instantly share code, notes, and snippets.

@biakaveron
Created June 24, 2009 13:57
Show Gist options
  • Save biakaveron/135287 to your computer and use it in GitHub Desktop.
Save biakaveron/135287 to your computer and use it in GitHub Desktop.
input helper
<?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