request.class.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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($_GET[$key]) ? $_GET[$key] : $default;
  12. }
  13. /**
  14. * Returns true if the request is a GET request. False otherwise.
  15. *
  16. * @return bool
  17. */
  18. public static function is_get()
  19. {
  20. $method = self::server()->request_method();
  21. $method = strtoupper($method);
  22. return $method == 'GET';
  23. }
  24. public static function post($key, $default = null)
  25. {
  26. return isset($_POST[$key]) ? $_POST[$key] : $default;
  27. }
  28. /**
  29. * Returns true if the request is a POST request. False otherwise.
  30. *
  31. * @return bool
  32. */
  33. public static function is_post()
  34. {
  35. $method = self::server()->request_method();
  36. $method = strtoupper($method);
  37. return $method == 'POST';
  38. }
  39. /**
  40. *
  41. * @return RequestServer
  42. */
  43. static function server()
  44. {
  45. return RequestServer::instance();
  46. }
  47. static function file($key, $default = null)
  48. {
  49. return isset($_FILES[$key]) ? $_FILES[$key] : $default;
  50. }
  51. static function environment($key, $default = null)
  52. {
  53. return isset($_ENV[$key]) ? $_ENV[$key] : $default;
  54. }
  55. }