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.0 KiB

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