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: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150:
<?php
/**
* MvcCore
*
* This source file is subject to the BSD 3 License
* For the full copyright and license information, please view
* the LICENSE.md file that are distributed with this source code.
*
* @copyright Copyright (c) 2016 Tom Flidr (https://github.com/mvccore)
* @license https://mvccore.github.io/docs/mvccore/5.0.0/LICENCE.md
*/
namespace MvcCore;
/**
* Responsibility - session data management - starting, writing and expirations.
* - Safe start (only once)
* - By `\MvcCore\Session::Start()`
* - Called by `\MvcCore\Application::GetInstance()->SessionStart();`
* - Called by `\MvcCore\Controller::Init();`.
* - Session writing and closing at request end:
* - In `\MvcCore\Session::Close()`
* - Called over `register_shutdown_function()`
* from `\MvcCore::Terminate();`
* - Session namespaces management:
* - Variables expiration by seconds.
* - Variables expiration by request hoops.
*/
interface ISession extends \MvcCore\Session\IConstants {
/**
* Session safe start only once.
* - called by `\MvcCore\Application::GetInstance()->SessionStart();`
* - called by `\MvcCore\Controller::Init();`
* It's free to call this function anywhere sooner for custom purposes,
* for example in `Bootstrap.php` by: `\MvcCore\Application::GetInstance()->SessionStart();`
* @return void
*/
public static function Start ();
/**
* Get Unix epoch for current request session start moment.
* @return int
*/
public static function GetSessionStartTime ();
/**
* Get static boolean about if session has been already started or not.
* @return bool
*/
public static function GetStarted ();
/**
* Get session metadata about session namespaces.
* This method is used for debugging purposes.
* @return \stdClass
*/
public static function GetSessionMetadata ();
/**
* Write and close session in `\MvcCore::Terminate();`.
* Serialize all metadata and call php function to write session into php session storage.
* (HDD, Redis, database, etc., depends on php configuration).
* @return void
*/
public static function Close ();
/**
* Get new or existing MvcCore session namespace instance.
* If session is not started, start session.
* @param string $name Session namespace unique name.
* @return \MvcCore\Session
*/
public static function GetNamespace ($name = \MvcCore\ISession::DEFAULT_NAMESPACE_NAME);
/**
* Set MvcCore session namespace expiration by page request(s) count.
* @param int $hoops
* @return \MvcCore\Session
*/
public function SetExpirationHoops ($hoops);
/**
* Set MvcCore session namespace expiration by expiration seconds.
* Zero (`0`) means "until the browser is closed" if there is no more
* higher namespace expirations in whole session.
* @param int $seconds
* @return \MvcCore\Session
*/
public function SetExpirationSeconds ($seconds);
/**
* Send `PHPSESSID` http cookie with session id hash before response body is sent.
* This function is always called by `\MvcCore\Application::Terminate();` at the request end.
* @return void
*/
public static function SendCookie ();
/**
* Get the highest expiration in seconds for namespace with
* the highest expiration to set expiration for `PHPSESSID` cookie.
* @return int
*/
public static function GetSessionMaxTime ();
/**
* Destroy whole session namespace in `$_SESSION` storage
* and internal static storages.
* @return void
*/
public function Destroy ();
/**
* Destroy all existing session namespaces in `$_SESSION` storage
* and internal static storages, destroy whole PHP session.
* @return void
*/
public static function DestroyAll ();
/**
* Magic function triggered by: `$value = \MvcCore\Session->key;`.
* @param string $key
* @return mixed
*/
public function __get ($key);
/**
* Magic function triggered by: `\MvcCore\Session->key = "value";`.
* @param string $key
* @param mixed $value
* @return void
*/
public function __set ($key, $value);
/**
* Magic function triggered by: `isset(\MvcCore\Session->key);`.
* @param string $key
* @return bool
*/
public function __isset ($key);
/**
* Magic function triggered by: `unset(\MvcCore\Session->key);`.
* @param string $key
* @return void
*/
public function __unset ($key);
}