/** Initialize the session storage handler. Along with the parameters defined by weeSession::construct, another parameter "table" identify which table should be used to store sessions. @param $aParams A list of parameters to configure the session class. @see weeSession::__construct */ public function __construct($aParams = array()) { // We are required to include this class now in case it is needed // when this object gets destroyed at the end of the script. // Autoload does not work if the script is terminating, resulting in a fatal error. class_exists('DatabaseException'); session_set_save_handler(array($this, 'storageOpen'), array($this, 'storageClose'), array($this, 'storageRead'), array($this, 'storageWrite'), array($this, 'storageDestroy'), array($this, 'storageGarbageCollector')); empty($aParams['db']) || $aParams['db'] instanceof weeDatabase or burn('InvalidArgumentException', _WT('The optional "db" parameter must be an instance of weeDatabase.')); isset($aParams['table']) or burn('InvalidArgumentException', _WT('The required "table" parameter is missing.')); if (!empty($aParams['db'])) { $this->setDb($aParams['db']); } parent::__construct($aParams); }
<?php define('ALLOW_INCLUSION', 1); define('DEBUG', 1); define('ROOT_PATH', '../../../'); require ROOT_PATH . 'wee/wee.php'; $iStep = array_value($_GET, 'step', 1); try { $o = new weeSession(); $aArray = array(1, 2, 3, 'soleil'); if ($iStep == 1) { $o['test'] = 42; $o['array'] = $aArray; isset($o['test']) or burn('UnitTestException', _WT('The session value "test" was not found.')); isset($o['array']) or burn('UnitTestException', _WT('The session value "array" was not found.')); $o->setFromArray(array('answer' => 42)); isset($o['answer']) or burn('UnitTestException', _WT('The session value "answer" was not found.')); } elseif ($iStep == 2) { isset($o['test']) or burn('UnitTestException', _WT('The session value "test" was not found.')); isset($o['array']) or burn('UnitTestException', _WT('The session value "array" was not found.')); $o['test'] == 42 or burn('UnitTestException', _WT('The session value "test" is incorrect.')); $o['array'] == $aArray or burn('UnitTestException', _WT('The session value "array" is incorrect.')); isset($o['answer']) or burn('UnitTestException', _WT('The session value "answer" was not found.')); $o['answer'] == 42 or burn('UnitTestException', _WT('The session value "answer" is incorrect.')); // Prepare for next step $o['test'] = 'answer'; unset($o['array']); $o['test'] == 'answer' or burn('UnitTestException', _WT('The session value "test" is incorrect.')); isset($o['array']) and burn('UnitTestException', _WT('The session value "array" should not exist.')); } else { $o['test'] == 'answer' or burn('UnitTestException', _WT('The session value "test" is incorrect.'));
<?php define('ALLOW_INCLUSION', 1); define('DEBUG', 1); define('ROOT_PATH', '../../../'); require ROOT_PATH . 'wee/wee.php'; $iStep = array_value($_GET, 'step', 1); try { $o = new weeSession(); if ($iStep == 1) { $o['cleartest'] = 'not cleared'; isset($o['cleartest']) or burn('UnitTestException', _WT('The session value "cleartest" was not found.')); } elseif ($iStep == 2) { isset($o['cleartest']) or burn('UnitTestException', _WT('The session value "cleartest" was not found.')); $o->clear(); isset($o['cleartest']) and burn('UnitTestException', _WT('The session value "cleartest" should not have been found.')); } elseif ($iStep == 3) { isset($o['cleartest']) and burn('UnitTestException', _WT('The session value "cleartest" should not have been found.')); $o->clear(); $o['cleartest'] = 'not cleared'; isset($o['cleartest']) or burn('UnitTestException', _WT('The session value "cleartest" was not found.')); } else { isset($o['cleartest']) or burn('UnitTestException', _WT('The session value "cleartest" was not found.')); } } catch (Exception $e) { echo $e->getMessage(); exit; } echo 'success';