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.
124 lines
3.1 KiB
124 lines
3.1 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 protected $params = array();
|
|
|
|
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($key = null, $default = null)
|
|
{
|
|
if ($key === null) {
|
|
return $_GET;
|
|
}
|
|
return (isset($_GET[$key])) ? $_GET[$key] : $default;
|
|
}
|
|
|
|
static public function Post($key = null, $default = null)
|
|
{
|
|
if ($key === null) {
|
|
return $_POST;
|
|
}
|
|
return (isset($_POST[$key])) ? $_POST[$key] : $default;
|
|
}
|
|
|
|
static public function Cookie($key = null, $default = false)
|
|
{
|
|
if ($key === null) {
|
|
return $_COOKIE;
|
|
}
|
|
return (isset($_COOKIE[$key])) ? $_COOKIE[$key] : $default;
|
|
}
|
|
|
|
static public function Server($key = null, $default = null)
|
|
{
|
|
if ($key === null) {
|
|
return $_SERVER;
|
|
}
|
|
return (isset($_SERVER[$key])) ? $_SERVER[$key] : $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 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;
|
|
}
|
|
|
|
static public function getParam($key = null, $default = false)
|
|
{
|
|
if ($key === null) {
|
|
return self::$params;
|
|
}
|
|
return (isset(self::$params[$key])) ? self::$params[$key] : $default;
|
|
}
|
|
|
|
static public function setParam($key, $value)
|
|
{
|
|
self::$params[$key] = $value;
|
|
}
|
|
|
|
static public function setParams($params = array())
|
|
{
|
|
self::$params = self::$params + $params;
|
|
}
|
|
|
|
}
|