request.class.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Provides access to various HTTP request elements: GET, POST, FILE, etc paramaters.
  4. * @license see /license.txt
  5. * @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
  6. */
  7. class Request
  8. {
  9. public static function get($key, $default = null)
  10. {
  11. return isset($_REQUEST[$key]) ? $_REQUEST[$key] : $default;
  12. }
  13. public static function has($key){
  14. return isset($_REQUEST[$key]);
  15. }
  16. /**
  17. * Returns true if the request is a GET request. False otherwise.
  18. *
  19. * @return bool
  20. */
  21. public static function is_get()
  22. {
  23. $method = self::server()->request_method();
  24. $method = strtoupper($method);
  25. return $method == 'GET';
  26. }
  27. public static function post($key, $default = null)
  28. {
  29. return isset($_POST[$key]) ? $_POST[$key] : $default;
  30. }
  31. /**
  32. * Returns true if the request is a POST request. False otherwise.
  33. *
  34. * @return bool
  35. */
  36. public static function is_post()
  37. {
  38. $method = self::server()->request_method();
  39. $method = strtoupper($method);
  40. return $method == 'POST';
  41. }
  42. static function file($key, $default = null)
  43. {
  44. return isset($_FILES[$key]) ? $_FILES[$key] : $default;
  45. }
  46. static function environment($key, $default = null)
  47. {
  48. return isset($_ENV[$key]) ? $_ENV[$key] : $default;
  49. }
  50. }