Files
majestic/classes/Env.class.php
pzinovkin f9ef17a685 No more relative urls by default, #16
git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@129 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
2010-03-15 21:06:36 +00:00

103 lines
2.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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 = array();
static protected $params = array();
static public function getRequestUri($trim_base = false)
{
if (!isset(self::$request[$trim_base])) {
// removes get params
list(self::$request[$trim_base], ) = explode('?', Env::Server('REQUEST_URI'));
if ($trim_base) {
// removes base url
$base = FrontController::getInstance()->getBaseUrl();
if (($length = strlen($base)) > 0 && strpos(self::$request[$trim_base], $base) === 0) {
self::$request[$trim_base] = (string) substr(self::$request[$trim_base], $length);
}
}
}
return self::$request[$trim_base];
}
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 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;
}
}