1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103:
<?php
namespace MvcCore\Session;
trait NamespaceMethods {
public static function GetNamespace (
$name = \MvcCore\ISession::DEFAULT_NAMESPACE_NAME
) {
if (!static::GetStarted())
static::Start();
if (!isset(static::$instances[$name])) {
$instance = new static();
$instance->__name = $name;
static::$meta->names[$name] = 1;
if (!isset($_SESSION[$name]))
$_SESSION[$name] = [];
static::$instances[$name] = $instance;
}
return static::$instances[$name];
}
public function SetExpirationHoops ($hoops) {
static::$meta->hoops[$this->__name] = $hoops;
return $this;
}
public function SetExpirationSeconds ($seconds = 0) {
if ($seconds > 0)
static::$meta->expirations[$this->__name] = static::$sessionStartTime + $seconds;
return $this;
}
public function Destroy () {
$name = $this->__name;
$names = & static::$meta->names;
$hoops = & static::$meta->hoops;
$expirations = & static::$meta->expirations;
$instances = & static::$instances;
if (isset($names[$name])) unset($names[$name]);
if (isset($hoops[$name])) unset($hoops[$name]);
if (isset($expirations[$name])) unset($expirations[$name]);
if (isset($_SESSION[$name])) unset($_SESSION[$name]);
if (isset($instances[$name])) unset($instances[$name]);
}
public static function DestroyAll () {
session_destroy();
$_SESSION = NULL;
static::$started = FALSE;
$response = \MvcCore\Application::GetInstance()->GetResponse();
if (!$response->IsSent()) {
$params = (object) session_get_cookie_params();
$response->DeleteCookie(
session_name(),
$params->path,
$params->domain,
$params->secure
);
}
}
}