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.

91 lines
2.3 KiB

<?php
/**
* Класс для работы с переменными окружения.
*
* @copyright NetMonsters <team@netmonsters.ru>
* @link http://netmonsters.ru
* @package Majestic
* @subpackage env
* @since
* @version SVN: $Id$
* @filesource $URL$
*/
class Env
{
static protected $request = null;
static public function getRequestUri()
{
if (self::$request === null) {
// removes get params
list(self::$request, ) = explode('?', Env::Server('REQUEST_URI'));
// removes base url
$base = FrontController::getInstance()->getBaseUrl();
if (($length = strlen($base)) > 0 && strpos(self::$request, $base) === 0) {
self::$request = (string) substr(self::$request, $length);
}
}
return self::$request;
}
static public function Get($var, $default = false)
{
return isset($_GET[$var]) ? $_GET[$var] : $default;
}
static public function Post($var, $default = false)
{
return isset($_POST[$var]) ? $_POST[$var] : $default;
}
static public function Server($var, $default = false)
{
return isset($_SERVER[$var]) ? $_SERVER[$var] : $default;
}
static public function Session($var, $default = false)
{
return isset($_SESSION[$var]) ? $_SESSION[$var] : $default;
}
static public function setSession($var, $value)
{
$_SESSION[$var] = $value;
}
/**
* Unsets session var
*
* @param string $var
*/
static public function unsetSession($var)
{
if (isset($_SESSION[$var])) {
unset($_SESSION[$var]);
}
}
static public function getCookie($var, $default = false)
{
return isset($_COOKIE[$var]) ? $_COOKIE[$var] : $default;
}
static public function setCookie($var, $value, $time = 0, $path = '/')
{
return setcookie($var, $value, $time, $path);
}
static public function Files($name = '', $default = array(), $param = false)
{
if (!isset($_FILES)) {
return $default;
}
if (empty($name)) {
return $_FILES;
}
$res = isset($_FILES[$name]) ? $_FILES[$name] : $default;
return $param ? $res[$param] : $res;
}
}