V 3.5 RC 1

This commit is contained in:
Romain Neutron
2011-12-05 00:23:28 +01:00
parent 6f1ee368aa
commit 4c5b7eb658
5563 changed files with 466984 additions and 985416 deletions

View File

@@ -0,0 +1,50 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package Session
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
abstract class Session_Storage_Abstract
{
/**
*
* @var boolean
*/
protected $open = true;
/**
*
* @return Session_Storage_Abstract
*/
public function close()
{
$this->open = false;
return $this;
}
/**
*
* @return Session_Storage_Abstract
*/
protected function require_open_storage()
{
if (!$this->open)
throw new Exception_Session_StorageClosed ();
return $this;
}
}

View File

@@ -0,0 +1,153 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package Session
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Session_Storage_CommandLine extends Session_Storage_Abstract implements Session_Storage_Interface
{
/**
*
* @var Session_Storage_CommandLine
*/
protected static $_instance;
/**
*
* @var string
*/
private static $_name = '';
/**
*
* @var Array
*/
private static $_cli_storage = array();
/**
*
* @param string $session_name
* @return Session_Storage_CommandLine
*/
public static function getInstance($session_name)
{
if (!self::$_instance)
{
self::$_instance = new self($session_name);
}
return self::$_instance;
}
/**
*
* @param string $name
* @return Session_Storage_CommandLine
*/
protected function __construct($name)
{
return $this;
}
/**
*
* @param string $key
* @return mixed
*/
public function get($key, $default_value = null)
{
return isset(self::$_cli_storage[self::$_name][$key]) ? self::$_cli_storage[self::$_name][$key] : $default_value;
}
/**
*
* @param string $key
* @return mixed
*/
public function has($key)
{
return isset(self::$_cli_storage[self::$_name][$key]);
}
/**
*
* @param string $key
* @param mixed $value
* @return boolean
*/
public function set($key, $value)
{
$this->require_open_storage();
return self::$_cli_storage[self::$_name][$key] = $value;
}
/**
*
* @param string $key
* @return boolean
*/
public function remove($key)
{
$retval = null;
$this->require_open_storage();
if (isset(self::$_cli_storage[self::$_name][$key]))
{
$retval = self::$_cli_storage[self::$_name][$key];
unset(self::$_cli_storage[self::$_name][$key]);
}
return $retval;
}
/**
* Return PHP session name
*
* @return string
*/
public function getName()
{
return 'commandLine';
}
/**
* Return PHP session Id
*
* @return string
*/
public function getId()
{
return 'commandLine';
}
public function reset()
{
self::$_cli_storage[self::$_name] = array();
return;
}
/**
*
* @return Void
*/
public function destroy()
{
unset(self::$_cli_storage[self::$_name]);
return;
}
}

View File

@@ -0,0 +1,54 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package Session
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
interface Session_Storage_Interface
{
/**
* Close the session storage
*
* @return Void
*/
public function close();
/**
* Return true if the storage contains the key
*
* @param string $key
* @return boolean
*/
public function has($key);
/**
* Set a key in the storage
*
* @param string $key
* @param mixed $default_value
*/
public function get($key, $default_value = null);
public function set($key, $value);
public function remove($key);
public function getName();
public function getId();
public function reset();
public function destroy();
}

View File

@@ -0,0 +1,164 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
* @package Session
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Session_Storage_PHPSession extends Session_Storage_Abstract implements Session_Storage_Interface
{
/**
*
* @var Session_Storage_PHPSession
*/
protected static $_instance;
/**
*
* @var string
*/
protected $name = 'PHPSESSID';
/**
*
* @param string $session_name
* @return Session_Storage_PHPSession
*/
public static function getInstance($session_name)
{
if (!self::$_instance)
{
self::$_instance = new self($session_name);
}
return self::$_instance;
}
/**
*
* @param string $session_name
* @return Session_Storage_PHPSession
*/
protected function __construct($session_name)
{
$this->name = $session_name;
$this->start();
return $this;
}
/**
*
* @return Session_Storage_PHPSession
*/
protected function start()
{
session_name($this->name);
session_start();
$this->open = true;
return $this;
}
/**
*
* @return Session_Storage_PHPSession
*/
public function close()
{
if ($this->open)
{
session_write_close();
}
parent::close();
return $this;
}
/**
*
* @param string $key
* @return mixed
*/
public function has($key)
{
return isset($_SESSION[$key]);
}
/**
*
* @param string $key
* @return mixed
*/
public function get($key, $default_value = null)
{
return isset($_SESSION[$key]) ? $_SESSION[$key] : $default_value;
}
public function set($key, $value)
{
$this->require_open_storage();
$_SESSION[$key] = $value;
return $this;
}
public function remove($key)
{
$this->require_open_storage();
if (isset($_SESSION[$key]))
unset($_SESSION[$key]);
return $this;
}
/**
* Return PHP session name
*
* @return string
*/
function getName()
{
return session_name();
}
/**
* Return PHP session Id
*
* @return <type>
*/
function getId()
{
return session_id();
}
public function reset()
{
$_SESSION = array();
return $this;
}
/**
*
* @return Void
*/
public function destroy()
{
session_destroy();
$this->open = false;
return;
}
}