Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Show file tree
Hide file tree
Showing 28 changed files with 740 additions and 554 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
"zendframework/zend-eventmanager": "Zend\\EventManager component",
"zendframework/zend-http": "Zend\\Http component",
"zendframework/zend-servicemanager": "Zend\\ServiceManager component",
"zendframework/zend-validator": "Zend\\Validator component",
"zendframework/zend-filter": "Zend\\Filter component"
"zendframework/zend-validator": "Zend\\Validator component"
},
"extra": {
"branch-alias": {
Expand Down
113 changes: 69 additions & 44 deletions src/AbstractManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Zend\Session;

use Zend\Session\Configuration\ConfigurationInterface as Configuration;
use Zend\Session\Config\ConfigInterface as Config;
use Zend\Session\ManagerInterface as Manager;
use Zend\Session\SaveHandler\SaveHandlerInterface as SaveHandler;
use Zend\Session\Storage\StorageInterface as Storage;
Expand All @@ -26,15 +26,15 @@
abstract class AbstractManager implements Manager
{
/**
* @var Configuration
* @var Config
*/
protected $config;

/**
* Default configuration class to use when no configuration provided
* @var string
*/
protected $configDefaultClass = 'Zend\\Session\\Configuration\\SessionConfiguration';
protected $defaultConfigClass = 'Zend\Session\Config\SessionConfig';

/**
* @var Storage
Expand All @@ -45,56 +45,89 @@ abstract class AbstractManager implements Manager
* Default storage class to use when no storage provided
* @var string
*/
protected $storageDefaultClass = 'Zend\\Session\\Storage\\SessionStorage';
protected $defaultStorageClass = 'Zend\Session\Storage\SessionStorage';

/**
* @var SaveHandler
*/
protected $saveHandler;


/**
* Constructor
*
* Allow passing a configuration object or class name, a storage object or
* class name, or an array of configuration.
*
* @param Configuration $config
* @param Storage $storage
* @param SaveHandler $saveHandler
* @return void
* @param Config|null $config
* @param Storage|null $storage
* @param SaveHandler|null $saveHandler
* @throws Exception\RuntimeException
*/
public function __construct(Configuration $config = null, Storage $storage = null, SaveHandler $saveHandler = null)
public function __construct(Config $config = null, Storage $storage = null, SaveHandler $saveHandler = null)
{
$this->setOptions($config);
$this->setStorage($storage);
if ($saveHandler) {
$this->setSaveHandler($saveHandler);
// init config
if ($config === null) {
if (!class_exists($this->defaultConfigClass)) {
throw new Exception\RuntimeException(sprintf(
'Unable to locate config class "%s"; class does not exist',
$this->defaultConfigClass
));
}

$config = new $this->defaultConfigClass();

if (!$config instanceof Config) {
throw new Exception\RuntimeException(sprintf(
'Default config class %s is invalid; must implement %s\Config\ConfigInterface',
$this->defaultConfigClass,
__NAMESPACE__
));
}
}

$this->config = $config;

// init storage
if ($storage === null) {
if (!class_exists($this->defaultStorageClass)) {
throw new Exception\RuntimeException(sprintf(
'Unable to locate storage class "%s"; class does not exist',
$this->defaultStorageClass
));
}

$storage = new $this->defaultStorageClass();

if (!$storage instanceof Storage) {
throw new Exception\RuntimeException(sprintf(
'Default storage class %s is invalid; must implement %s\Storage\StorageInterface',
$this->defaultConfigClass,
__NAMESPACE__
));
}
}

$this->storage = $storage;

// save handler
if ($saveHandler !== null) {
$this->saveHandler = $saveHandler;
}
}

/**
* Set configuration object
*
* @param null|Configuration $config
* @return void
* @param Config $config
* @return AbstractManager
*/
public function setOptions(Configuration $config = null)
public function setConfig(Config $config)
{
if (null === $config) {
$config = new $this->configDefaultClass();
if (!$config instanceof Configuration) {
throw new Exception\InvalidArgumentException('Default configuration type provided is invalid; must implement Zend\\Session\\Configuration');
}
}

$this->config = $config;
return $this;
}

/**
* Retrieve configuration object
*
* @return Configuration
* @return Config
*/
public function getConfig()
{
Expand All @@ -104,19 +137,13 @@ public function getConfig()
/**
* Set session storage object
*
* @param null|Storage $storage
* @return void
* @param Storage $storage
* @return AbstractManager
*/
public function setStorage(Storage $storage = null)
public function setStorage(Storage $storage)
{
if (null === $storage) {
$storage = new $this->storageDefaultClass();
if (!$storage instanceof Storage) {
throw new Exception\InvalidArgumentException('Default storage type provided is invalid; must implement Zend\\Session\\Storage');
}
}

$this->storage = $storage;
return $this;
}

/**
Expand All @@ -132,15 +159,13 @@ public function getStorage()
/**
* Set session save handler object
*
* @param SaveHandler $saveHandler
* @return void
* @param SaveHandler $saveHandler
* @return AbstractManager
*/
public function setSaveHandler(SaveHandler $saveHandler)
{
if ($saveHandler === null) {
return ;
}
$this->saveHandler = $saveHandler;
return $this;
}

/**
Expand All @@ -152,4 +177,4 @@ public function getSaveHandler()
{
return $this->saveHandler;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,49 @@
* @package Zend_Session
*/

namespace Zend\Session\Configuration;
namespace Zend\Session\Config;

/**
* Standard session configuration
*
* @category Zend
* @package Zend_Session
*/
interface ConfigurationInterface
interface ConfigInterface
{
public function setOptions(array $options);
public function setOptions($options);
public function getOptions();

public function setOption($option, $value);
public function hasOption($option);
public function getOption($option);
public function toArray();
public function hasOption($option);

public function setSavePath($savePath);
public function getSavePath();
public function toArray();

public function setName($name);
public function getName();

public function setSavePath($savePath);
public function getSavePath();

public function setCookieLifetime($cookieLifetime);
public function getCookieLifetime();

public function setCookiePath($cookiePath);
public function getCookiePath();

public function setCookieDomain($cookieDomain);
public function getCookieDomain();

public function setCookieSecure($cookieSecure);
public function getCookieSecure();

public function setCookieHttpOnly($cookieHttpOnly);
public function getCookieHttpOnly();

public function setUseCookies($useCookies);
public function getUseCookies();

public function setRememberMeSeconds($rememberMeSeconds);
public function getRememberMeSeconds();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @package Zend_Session
*/

namespace Zend\Session\Configuration;
namespace Zend\Session\Config;

use Zend\Session\Exception;
use Zend\Validator\Hostname as HostnameValidator;
Expand All @@ -20,7 +20,7 @@
* @package Zend_Session
* @subpackage Configuration
*/
class SessionConfiguration extends StandardConfiguration
class SessionConfig extends StandardConfig
{
/**
* Used with {@link handleError()}; stores PHP error code
Expand Down Expand Up @@ -107,8 +107,6 @@ public function setStorageOption($storageName, $storageValue)
*/
public function getStorageOption($storageOption)
{
$key = false;
$transform = false;
switch ($storageOption) {
case 'remember_me_seconds':
// No remote storage option; just return the current value
Expand All @@ -127,19 +125,6 @@ public function getStorageOption($storageOption)
}
}

/**
* Handle PHP errors
*
* @param int $code
* @param string $message
* @return void
*/
protected function handleError($code, $message)
{
$this->phpErrorCode = $code;
$this->phpErrorMessage = $message;
}

/**
* Set session.save_handler
*
Expand All @@ -154,7 +139,9 @@ public function setPhpSaveHandler($phpSaveHandler)
ini_set('session.save_handler', $phpSaveHandler);
restore_error_handler();
if ($this->phpErrorCode >= E_WARNING) {
throw new Exception\InvalidArgumentException('Invalid save handler specified');
throw new Exception\InvalidArgumentException(
'Invalid save handler specified: ' . $this->phpErrorMessage
);
}

$this->setOption('save_handler', $phpSaveHandler);
Expand Down Expand Up @@ -203,24 +190,6 @@ public function setCacheLimiter($cacheLimiter)
return $this;
}

/**
* Retrieve list of valid hash functions
*
* @return array
*/
protected function getHashFunctions()
{
if (empty($this->validHashFunctions)) {
/**
* @see http://php.net/manual/en/session.configuration.php#ini.session.hash-function
* "0" and "1" refer to MD5-128 and SHA1-160, respectively, and are
* valid in addition to whatever is reported by hash_algos()
*/
$this->validHashFunctions = array('0', '1') + hash_algos();
}
return $this->validHashFunctions;
}

/**
* Set session.hash_function
*
Expand Down Expand Up @@ -261,4 +230,35 @@ public function setHashBitsPerCharacter($hashBitsPerCharacter)
ini_set('session.hash_bits_per_character', $hashBitsPerCharacter);
return $this;
}

/**
* Retrieve list of valid hash functions
*
* @return array
*/
protected function getHashFunctions()
{
if (empty($this->validHashFunctions)) {
/**
* @link http://php.net/manual/en/session.configuration.php#ini.session.hash-function
* "0" and "1" refer to MD5-128 and SHA1-160, respectively, and are
* valid in addition to whatever is reported by hash_algos()
*/
$this->validHashFunctions = array('0', '1') + hash_algos();
}
return $this->validHashFunctions;
}

/**
* Handle PHP errors
*
* @param int $code
* @param string $message
* @return void
*/
protected function handleError($code, $message)
{
$this->phpErrorCode = $code;
$this->phpErrorMessage = $message;
}
}
Loading

0 comments on commit d904244

Please sign in to comment.