You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.3 KiB

  1. <?php
  2. /**
  3. * Класс для работы с переменными окружения.
  4. *
  5. * @copyright NetMonsters <team@netmonsters.ru>
  6. * @link http://netmonsters.ru
  7. * @package Majestic
  8. * @subpackage env
  9. * @since
  10. * @version SVN: $Id$
  11. * @filesource $URL$
  12. */
  13. class Env
  14. {
  15. static protected $request = null;
  16. static public function getRequestUri()
  17. {
  18. if (self::$request === null) {
  19. // removes get params
  20. list(self::$request, ) = explode('?', Env::Server('REQUEST_URI'));
  21. // removes base url
  22. $base = FrontController::getInstance()->getBaseUrl();
  23. if (($length = strlen($base)) > 0 && strpos(self::$request, $base) === 0) {
  24. self::$request = (string) substr(self::$request, $length);
  25. }
  26. }
  27. return self::$request;
  28. }
  29. static public function Get($var, $default = false)
  30. {
  31. return isset($_GET[$var]) ? $_GET[$var] : $default;
  32. }
  33. static public function Post($var, $default = false)
  34. {
  35. return isset($_POST[$var]) ? $_POST[$var] : $default;
  36. }
  37. static public function Server($var, $default = false)
  38. {
  39. return isset($_SERVER[$var]) ? $_SERVER[$var] : $default;
  40. }
  41. static public function Session($var, $default = false)
  42. {
  43. return isset($_SESSION[$var]) ? $_SESSION[$var] : $default;
  44. }
  45. static public function setSession($var, $value)
  46. {
  47. $_SESSION[$var] = $value;
  48. }
  49. /**
  50. * Unsets session var
  51. *
  52. * @param string $var
  53. */
  54. static public function unsetSession($var)
  55. {
  56. if (isset($_SESSION[$var])) {
  57. unset($_SESSION[$var]);
  58. }
  59. }
  60. static public function getCookie($var, $default = false)
  61. {
  62. return isset($_COOKIE[$var]) ? $_COOKIE[$var] : $default;
  63. }
  64. static public function setCookie($var, $value, $time = 0, $path = '/')
  65. {
  66. return setcookie($var, $value, $time, $path);
  67. }
  68. static public function Files($name = '', $default = array(), $param = false)
  69. {
  70. if (!isset($_FILES)) {
  71. return $default;
  72. }
  73. if (empty($name)) {
  74. return $_FILES;
  75. }
  76. $res = isset($_FILES[$name]) ? $_FILES[$name] : $default;
  77. return $param ? $res[$param] : $res;
  78. }
  79. }