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.

63 lines
1.5 KiB

  1. <?php
  2. /**
  3. * Класс для работы с переменными окружения.
  4. *
  5. */
  6. final class Env
  7. {
  8. static public $params = array();
  9. static function Get($var, $default = false)
  10. {
  11. return isset($_GET[$var]) ? $_GET[$var] : $default;
  12. }
  13. static function Post($var, $default = false)
  14. {
  15. return isset($_POST[$var]) ? $_POST[$var] : $default;
  16. }
  17. static function Server($var, $default = false)
  18. {
  19. return isset($_SERVER[$var]) ? $_SERVER[$var] : $default;
  20. }
  21. static function Session($var, $default = false)
  22. {
  23. return isset($_SESSION[$var]) ? $_SESSION[$var] : $default;
  24. }
  25. static function getCookie($var, $default = false)
  26. {
  27. return isset($_COOKIE[$var]) ? $_COOKIE[$var] : $default;
  28. }
  29. static function setCookie($var, $value, $time = 0, $path = '/')
  30. {
  31. return setcookie($var, $value, $time, $path);
  32. }
  33. static function getParam($var, $default = false)
  34. {
  35. return isset(self::$params[$var]) ? self::$params[$var] : $default;
  36. }
  37. static function setParam($var, $val)
  38. {
  39. self::$params[$var] = $val;
  40. }
  41. static function setParams($params=array())
  42. {
  43. self::$params = self::$params + $params;
  44. }
  45. static function parseTimer($time)
  46. {
  47. $hours = intval($time / 3600);
  48. $minutes = intval($time/60 - $hours*60);
  49. return sprintf('%02d:%02d:%02d', $hours, $minutes, $time - $hours*3600 - $minutes*60);
  50. }
  51. }
  52. ?>