Actualización
This commit is contained in:
152
main/inc/lib/system/session.class.php
Normal file
152
main/inc/lib/system/session.class.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
namespace System;
|
||||
|
||||
/**
|
||||
* Session Management.
|
||||
*
|
||||
* @see ChamiloSession
|
||||
*
|
||||
* @license see /license.txt
|
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
|
||||
*/
|
||||
class Session implements \ArrayAccess
|
||||
{
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function __unset($name)
|
||||
{
|
||||
unset($_SESSION[$name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function __isset($name)
|
||||
{
|
||||
return self::has($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* It it exists returns the value stored at the specified offset.
|
||||
* If offset does not exists returns null. Do not trigger a warning.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
return self::read($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function __set($name, $value)
|
||||
{
|
||||
self::write($name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $variable
|
||||
* @param null $default
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function read($variable, $default = null)
|
||||
{
|
||||
return isset($_SESSION[$variable]) ? $_SESSION[$variable] : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $variable
|
||||
* @param mixed $value
|
||||
*/
|
||||
public static function write($variable, $value)
|
||||
{
|
||||
$_SESSION[$variable] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $variable
|
||||
*/
|
||||
public static function erase($variable)
|
||||
{
|
||||
$variable = (string) $variable;
|
||||
if (isset($GLOBALS[$variable])) {
|
||||
unset($GLOBALS[$variable]);
|
||||
}
|
||||
if (isset($_SESSION[$variable])) {
|
||||
unset($_SESSION[$variable]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if session has variable set up, false otherwise.
|
||||
*
|
||||
* @param string $variable
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function has($variable)
|
||||
{
|
||||
return isset($_SESSION[$variable]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear session.
|
||||
*/
|
||||
public static function clear()
|
||||
{
|
||||
session_regenerate_id();
|
||||
session_unset();
|
||||
$_SESSION = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy session.
|
||||
*/
|
||||
public static function destroy()
|
||||
{
|
||||
session_unset();
|
||||
$_SESSION = [];
|
||||
session_destroy();
|
||||
}
|
||||
|
||||
/*
|
||||
* ArrayAccess : bool
|
||||
*/
|
||||
public function offsetExists($offset): bool
|
||||
{
|
||||
return isset($_SESSION[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* It it exists returns the value stored at the specified offset.
|
||||
* If offset does not exists returns null. Do not trigger a warning.
|
||||
*
|
||||
* @param string $offset
|
||||
*
|
||||
* @return mixed (write offsetGet($offset): mixed on PHP 8 and & > )
|
||||
*/
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
return self::read($offset);
|
||||
}
|
||||
|
||||
public function offsetSet($offset, $value): void
|
||||
{
|
||||
self::write($offset, $value);
|
||||
}
|
||||
|
||||
public function offsetUnset($offset): void
|
||||
{
|
||||
unset($_SESSION[$offset]);
|
||||
}
|
||||
}
|
||||
60
main/inc/lib/system/web/request.class.php
Normal file
60
main/inc/lib/system/web/request.class.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Provides access to various HTTP request elements: GET, POST, FILE, etc paramaters.
|
||||
* @license see /license.txt
|
||||
* @deprecated
|
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
|
||||
*/
|
||||
class Request
|
||||
{
|
||||
|
||||
public static function get($key, $default = null)
|
||||
{
|
||||
return isset($_REQUEST[$key]) ? $_REQUEST[$key] : $default;
|
||||
}
|
||||
|
||||
public static function has($key) {
|
||||
return isset($_REQUEST[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the request is a GET request. False otherwise.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_get()
|
||||
{
|
||||
$method = self::server()->request_method();
|
||||
$method = strtoupper($method);
|
||||
return $method == 'GET';
|
||||
}
|
||||
|
||||
public static function post($key, $default = null)
|
||||
{
|
||||
return isset($_POST[$key]) ? $_POST[$key] : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the request is a POST request. False otherwise.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_post()
|
||||
{
|
||||
$method = self::server()->request_method();
|
||||
$method = strtoupper($method);
|
||||
return $method == 'POST';
|
||||
}
|
||||
|
||||
static function file($key, $default = null)
|
||||
{
|
||||
return isset($_FILES[$key]) ? $_FILES[$key] : $default;
|
||||
}
|
||||
|
||||
static function environment($key, $default = null)
|
||||
{
|
||||
return isset($_ENV[$key]) ? $_ENV[$key] : $default;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user