diff options
| author | Gerardo Zamudio <gerardozamudio@users.noreply.github.com> | 2016-02-24 23:48:50 -0600 |
|---|---|---|
| committer | Gerardo Zamudio <gerardozamudio@users.noreply.github.com> | 2016-02-24 23:48:50 -0600 |
| commit | e4de6b3898b64b26d29aff31f21df5fda8055686 (patch) | |
| tree | 575f8a65440f291d70a070d168eafca8c82a6459 /app/Core/Session/SessionStorage.php | |
| parent | d9ffbea174ea6524d0a22f8375ca8b3aa04a3c96 (diff) | |
| parent | a6540bc604c837d92c9368540c145606723e97f7 (diff) | |
Merge pull request #1 from fguillot/master
Update from upstream
Diffstat (limited to 'app/Core/Session/SessionStorage.php')
| -rw-r--r-- | app/Core/Session/SessionStorage.php | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/app/Core/Session/SessionStorage.php b/app/Core/Session/SessionStorage.php new file mode 100644 index 00000000..667d9253 --- /dev/null +++ b/app/Core/Session/SessionStorage.php @@ -0,0 +1,89 @@ +<?php + +namespace Kanboard\Core\Session; + +/** + * Session Storage + * + * @package session + * @author Frederic Guillot + * + * @property array $user + * @property array $flash + * @property array $csrf + * @property array $postAuthenticationValidated + * @property array $filters + * @property string $redirectAfterLogin + * @property string $captcha + * @property string $commentSorting + * @property bool $hasSubtaskInProgress + * @property bool $hasRememberMe + * @property bool $boardCollapsed + * @property bool $twoFactorBeforeCodeCalled + * @property string $twoFactorSecret + */ +class SessionStorage +{ + /** + * Pointer to external storage + * + * @access private + * @var array + */ + private $storage = array(); + + /** + * Set external storage + * + * @access public + * @param array $storage External session storage (example: $_SESSION) + */ + public function setStorage(array &$storage) + { + $this->storage =& $storage; + + // Load dynamically existing session variables into object properties + foreach ($storage as $key => $value) { + $this->$key = $value; + } + } + + /** + * Get all session variables + * + * @access public + * @return array + */ + public function getAll() + { + $session = get_object_vars($this); + unset($session['storage']); + + return $session; + } + + /** + * Flush session data + * + * @access public + */ + public function flush() + { + $session = get_object_vars($this); + unset($session['storage']); + + foreach (array_keys($session) as $property) { + unset($this->$property); + } + } + + /** + * Copy class properties to external storage + * + * @access public + */ + public function __destruct() + { + $this->storage = $this->getAll(); + } +} |
