2014-01-23 12:09:48 +01:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
/**
|
|
|
|
* This file is part of Icinga Web 2.
|
|
|
|
*
|
|
|
|
* Icinga Web 2 - Head for multiple monitoring backends.
|
|
|
|
* Copyright (C) 2014 Icinga Development Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* @copyright 2014 Icinga Development Team <info@icinga.org>
|
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
|
|
|
* @author Icinga Development Team <info@icinga.org>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
2014-03-25 11:12:55 +01:00
|
|
|
namespace Icinga\Web\Session;
|
2014-01-23 14:40:59 +01:00
|
|
|
|
2014-01-23 12:09:48 +01:00
|
|
|
/**
|
|
|
|
* Base class for handling sessions
|
|
|
|
*/
|
2014-01-23 14:40:59 +01:00
|
|
|
abstract class Session extends SessionNamespace
|
2014-01-23 12:09:48 +01:00
|
|
|
{
|
|
|
|
/**
|
2014-01-23 14:40:59 +01:00
|
|
|
* Container for session namespaces
|
2014-01-23 12:09:48 +01:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2014-01-23 14:40:59 +01:00
|
|
|
protected $namespaces = array();
|
2014-01-23 12:09:48 +01:00
|
|
|
|
2014-04-04 11:10:45 +02:00
|
|
|
/**
|
|
|
|
* The identifiers of all namespaces removed from this session
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $removedNamespaces = array();
|
|
|
|
|
2014-01-23 12:09:48 +01:00
|
|
|
/**
|
|
|
|
* Read all values from the underlying session implementation
|
|
|
|
*/
|
|
|
|
abstract public function read();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Persists changes to the underlying session implementation
|
|
|
|
*/
|
|
|
|
abstract public function write();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Purge session
|
|
|
|
*/
|
|
|
|
abstract public function purge();
|
|
|
|
|
2014-02-26 19:23:34 +01:00
|
|
|
/**
|
|
|
|
* Assign a new session id to this session.
|
|
|
|
*/
|
|
|
|
abstract public function refreshId();
|
|
|
|
|
2014-01-23 12:09:48 +01:00
|
|
|
/**
|
2014-01-23 14:40:59 +01:00
|
|
|
* Get or create a new session namespace
|
2014-01-23 12:09:48 +01:00
|
|
|
*
|
2014-01-23 14:40:59 +01:00
|
|
|
* @param string $identifier The namespace's identifier
|
2014-01-23 12:09:48 +01:00
|
|
|
*
|
2014-01-23 14:40:59 +01:00
|
|
|
* @return SessionNamespace
|
2014-01-23 12:09:48 +01:00
|
|
|
*/
|
2014-01-23 14:40:59 +01:00
|
|
|
public function getNamespace($identifier)
|
2014-01-23 12:09:48 +01:00
|
|
|
{
|
2014-01-23 14:40:59 +01:00
|
|
|
if (!isset($this->namespaces[$identifier])) {
|
2014-04-04 11:10:45 +02:00
|
|
|
if (in_array($identifier, $this->removedNamespaces)) {
|
|
|
|
unset($this->removedNamespaces[array_search($identifier, $this->removedNamespaces)]);
|
|
|
|
}
|
|
|
|
|
2014-01-23 14:40:59 +01:00
|
|
|
$this->namespaces[$identifier] = new SessionNamespace();
|
2014-01-23 12:09:48 +01:00
|
|
|
}
|
|
|
|
|
2014-01-23 14:40:59 +01:00
|
|
|
return $this->namespaces[$identifier];
|
2014-01-23 12:09:48 +01:00
|
|
|
}
|
|
|
|
|
2014-03-25 10:31:52 +01:00
|
|
|
/**
|
|
|
|
* Return whether the given session namespace exists
|
|
|
|
*
|
|
|
|
* @param string $identifier The namespace's identifier to check
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasNamespace($identifier)
|
|
|
|
{
|
|
|
|
return isset($this->namespaces[$identifier]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the given session namespace
|
|
|
|
*
|
|
|
|
* @param string $identifier The identifier of the namespace to remove
|
|
|
|
*/
|
|
|
|
public function removeNamespace($identifier)
|
|
|
|
{
|
|
|
|
unset($this->namespaces[$identifier]);
|
2014-04-04 11:10:45 +02:00
|
|
|
$this->removedNamespaces[] = $identifier;
|
2014-03-25 10:31:52 +01:00
|
|
|
}
|
|
|
|
|
2014-01-23 12:09:48 +01:00
|
|
|
/**
|
2014-01-23 14:40:59 +01:00
|
|
|
* Clear all values and namespaces from the session cache
|
2014-01-23 12:09:48 +01:00
|
|
|
*/
|
|
|
|
public function clear()
|
|
|
|
{
|
2014-01-23 14:40:59 +01:00
|
|
|
$this->values = array();
|
2014-04-04 11:10:45 +02:00
|
|
|
$this->removed = array();
|
2014-01-23 14:40:59 +01:00
|
|
|
$this->namespaces = array();
|
2014-04-04 11:10:45 +02:00
|
|
|
$this->removedNamespaces = array();
|
2014-01-23 12:09:48 +01:00
|
|
|
}
|
|
|
|
}
|