Code refactoring, #16
git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@114 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
This commit is contained in:
@ -3,38 +3,54 @@
|
||||
* Класс для работы с переменными окружения.
|
||||
*
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage Core
|
||||
* @subpackage env
|
||||
* @since
|
||||
* @version SVN: $Id$
|
||||
* @filesource $URL$
|
||||
*/
|
||||
final class Env
|
||||
{
|
||||
static public $params = array();
|
||||
|
||||
static function Get($var, $default = false)
|
||||
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 function Post($var, $default = false)
|
||||
static public function Post($var, $default = false)
|
||||
{
|
||||
return isset($_POST[$var]) ? $_POST[$var] : $default;
|
||||
}
|
||||
|
||||
static function Server($var, $default = false)
|
||||
static public function Server($var, $default = false)
|
||||
{
|
||||
return isset($_SERVER[$var]) ? $_SERVER[$var] : $default;
|
||||
}
|
||||
|
||||
static function Session($var, $default = false)
|
||||
static public function Session($var, $default = false)
|
||||
{
|
||||
return isset($_SESSION[$var]) ? $_SESSION[$var] : $default;
|
||||
}
|
||||
|
||||
static function setSession($var, $value)
|
||||
static public function setSession($var, $value)
|
||||
{
|
||||
$_SESSION[$var] = $value;
|
||||
}
|
||||
@ -44,48 +60,32 @@ final class Env
|
||||
*
|
||||
* @param string $var
|
||||
*/
|
||||
static function unsetSession($var)
|
||||
static public function unsetSession($var)
|
||||
{
|
||||
if (isset($_SESSION[$var])) {
|
||||
unset($_SESSION[$var]);
|
||||
}
|
||||
}
|
||||
|
||||
static function getCookie($var, $default = false)
|
||||
static public function getCookie($var, $default = false)
|
||||
{
|
||||
return isset($_COOKIE[$var]) ? $_COOKIE[$var] : $default;
|
||||
}
|
||||
|
||||
static function setCookie($var, $value, $time = 0, $path = '/')
|
||||
static public function setCookie($var, $value, $time = 0, $path = '/')
|
||||
{
|
||||
return setcookie($var, $value, $time, $path);
|
||||
}
|
||||
|
||||
static function getParam($var, $default = false)
|
||||
{
|
||||
return isset(self::$params[$var]) ? self::$params[$var] : $default;
|
||||
}
|
||||
|
||||
static function setParam($var, $val)
|
||||
{
|
||||
self::$params[$var] = $val;
|
||||
}
|
||||
|
||||
static function setParams($params=array())
|
||||
{
|
||||
self::$params = self::$params + $params;
|
||||
}
|
||||
|
||||
static public function Files($name = '', $default = array(), $param = false)
|
||||
{
|
||||
if(!isset($_FILES)){
|
||||
if (!isset($_FILES)) {
|
||||
return $default;
|
||||
}
|
||||
if(empty($name)){
|
||||
if (empty($name)) {
|
||||
return $_FILES;
|
||||
}
|
||||
$res = isset($_FILES[$name]) ? $_FILES[$name] : $default;
|
||||
return $param ? $res[$param] : $res;
|
||||
}
|
||||
}
|
||||
?>
|
||||
}
|
Reference in New Issue
Block a user