diff options
Diffstat (limited to '')
-rw-r--r-- | library/vendor/Zend/Session.php | 895 | ||||
-rw-r--r-- | library/vendor/Zend/Session/Abstract.php | 182 | ||||
-rw-r--r-- | library/vendor/Zend/Session/Exception.php | 73 | ||||
-rw-r--r-- | library/vendor/Zend/Session/Namespace.php | 511 | ||||
-rw-r--r-- | library/vendor/Zend/Session/SaveHandler/DbTable.php | 579 | ||||
-rw-r--r-- | library/vendor/Zend/Session/SaveHandler/Exception.php | 36 | ||||
-rw-r--r-- | library/vendor/Zend/Session/SaveHandler/Interface.php | 81 | ||||
-rw-r--r-- | library/vendor/Zend/Session/Validator/Abstract.php | 70 | ||||
-rw-r--r-- | library/vendor/Zend/Session/Validator/Exception.php | 42 | ||||
-rw-r--r-- | library/vendor/Zend/Session/Validator/HttpUserAgent.php | 65 | ||||
-rw-r--r-- | library/vendor/Zend/Session/Validator/Interface.php | 52 |
11 files changed, 2586 insertions, 0 deletions
diff --git a/library/vendor/Zend/Session.php b/library/vendor/Zend/Session.php new file mode 100644 index 0000000..a1ed797 --- /dev/null +++ b/library/vendor/Zend/Session.php @@ -0,0 +1,895 @@ +<?php + +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Session + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + * @since Preview Release 0.2 + */ + + +/** + * @see Zend_Session_Abstract + */ + +/** + * @see Zend_Session_Namespace + */ + +/** + * @see Zend_Session_SaveHandler_Interface + */ + + +/** + * Zend_Session + * + * @category Zend + * @package Zend_Session + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Session extends Zend_Session_Abstract +{ + /** + * Whether or not Zend_Session is being used with unit tests + * + * @internal + * @var bool + */ + public static $_unitTestEnabled = false; + + /** + * $_throwStartupException + * + * @var bool|bitset This could also be a combiniation of error codes to catch + */ + protected static $_throwStartupExceptions = true; + + /** + * Check whether or not the session was started + * + * @var bool + */ + private static $_sessionStarted = false; + + /** + * Whether or not the session id has been regenerated this request. + * + * Id regeneration state + * <0 - regenerate requested when session is started + * 0 - do nothing + * >0 - already called session_regenerate_id() + * + * @var int + */ + private static $_regenerateIdState = 0; + + /** + * Private list of php's ini values for ext/session + * null values will default to the php.ini value, otherwise + * the value below will overwrite the default ini value, unless + * the user has set an option explicity with setOptions() + * + * @var array + */ + private static $_defaultOptions = array( + 'save_path' => null, + 'name' => null, /* this should be set to a unique value for each application */ + 'save_handler' => null, + //'auto_start' => null, /* intentionally excluded (see manual) */ + 'gc_probability' => null, + 'gc_divisor' => null, + 'gc_maxlifetime' => null, + 'serialize_handler' => null, + 'cookie_lifetime' => null, + 'cookie_path' => null, + 'cookie_domain' => null, + 'cookie_secure' => null, + 'cookie_httponly' => null, + 'use_cookies' => null, + 'use_only_cookies' => 'on', + 'referer_check' => null, + 'entropy_file' => null, + 'entropy_length' => null, + 'cache_limiter' => null, + 'cache_expire' => null, + 'use_trans_sid' => null, + 'bug_compat_42' => null, + 'bug_compat_warn' => null, + 'hash_function' => null, + 'hash_bits_per_character' => null + ); + + /** + * List of options pertaining to Zend_Session that can be set by developers + * using Zend_Session::setOptions(). This list intentionally duplicates + * the individual declaration of static "class" variables by the same names. + * + * @var array + */ + private static $_localOptions = array( + 'strict' => '_strict', + 'remember_me_seconds' => '_rememberMeSeconds', + 'throw_startup_exceptions' => '_throwStartupExceptions' + ); + + /** + * Whether or not write close has been performed. + * + * @var bool + */ + private static $_writeClosed = false; + + /** + * Whether or not session id cookie has been deleted + * + * @var bool + */ + private static $_sessionCookieDeleted = false; + + /** + * Whether or not session has been destroyed via session_destroy() + * + * @var bool + */ + private static $_destroyed = false; + + /** + * Whether or not session must be initiated before usage + * + * @var bool + */ + private static $_strict = false; + + /** + * Default number of seconds the session will be remembered for when asked to be remembered + * + * @var int + */ + private static $_rememberMeSeconds = 1209600; // 2 weeks + + /** + * Whether the default options listed in Zend_Session::$_localOptions have been set + * + * @var bool + */ + private static $_defaultOptionsSet = false; + + /** + * A reference to the set session save handler + * + * @var Zend_Session_SaveHandler_Interface + */ + private static $_saveHandler = null; + + + /** + * Constructor overriding - make sure that a developer cannot instantiate + */ + protected function __construct() + { + } + + + /** + * setOptions - set both the class specified + * + * @param array $userOptions - pass-by-keyword style array of <option name, option value> pairs + * @throws Zend_Session_Exception + * @return void + */ + public static function setOptions(array $userOptions = array()) + { + // set default options on first run only (before applying user settings) + if (!self::$_defaultOptionsSet) { + foreach (self::$_defaultOptions as $defaultOptionName => $defaultOptionValue) { + if (isset(self::$_defaultOptions[$defaultOptionName])) { + ini_set("session.$defaultOptionName", $defaultOptionValue); + } + } + + self::$_defaultOptionsSet = true; + } + + // set the options the user has requested to set + foreach ($userOptions as $userOptionName => $userOptionValue) { + + $userOptionName = strtolower($userOptionName); + + // set the ini based values + if (array_key_exists($userOptionName, self::$_defaultOptions)) { + ini_set("session.$userOptionName", $userOptionValue); + } + elseif (isset(self::$_localOptions[$userOptionName])) { + self::${self::$_localOptions[$userOptionName]} = $userOptionValue; + } + else { + /** @see Zend_Session_Exception */ + throw new Zend_Session_Exception("Unknown option: $userOptionName = $userOptionValue"); + } + } + } + + /** + * getOptions() + * + * @param string $optionName OPTIONAL + * @return array|string + */ + public static function getOptions($optionName = null) + { + $options = array(); + foreach (ini_get_all('session') as $sysOptionName => $sysOptionValues) { + $options[substr($sysOptionName, 8)] = $sysOptionValues['local_value']; + } + foreach (self::$_localOptions as $localOptionName => $localOptionMemberName) { + $options[$localOptionName] = self::${$localOptionMemberName}; + } + + if ($optionName) { + if (array_key_exists($optionName, $options)) { + return $options[$optionName]; + } + return null; + } + + return $options; + } + + /** + * setSaveHandler() - Session Save Handler assignment + * + * @param Zend_Session_SaveHandler_Interface $interface + * @throws Zend_Session_Exception When the session_set_save_handler call fails + * @return void + */ + public static function setSaveHandler(Zend_Session_SaveHandler_Interface $saveHandler) + { + self::$_saveHandler = $saveHandler; + + if (self::$_unitTestEnabled) { + return; + } + + $result = session_set_save_handler( + array(&$saveHandler, 'open'), + array(&$saveHandler, 'close'), + array(&$saveHandler, 'read'), + array(&$saveHandler, 'write'), + array(&$saveHandler, 'destroy'), + array(&$saveHandler, 'gc') + ); + + if (!$result) { + throw new Zend_Session_Exception('Unable to set session handler'); + } + } + + + /** + * getSaveHandler() - Get the session Save Handler + * + * @return Zend_Session_SaveHandler_Interface + */ + public static function getSaveHandler() + { + return self::$_saveHandler; + } + + + /** + * regenerateId() - Regenerate the session id. Best practice is to call this after + * session is started. If called prior to session starting, session id will be regenerated + * at start time. + * + * @throws Zend_Session_Exception + * @return void + */ + public static function regenerateId() + { + if (!self::$_unitTestEnabled && headers_sent($filename, $linenum)) { + /** @see Zend_Session_Exception */ + throw new Zend_Session_Exception("You must call " . __CLASS__ . '::' . __FUNCTION__ . + "() before any output has been sent to the browser; output started in {$filename}/{$linenum}"); + } + + if ( !self::$_sessionStarted ) { + self::$_regenerateIdState = -1; + } else { + if (!self::$_unitTestEnabled) { + session_regenerate_id(true); + } + self::$_regenerateIdState = 1; + } + } + + + /** + * rememberMe() - Write a persistent cookie that expires after a number of seconds in the future. If no number of + * seconds is specified, then this defaults to self::$_rememberMeSeconds. Due to clock errors on end users' systems, + * large values are recommended to avoid undesirable expiration of session cookies. + * + * @param int $seconds OPTIONAL specifies TTL for cookie in seconds from present time + * @return void + */ + public static function rememberMe($seconds = null) + { + $seconds = (int) $seconds; + $seconds = ($seconds > 0) ? $seconds : self::$_rememberMeSeconds; + + self::rememberUntil($seconds); + } + + + /** + * forgetMe() - Write a volatile session cookie, removing any persistent cookie that may have existed. The session + * would end upon, for example, termination of a web browser program. + * + * @return void + */ + public static function forgetMe() + { + self::rememberUntil(0); + } + + + /** + * rememberUntil() - This method does the work of changing the state of the session cookie and making + * sure that it gets resent to the browser via regenerateId() + * + * @param int $seconds + * @return void + */ + public static function rememberUntil($seconds = 0) + { + if (self::$_unitTestEnabled) { + self::regenerateId(); + return; + } + + $cookieParams = session_get_cookie_params(); + + session_set_cookie_params( + $seconds, + $cookieParams['path'], + $cookieParams['domain'], + $cookieParams['secure'] + ); + + // normally "rememberMe()" represents a security context change, so should use new session id + self::regenerateId(); + } + + + /** + * sessionExists() - whether or not a session exists for the current request + * + * @return bool + */ + public static function sessionExists() + { + if ((bool)ini_get('session.use_cookies') == true && isset($_COOKIE[session_name()])) { + return true; + } elseif ((bool)ini_get('session.use_only_cookies') == false && isset($_REQUEST[session_name()])) { + return true; + } elseif (self::$_unitTestEnabled) { + return true; + } + + return false; + } + + + /** + * Whether or not session has been destroyed via session_destroy() + * + * @return bool + */ + public static function isDestroyed() + { + return self::$_destroyed; + } + + + /** + * start() - Start the session. + * + * @param bool|array $options OPTIONAL Either user supplied options, or flag indicating if start initiated automatically + * @throws Zend_Session_Exception + * @return void + */ + public static function start($options = false) + { + // Check to see if we've been passed an invalid session ID + if ( self::getId() && !self::_checkId(self::getId()) ) { + // Generate a valid, temporary replacement + self::setId(md5(self::getId())); + // Force a regenerate after session is started + self::$_regenerateIdState = -1; + } + + if (self::$_sessionStarted && self::$_destroyed) { + throw new Zend_Session_Exception('The session was explicitly destroyed during this request, attempting to re-start is not allowed.'); + } + + if (self::$_sessionStarted) { + return; // already started + } + + // make sure our default options (at the least) have been set + if (!self::$_defaultOptionsSet) { + self::setOptions(is_array($options) ? $options : array()); + } + + // In strict mode, do not allow auto-starting Zend_Session, such as via "new Zend_Session_Namespace()" + if (self::$_strict && $options === true) { + /** @see Zend_Session_Exception */ + throw new Zend_Session_Exception('You must explicitly start the session with Zend_Session::start() when session options are set to strict.'); + } + + $filename = $linenum = null; + if (!self::$_unitTestEnabled && headers_sent($filename, $linenum)) { + /** @see Zend_Session_Exception */ + throw new Zend_Session_Exception("Session must be started before any output has been sent to the browser;" + . " output started in {$filename}/{$linenum}"); + } + + // See http://www.php.net/manual/en/ref.session.php for explanation + if (!self::$_unitTestEnabled && defined('SID')) { + /** @see Zend_Session_Exception */ + throw new Zend_Session_Exception('session has already been started by session.auto-start or session_start()'); + } + + /** + * Hack to throw exceptions on start instead of php errors + * @see http://framework.zend.com/issues/browse/ZF-1325 + */ + + $errorLevel = (is_int(self::$_throwStartupExceptions)) ? self::$_throwStartupExceptions : E_ALL; + + /** @see Zend_Session_Exception */ + if (!self::$_unitTestEnabled) { + + if (self::$_throwStartupExceptions) { + set_error_handler(array('Zend_Session_Exception', 'handleSessionStartError'), $errorLevel); + } + + $startedCleanly = session_start(); + + if (self::$_throwStartupExceptions) { + restore_error_handler(); + } + + if (!$startedCleanly || Zend_Session_Exception::$sessionStartError != null) { + if (self::$_throwStartupExceptions) { + set_error_handler(array('Zend_Session_Exception', 'handleSilentWriteClose'), $errorLevel); + } + session_write_close(); + if (self::$_throwStartupExceptions) { + restore_error_handler(); + throw new Zend_Session_Exception(__CLASS__ . '::' . __FUNCTION__ . '() - ' . Zend_Session_Exception::$sessionStartError); + } + } + } + + parent::$_readable = true; + parent::$_writable = true; + self::$_sessionStarted = true; + if (self::$_regenerateIdState === -1) { + self::regenerateId(); + } + + // run validators if they exist + if (isset($_SESSION['__ZF']['VALID'])) { + self::_processValidators(); + } + + self::_processStartupMetadataGlobal(); + } + + /** + * Perform a hash-bits check on the session ID + * + * @param string $id Session ID + * @return bool + */ + protected static function _checkId($id) + { + $saveHandler = ini_get('session.save_handler'); + if ($saveHandler == 'cluster') { // Zend Server SC, validate only after last dash + $dashPos = strrpos($id, '-'); + if ($dashPos) { + $id = substr($id, $dashPos + 1); + } + } + + $hashBitsPerChar = ini_get('session.hash_bits_per_character'); + if (!$hashBitsPerChar) { + $hashBitsPerChar = 5; // the default value + } + switch($hashBitsPerChar) { + case 4: $pattern = '^[0-9a-f]*$'; break; + case 5: $pattern = '^[0-9a-v]*$'; break; + case 6: $pattern = '^[0-9a-zA-Z-,]*$'; break; + } + return preg_match('#'.$pattern.'#', $id); + } + + + /** + * _processGlobalMetadata() - this method initizes the sessions GLOBAL + * metadata, mostly global data expiration calculations. + * + * @return void + */ + private static function _processStartupMetadataGlobal() + { + // process global metadata + if (isset($_SESSION['__ZF'])) { + + // expire globally expired values + foreach ($_SESSION['__ZF'] as $namespace => $namespace_metadata) { + + // Expire Namespace by Time (ENT) + if (isset($namespace_metadata['ENT']) && ($namespace_metadata['ENT'] > 0) && (time() > $namespace_metadata['ENT']) ) { + unset($_SESSION[$namespace]); + unset($_SESSION['__ZF'][$namespace]); + } + + // Expire Namespace by Global Hop (ENGH) if it wasnt expired above + if (isset($_SESSION['__ZF'][$namespace]) && isset($namespace_metadata['ENGH']) && $namespace_metadata['ENGH'] >= 1) { + + $_SESSION['__ZF'][$namespace]['ENGH']--; + + if ($_SESSION['__ZF'][$namespace]['ENGH'] === 0) { + if (isset($_SESSION[$namespace])) { + parent::$_expiringData[$namespace] = $_SESSION[$namespace]; + unset($_SESSION[$namespace]); + } + unset($_SESSION['__ZF'][$namespace]); + } + } + + // Expire Namespace Variables by Time (ENVT) + if (isset($namespace_metadata['ENVT'])) { + foreach ($namespace_metadata['ENVT'] as $variable => $time) { + if (time() > $time) { + unset($_SESSION[$namespace][$variable]); + unset($_SESSION['__ZF'][$namespace]['ENVT'][$variable]); + } + } + if (empty($_SESSION['__ZF'][$namespace]['ENVT'])) { + unset($_SESSION['__ZF'][$namespace]['ENVT']); + } + } + + // Expire Namespace Variables by Global Hop (ENVGH) + if (isset($namespace_metadata['ENVGH'])) { + foreach ($namespace_metadata['ENVGH'] as $variable => $hops) { + $_SESSION['__ZF'][$namespace]['ENVGH'][$variable]--; + + if ($_SESSION['__ZF'][$namespace]['ENVGH'][$variable] === 0) { + if (isset($_SESSION[$namespace][$variable])) { + parent::$_expiringData[$namespace][$variable] = $_SESSION[$namespace][$variable]; + unset($_SESSION[$namespace][$variable]); + } + unset($_SESSION['__ZF'][$namespace]['ENVGH'][$variable]); + } + } + if (empty($_SESSION['__ZF'][$namespace]['ENVGH'])) { + unset($_SESSION['__ZF'][$namespace]['ENVGH']); + } + } + + if (isset($namespace) && empty($_SESSION['__ZF'][$namespace])) { + unset($_SESSION['__ZF'][$namespace]); + } + } + } + + if (isset($_SESSION['__ZF']) && empty($_SESSION['__ZF'])) { + unset($_SESSION['__ZF']); + } + } + + + /** + * isStarted() - convenience method to determine if the session is already started. + * + * @return bool + */ + public static function isStarted() + { + return self::$_sessionStarted; + } + + + /** + * isRegenerated() - convenience method to determine if session_regenerate_id() + * has been called during this request by Zend_Session. + * + * @return bool + */ + public static function isRegenerated() + { + return ( (self::$_regenerateIdState > 0) ? true : false ); + } + + + /** + * getId() - get the current session id + * + * @return string + */ + public static function getId() + { + return session_id(); + } + + + /** + * setId() - set an id to a user specified id + * + * @throws Zend_Session_Exception + * @param string $id + * @return void + */ + public static function setId($id) + { + if (!self::$_unitTestEnabled && defined('SID')) { + /** @see Zend_Session_Exception */ + throw new Zend_Session_Exception('The session has already been started. The session id must be set first.'); + } + + if (!self::$_unitTestEnabled && headers_sent($filename, $linenum)) { + /** @see Zend_Session_Exception */ + throw new Zend_Session_Exception("You must call ".__CLASS__.'::'.__FUNCTION__. + "() before any output has been sent to the browser; output started in {$filename}/{$linenum}"); + } + + if (!is_string($id) || $id === '') { + /** @see Zend_Session_Exception */ + throw new Zend_Session_Exception('You must provide a non-empty string as a session identifier.'); + } + + session_id($id); + } + + + /** + * registerValidator() - register a validator that will attempt to validate this session for + * every future request + * + * @param Zend_Session_Validator_Interface $validator + * @return void + */ + public static function registerValidator(Zend_Session_Validator_Interface $validator) + { + $validator->setup(); + } + + + /** + * stop() - Disable write access. Optionally disable read (not implemented). + * + * @return void + */ + public static function stop() + { + parent::$_writable = false; + } + + + /** + * writeClose() - Shutdown the sesssion, close writing and detach $_SESSION from the back-end storage mechanism. + * This will complete the internal data transformation on this request. + * + * @param bool $readonly - OPTIONAL remove write access (i.e. throw error if Zend_Session's attempt writes) + * @return void + */ + public static function writeClose($readonly = true) + { + if (self::$_unitTestEnabled) { + return; + } + + if (self::$_writeClosed) { + return; + } + + if ($readonly) { + parent::$_writable = false; + } + + session_write_close(); + self::$_writeClosed = true; + } + + + /** + * destroy() - This is used to destroy session data, and optionally, the session cookie itself + * + * @param bool $remove_cookie - OPTIONAL remove session id cookie, defaults to true (remove cookie) + * @param bool $readonly - OPTIONAL remove write access (i.e. throw error if Zend_Session's attempt writes) + * @return void + */ + public static function destroy($remove_cookie = true, $readonly = true) + { + if (self::$_unitTestEnabled) { + return; + } + + if (self::$_destroyed) { + return; + } + + if ($readonly) { + parent::$_writable = false; + } + + session_destroy(); + self::$_destroyed = true; + + if ($remove_cookie) { + self::expireSessionCookie(); + } + } + + + /** + * expireSessionCookie() - Sends an expired session id cookie, causing the client to delete the session cookie + * + * @return void + */ + public static function expireSessionCookie() + { + if (self::$_unitTestEnabled) { + return; + } + + if (self::$_sessionCookieDeleted) { + return; + } + + self::$_sessionCookieDeleted = true; + + if (isset($_COOKIE[session_name()])) { + $cookie_params = session_get_cookie_params(); + + setcookie( + session_name(), + false, + 315554400, // strtotime('1980-01-01'), + $cookie_params['path'], + $cookie_params['domain'], + $cookie_params['secure'] + ); + } + } + + + /** + * _processValidator() - internal function that is called in the existence of VALID metadata + * + * @throws Zend_Session_Exception + * @return void + */ + private static function _processValidators() + { + foreach ($_SESSION['__ZF']['VALID'] as $validator_name => $valid_data) { + if (!class_exists($validator_name)) { + Zend_Loader::loadClass($validator_name); + } + $validator = new $validator_name; + if ($validator->validate() === false) { + /** @see Zend_Session_Validator_Exception */ + throw new Zend_Session_Validator_Exception("This session is not valid according to {$validator_name}."); + } + } + } + + + /** + * namespaceIsset() - check to see if a namespace is set + * + * @param string $namespace + * @return bool + */ + public static function namespaceIsset($namespace) + { + return parent::_namespaceIsset($namespace); + } + + + /** + * namespaceUnset() - unset a namespace or a variable within a namespace + * + * @param string $namespace + * @throws Zend_Session_Exception + * @return void + */ + public static function namespaceUnset($namespace) + { + parent::_namespaceUnset($namespace); + Zend_Session_Namespace::resetSingleInstance($namespace); + } + + + /** + * namespaceGet() - get all variables in a namespace + * Deprecated: Use getIterator() in Zend_Session_Namespace. + * + * @param string $namespace + * @return array + */ + public static function namespaceGet($namespace) + { + return parent::_namespaceGetAll($namespace); + } + + + /** + * getIterator() - return an iteratable object for use in foreach and the like, + * this completes the IteratorAggregate interface + * + * @throws Zend_Session_Exception + * @return ArrayObject + */ + public static function getIterator() + { + if (parent::$_readable === false) { + /** @see Zend_Session_Exception */ + throw new Zend_Session_Exception(parent::_THROW_NOT_READABLE_MSG); + } + + $spaces = array(); + if (isset($_SESSION)) { + $spaces = array_keys($_SESSION); + foreach($spaces as $key => $space) { + if (!strncmp($space, '__', 2) || !is_array($_SESSION[$space])) { + unset($spaces[$key]); + } + } + } + + return new ArrayObject(array_merge($spaces, array_keys(parent::$_expiringData))); + } + + + /** + * isWritable() - returns a boolean indicating if namespaces can write (use setters) + * + * @return bool + */ + public static function isWritable() + { + return parent::$_writable; + } + + + /** + * isReadable() - returns a boolean indicating if namespaces can write (use setters) + * + * @return bool + */ + public static function isReadable() + { + return parent::$_readable; + } + +} diff --git a/library/vendor/Zend/Session/Abstract.php b/library/vendor/Zend/Session/Abstract.php new file mode 100644 index 0000000..15ffde0 --- /dev/null +++ b/library/vendor/Zend/Session/Abstract.php @@ -0,0 +1,182 @@ +<?php + +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Session + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + * @since Preview Release 0.2 + */ + + +/** + * Zend_Session_Abstract + * + * @category Zend + * @package Zend_Session + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +abstract class Zend_Session_Abstract +{ + /** + * Whether or not session permits writing (modification of $_SESSION[]) + * + * @var bool + */ + protected static $_writable = false; + + /** + * Whether or not session permits reading (reading data in $_SESSION[]) + * + * @var bool + */ + protected static $_readable = false; + + /** + * Since expiring data is handled at startup to avoid __destruct difficulties, + * the data that will be expiring at end of this request is held here + * + * @var array + */ + protected static $_expiringData = array(); + + + /** + * Error message thrown when an action requires modification, + * but current Zend_Session has been marked as read-only. + */ + const _THROW_NOT_WRITABLE_MSG = 'Zend_Session is currently marked as read-only.'; + + + /** + * Error message thrown when an action requires reading session data, + * but current Zend_Session is not marked as readable. + */ + const _THROW_NOT_READABLE_MSG = 'Zend_Session is not marked as readable.'; + + + /** + * namespaceIsset() - check to see if a namespace or a variable within a namespace is set + * + * @param string $namespace + * @param string $name + * @return bool + */ + protected static function _namespaceIsset($namespace, $name = null) + { + if (self::$_readable === false) { + /** + * @see Zend_Session_Exception + */ + throw new Zend_Session_Exception(self::_THROW_NOT_READABLE_MSG); + } + + if ($name === null) { + return ( isset($_SESSION[$namespace]) || isset(self::$_expiringData[$namespace]) ); + } else { + return ( isset($_SESSION[$namespace][$name]) || isset(self::$_expiringData[$namespace][$name]) ); + } + } + + + /** + * namespaceUnset() - unset a namespace or a variable within a namespace + * + * @param string $namespace + * @param string $name + * @throws Zend_Session_Exception + * @return void + */ + protected static function _namespaceUnset($namespace, $name = null) + { + if (self::$_writable === false) { + /** + * @see Zend_Session_Exception + */ + throw new Zend_Session_Exception(self::_THROW_NOT_WRITABLE_MSG); + } + + $name = (string) $name; + + // check to see if the api wanted to remove a var from a namespace or a namespace + if ($name === '') { + unset($_SESSION[$namespace]); + unset(self::$_expiringData[$namespace]); + } else { + unset($_SESSION[$namespace][$name]); + unset(self::$_expiringData[$namespace][$name]); + } + + // if we remove the last value, remove namespace. + if (empty($_SESSION[$namespace])) { + unset($_SESSION[$namespace]); + } + } + + + /** + * namespaceGet() - Get $name variable from $namespace, returning by reference. + * + * @param string $namespace + * @param string $name + * @return mixed + */ + protected static function & _namespaceGet($namespace, $name = null) + { + if (self::$_readable === false) { + /** + * @see Zend_Session_Exception + */ + throw new Zend_Session_Exception(self::_THROW_NOT_READABLE_MSG); + } + + if ($name === null) { + if (isset($_SESSION[$namespace])) { // check session first for data requested + return $_SESSION[$namespace]; + } elseif (isset(self::$_expiringData[$namespace])) { // check expiring data for data reqeusted + return self::$_expiringData[$namespace]; + } else { + return $_SESSION[$namespace]; // satisfy return by reference + } + } else { + if (isset($_SESSION[$namespace][$name])) { // check session first + return $_SESSION[$namespace][$name]; + } elseif (isset(self::$_expiringData[$namespace][$name])) { // check expiring data + return self::$_expiringData[$namespace][$name]; + } else { + return $_SESSION[$namespace][$name]; // satisfy return by reference + } + } + } + + + /** + * namespaceGetAll() - Get an array containing $namespace, including expiring data. + * + * @param string $namespace + * @param string $name + * @return mixed + */ + protected static function _namespaceGetAll($namespace) + { + $currentData = (isset($_SESSION[$namespace]) && is_array($_SESSION[$namespace])) ? + $_SESSION[$namespace] : array(); + $expiringData = (isset(self::$_expiringData[$namespace]) && is_array(self::$_expiringData[$namespace])) ? + self::$_expiringData[$namespace] : array(); + return array_merge($currentData, $expiringData); + } +} diff --git a/library/vendor/Zend/Session/Exception.php b/library/vendor/Zend/Session/Exception.php new file mode 100644 index 0000000..52672ec --- /dev/null +++ b/library/vendor/Zend/Session/Exception.php @@ -0,0 +1,73 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Session + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + * @since Preview Release 0.2 + */ + + +/** + * @see Zend_Exception + */ + + +/** + * Zend_Session_Exception + * + * @category Zend + * @package Zend_Session + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Session_Exception extends Zend_Exception +{ + /** + * sessionStartError + * + * @see http://framework.zend.com/issues/browse/ZF-1325 + * @var string PHP Error Message + */ + static public $sessionStartError = null; + + /** + * handleSessionStartError() - interface for set_error_handler() + * + * @see http://framework.zend.com/issues/browse/ZF-1325 + * @param int $errno + * @param string $errstr + * @return void + */ + static public function handleSessionStartError($errno, $errstr, $errfile, $errline, $errcontext) + { + self::$sessionStartError = $errfile . '(Line:' . $errline . '): Error #' . $errno . ' ' . $errstr; + } + + /** + * handleSilentWriteClose() - interface for set_error_handler() + * + * @see http://framework.zend.com/issues/browse/ZF-1325 + * @param int $errno + * @param string $errstr + * @return void + */ + static public function handleSilentWriteClose($errno, $errstr, $errfile, $errline, $errcontext) + { + self::$sessionStartError .= PHP_EOL . $errfile . '(Line:' . $errline . '): Error #' . $errno . ' ' . $errstr; + } +} + diff --git a/library/vendor/Zend/Session/Namespace.php b/library/vendor/Zend/Session/Namespace.php new file mode 100644 index 0000000..52d7945 --- /dev/null +++ b/library/vendor/Zend/Session/Namespace.php @@ -0,0 +1,511 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Session + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + * @since Preview Release 0.2 + */ + + +/** + * @see Zend_Session + */ + + +/** + * @see Zend_Session_Abstract + */ + + +/** + * Zend_Session_Namespace + * + * @category Zend + * @package Zend_Session + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Session_Namespace extends Zend_Session_Abstract implements IteratorAggregate +{ + + /** + * used as option to constructor to prevent additional instances to the same namespace + */ + const SINGLE_INSTANCE = true; + + /** + * Namespace - which namespace this instance of zend-session is saving-to/getting-from + * + * @var string + */ + protected $_namespace = "Default"; + + /** + * Namespace locking mechanism + * + * @var array + */ + protected static $_namespaceLocks = array(); + + /** + * Single instance namespace array to ensure data security. + * + * @var array + */ + protected static $_singleInstances = array(); + + /** + * resetSingleInstance() + * + * @param string $namespaceName + * @return null + */ + public static function resetSingleInstance($namespaceName = null) + { + if ($namespaceName != null) { + if (array_key_exists($namespaceName, self::$_singleInstances)) { + unset(self::$_singleInstances[$namespaceName]); + } + return; + } + + self::$_singleInstances = array(); + return; + } + + /** + * __construct() - Returns an instance object bound to a particular, isolated section + * of the session, identified by $namespace name (defaulting to 'Default'). + * The optional argument $singleInstance will prevent construction of additional + * instance objects acting as accessors to this $namespace. + * + * @param string $namespace - programmatic name of the requested namespace + * @param bool $singleInstance - prevent creation of additional accessor instance objects for this namespace + * @return void + */ + public function __construct($namespace = 'Default', $singleInstance = false) + { + if ($namespace === '') { + /** + * @see Zend_Session_Exception + */ + throw new Zend_Session_Exception('Session namespace must be a non-empty string.'); + } + + if ($namespace[0] == "_") { + /** + * @see Zend_Session_Exception + */ + throw new Zend_Session_Exception('Session namespace must not start with an underscore.'); + } + + if (preg_match('#(^[0-9])#i', $namespace[0])) { + /** + * @see Zend_Session_Exception + */ + throw new Zend_Session_Exception('Session namespace must not start with a number.'); + } + + if (isset(self::$_singleInstances[$namespace])) { + /** + * @see Zend_Session_Exception + */ + throw new Zend_Session_Exception("A session namespace object already exists for this namespace ('$namespace'), and no additional accessors (session namespace objects) for this namespace are permitted."); + } + + if ($singleInstance === true) { + self::$_singleInstances[$namespace] = true; + } + + $this->_namespace = $namespace; + + // Process metadata specific only to this namespace. + Zend_Session::start(true); // attempt auto-start (throws exception if strict option set) + + if (self::$_readable === false) { + /** + * @see Zend_Session_Exception + */ + throw new Zend_Session_Exception(self::_THROW_NOT_READABLE_MSG); + } + + if (!isset($_SESSION['__ZF'])) { + return; // no further processing needed + } + + // do not allow write access to namespaces, after stop() or writeClose() + if (parent::$_writable === true) { + if (isset($_SESSION['__ZF'][$namespace])) { + + // Expire Namespace by Namespace Hop (ENNH) + if (isset($_SESSION['__ZF'][$namespace]['ENNH'])) { + $_SESSION['__ZF'][$namespace]['ENNH']--; + + if ($_SESSION['__ZF'][$namespace]['ENNH'] === 0) { + if (isset($_SESSION[$namespace])) { + self::$_expiringData[$namespace] = $_SESSION[$namespace]; + unset($_SESSION[$namespace]); + } + unset($_SESSION['__ZF'][$namespace]); + } + } + + // Expire Namespace Variables by Namespace Hop (ENVNH) + if (isset($_SESSION['__ZF'][$namespace]['ENVNH'])) { + foreach ($_SESSION['__ZF'][$namespace]['ENVNH'] as $variable => $hops) { + $_SESSION['__ZF'][$namespace]['ENVNH'][$variable]--; + + if ($_SESSION['__ZF'][$namespace]['ENVNH'][$variable] === 0) { + if (isset($_SESSION[$namespace][$variable])) { + self::$_expiringData[$namespace][$variable] = $_SESSION[$namespace][$variable]; + unset($_SESSION[$namespace][$variable]); + } + unset($_SESSION['__ZF'][$namespace]['ENVNH'][$variable]); + } + } + if(empty($_SESSION['__ZF'][$namespace]['ENVNH'])) { + unset($_SESSION['__ZF'][$namespace]['ENVNH']); + } + } + } + + if (empty($_SESSION['__ZF'][$namespace])) { + unset($_SESSION['__ZF'][$namespace]); + } + + if (empty($_SESSION['__ZF'])) { + unset($_SESSION['__ZF']); + } + } + } + + + /** + * getIterator() - return an iteratable object for use in foreach and the like, + * this completes the IteratorAggregate interface + * + * @return ArrayObject - iteratable container of the namespace contents + */ + public function getIterator() + { + return new ArrayObject(parent::_namespaceGetAll($this->_namespace)); + } + + + /** + * lock() - mark a session/namespace as readonly + * + * @return void + */ + public function lock() + { + self::$_namespaceLocks[$this->_namespace] = true; + } + + + /** + * unlock() - unmark a session/namespace to enable read & write + * + * @return void + */ + public function unlock() + { + unset(self::$_namespaceLocks[$this->_namespace]); + } + + + /** + * unlockAll() - unmark all session/namespaces to enable read & write + * + * @return void + */ + public static function unlockAll() + { + self::$_namespaceLocks = array(); + } + + + /** + * isLocked() - return lock status, true if, and only if, read-only + * + * @return bool + */ + public function isLocked() + { + return isset(self::$_namespaceLocks[$this->_namespace]); + } + + + /** + * unsetAll() - unset all variables in this namespace + * + * @return true + */ + public function unsetAll() + { + return parent::_namespaceUnset($this->_namespace); + } + + + /** + * __get() - method to get a variable in this object's current namespace + * + * @param string $name - programmatic name of a key, in a <key,value> pair in the current namespace + * @return mixed + */ + public function & __get($name) + { + if ($name === '') { + /** + * @see Zend_Session_Exception + */ + throw new Zend_Session_Exception("The '$name' key must be a non-empty string"); + } + + return parent::_namespaceGet($this->_namespace, $name); + } + + + /** + * __set() - method to set a variable/value in this object's namespace + * + * @param string $name - programmatic name of a key, in a <key,value> pair in the current namespace + * @param mixed $value - value in the <key,value> pair to assign to the $name key + * @throws Zend_Session_Exception + * @return true + */ + public function __set($name, $value) + { + if (isset(self::$_namespaceLocks[$this->_namespace])) { + /** + * @see Zend_Session_Exception + */ + throw new Zend_Session_Exception('This session/namespace has been marked as read-only.'); + } + + if ($name === '') { + /** + * @see Zend_Session_Exception + */ + throw new Zend_Session_Exception("The '$name' key must be a non-empty string"); + } + + if (parent::$_writable === false) { + /** + * @see Zend_Session_Exception + */ + throw new Zend_Session_Exception(parent::_THROW_NOT_WRITABLE_MSG); + } + + $name = (string) $name; + + $_SESSION[$this->_namespace][$name] = $value; + } + + + /** + * apply() - enables applying user-selected function, such as array_merge() to the namespace + * Parameters following the $callback argument are passed to the callback function. + * Caveat: ignores members expiring now. + * + * Example: + * $namespace->apply('array_merge', array('tree' => 'apple', 'fruit' => 'peach'), array('flower' => 'rose')); + * $namespace->apply('count'); + * + * @param string|array $callback - callback function + */ + public function apply($callback) + { + $arg_list = func_get_args(); + $arg_list[0] = $_SESSION[$this->_namespace]; + return call_user_func_array($callback, $arg_list); + } + + + /** + * applySet() - enables applying user-selected function, and sets entire namespace to the result + * Result of $callback must be an array. + * Parameters following the $callback argument are passed to the callback function. + * Caveat: ignores members expiring now. + * + * Example: + * $namespace->applySet('array_merge', array('tree' => 'apple', 'fruit' => 'peach'), array('flower' => 'rose')); + * + * @param string|array $callback - callback function + */ + public function applySet($callback) + { + $arg_list = func_get_args(); + $arg_list[0] = $_SESSION[$this->_namespace]; + $result = call_user_func_array($callback, $arg_list); + if (!is_array($result)) { + /** + * @see Zend_Session_Exception + */ + throw new Zend_Session_Exception('Result must be an array. Got: ' . gettype($result)); + } + $_SESSION[$this->_namespace] = $result; + return $result; + } + + + /** + * __isset() - determine if a variable in this object's namespace is set + * + * @param string $name - programmatic name of a key, in a <key,value> pair in the current namespace + * @return bool + */ + public function __isset($name) + { + if ($name === '') { + /** + * @see Zend_Session_Exception + */ + throw new Zend_Session_Exception("The '$name' key must be a non-empty string"); + } + + return parent::_namespaceIsset($this->_namespace, $name); + } + + + /** + * __unset() - unset a variable in this object's namespace. + * + * @param string $name - programmatic name of a key, in a <key,value> pair in the current namespace + * @return true + */ + public function __unset($name) + { + if ($name === '') { + /** + * @see Zend_Session_Exception + */ + throw new Zend_Session_Exception("The '$name' key must be a non-empty string"); + } + + return parent::_namespaceUnset($this->_namespace, $name); + } + + + /** + * setExpirationSeconds() - expire the namespace, or specific variables after a specified + * number of seconds + * + * @param int $seconds - expires in this many seconds + * @param mixed $variables - OPTIONAL list of variables to expire (defaults to all) + * @throws Zend_Session_Exception + * @return void + */ + public function setExpirationSeconds($seconds, $variables = null) + { + if (parent::$_writable === false) { + /** + * @see Zend_Session_Exception + */ + throw new Zend_Session_Exception(parent::_THROW_NOT_WRITABLE_MSG); + } + + if ($seconds <= 0) { + /** + * @see Zend_Session_Exception + */ + throw new Zend_Session_Exception('Seconds must be positive.'); + } + + if ($variables === null) { + + // apply expiration to entire namespace + $_SESSION['__ZF'][$this->_namespace]['ENT'] = time() + $seconds; + + } else { + + if (is_string($variables)) { + $variables = array($variables); + } + + foreach ($variables as $variable) { + if (!empty($variable)) { + $_SESSION['__ZF'][$this->_namespace]['ENVT'][$variable] = time() + $seconds; + } + } + } + } + + + /** + * setExpirationHops() - expire the namespace, or specific variables after a specified + * number of page hops + * + * @param int $hops - how many "hops" (number of subsequent requests) before expiring + * @param mixed $variables - OPTIONAL list of variables to expire (defaults to all) + * @param boolean $hopCountOnUsageOnly - OPTIONAL if set, only count a hop/request if this namespace is used + * @throws Zend_Session_Exception + * @return void + */ + public function setExpirationHops($hops, $variables = null, $hopCountOnUsageOnly = false) + { + if (parent::$_writable === false) { + /** + * @see Zend_Session_Exception + */ + throw new Zend_Session_Exception(parent::_THROW_NOT_WRITABLE_MSG); + } + + if ($hops <= 0) { + /** + * @see Zend_Session_Exception + */ + throw new Zend_Session_Exception('Hops must be positive number.'); + } + + if ($variables === null) { + + // apply expiration to entire namespace + if ($hopCountOnUsageOnly === false) { + $_SESSION['__ZF'][$this->_namespace]['ENGH'] = $hops; + } else { + $_SESSION['__ZF'][$this->_namespace]['ENNH'] = $hops; + } + + } else { + + if (is_string($variables)) { + $variables = array($variables); + } + + foreach ($variables as $variable) { + if (!empty($variable)) { + if ($hopCountOnUsageOnly === false) { + $_SESSION['__ZF'][$this->_namespace]['ENVGH'][$variable] = $hops; + } else { + $_SESSION['__ZF'][$this->_namespace]['ENVNH'][$variable] = $hops; + } + } + } + } + } + + /** + * Returns the namespace name + * + * @return string + */ + public function getNamespace() + { + return $this->_namespace; + } +} diff --git a/library/vendor/Zend/Session/SaveHandler/DbTable.php b/library/vendor/Zend/Session/SaveHandler/DbTable.php new file mode 100644 index 0000000..a4b1bf7 --- /dev/null +++ b/library/vendor/Zend/Session/SaveHandler/DbTable.php @@ -0,0 +1,579 @@ +<?php + +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-webat this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Session + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ + +/** + * @see Zend_Session + */ + +/** + * @see Zend_Db_Table_Abstract + */ + +/** + * @see Zend_Db_Table_Row_Abstract + */ + +/** + * @see Zend_Config + */ + +/** + * Zend_Session_SaveHandler_DbTable + * + * @category Zend + * @package Zend_Session + * @subpackage SaveHandler + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Session_SaveHandler_DbTable + extends Zend_Db_Table_Abstract + implements Zend_Session_SaveHandler_Interface +{ + const PRIMARY_ASSIGNMENT = 'primaryAssignment'; + const PRIMARY_ASSIGNMENT_SESSION_SAVE_PATH = 'sessionSavePath'; + const PRIMARY_ASSIGNMENT_SESSION_NAME = 'sessionName'; + const PRIMARY_ASSIGNMENT_SESSION_ID = 'sessionId'; + + const MODIFIED_COLUMN = 'modifiedColumn'; + const LIFETIME_COLUMN = 'lifetimeColumn'; + const DATA_COLUMN = 'dataColumn'; + + const LIFETIME = 'lifetime'; + const OVERRIDE_LIFETIME = 'overrideLifetime'; + + const PRIMARY_TYPE_NUM = 'PRIMARY_TYPE_NUM'; + const PRIMARY_TYPE_PRIMARYNUM = 'PRIMARY_TYPE_PRIMARYNUM'; + const PRIMARY_TYPE_ASSOC = 'PRIMARY_TYPE_ASSOC'; + const PRIMARY_TYPE_WHERECLAUSE = 'PRIMARY_TYPE_WHERECLAUSE'; + + /** + * Session table primary key value assignment + * + * @var array + */ + protected $_primaryAssignment = null; + + /** + * Session table last modification time column + * + * @var string + */ + protected $_modifiedColumn = null; + + /** + * Session table lifetime column + * + * @var string + */ + protected $_lifetimeColumn = null; + + /** + * Session table data column + * + * @var string + */ + protected $_dataColumn = null; + + /** + * Session lifetime + * + * @var int + */ + protected $_lifetime = false; + + /** + * Whether or not the lifetime of an existing session should be overridden + * + * @var boolean + */ + protected $_overrideLifetime = false; + + /** + * Session save path + * + * @var string + */ + protected $_sessionSavePath; + + /** + * Session name + * + * @var string + */ + protected $_sessionName; + + /** + * Constructor + * + * $config is an instance of Zend_Config or an array of key/value pairs containing configuration options for + * Zend_Session_SaveHandler_DbTable and Zend_Db_Table_Abstract. These are the configuration options for + * Zend_Session_SaveHandler_DbTable: + * + * primaryAssignment => (string|array) Session table primary key value assignment + * (optional; default: 1 => sessionId) You have to assign a value to each primary key of your session table. + * The value of this configuration option is either a string if you have only one primary key or an array if + * you have multiple primary keys. The array consists of numeric keys starting at 1 and string values. There + * are some values which will be replaced by session information: + * + * sessionId => The id of the current session + * sessionName => The name of the current session + * sessionSavePath => The save path of the current session + * + * NOTE: One of your assignments MUST contain 'sessionId' as value! + * + * modifiedColumn => (string) Session table last modification time column + * + * lifetimeColumn => (string) Session table lifetime column + * + * dataColumn => (string) Session table data column + * + * lifetime => (integer) Session lifetime (optional; default: ini_get('session.gc_maxlifetime')) + * + * overrideLifetime => (boolean) Whether or not the lifetime of an existing session should be overridden + * (optional; default: false) + * + * @param Zend_Config|array $config User-provided configuration + * @return void + * @throws Zend_Session_SaveHandler_Exception + */ + public function __construct($config) + { + if ($config instanceof Zend_Config) { + $config = $config->toArray(); + } else if (!is_array($config)) { + /** + * @see Zend_Session_SaveHandler_Exception + */ + + throw new Zend_Session_SaveHandler_Exception( + '$config must be an instance of Zend_Config or array of key/value pairs containing ' + . 'configuration options for Zend_Session_SaveHandler_DbTable and Zend_Db_Table_Abstract.'); + } + + foreach ($config as $key => $value) { + do { + switch ($key) { + case self::PRIMARY_ASSIGNMENT: + $this->_primaryAssignment = $value; + break; + case self::MODIFIED_COLUMN: + $this->_modifiedColumn = (string) $value; + break; + case self::LIFETIME_COLUMN: + $this->_lifetimeColumn = (string) $value; + break; + case self::DATA_COLUMN: + $this->_dataColumn = (string) $value; + break; + case self::LIFETIME: + $this->setLifetime($value); + break; + case self::OVERRIDE_LIFETIME: + $this->setOverrideLifetime($value); + break; + default: + // unrecognized options passed to parent::__construct() + break 2; + } + unset($config[$key]); + } while (false); + } + + parent::__construct($config); + } + + /** + * Destructor + * + * @return void + */ + public function __destruct() + { + Zend_Session::writeClose(); + } + + /** + * Set session lifetime and optional whether or not the lifetime of an existing session should be overridden + * + * $lifetime === false resets lifetime to session.gc_maxlifetime + * + * @param int $lifetime + * @param boolean $overrideLifetime (optional) + * @return Zend_Session_SaveHandler_DbTable + */ + public function setLifetime($lifetime, $overrideLifetime = null) + { + if ($lifetime < 0) { + /** + * @see Zend_Session_SaveHandler_Exception + */ + throw new Zend_Session_SaveHandler_Exception(); + } else if (empty($lifetime)) { + $this->_lifetime = (int) ini_get('session.gc_maxlifetime'); + } else { + $this->_lifetime = (int) $lifetime; + } + + if ($overrideLifetime != null) { + $this->setOverrideLifetime($overrideLifetime); + } + + return $this; + } + + /** + * Retrieve session lifetime + * + * @return int + */ + public function getLifetime() + { + return $this->_lifetime; + } + + /** + * Set whether or not the lifetime of an existing session should be overridden + * + * @param boolean $overrideLifetime + * @return Zend_Session_SaveHandler_DbTable + */ + public function setOverrideLifetime($overrideLifetime) + { + $this->_overrideLifetime = (boolean) $overrideLifetime; + + return $this; + } + + /** + * Retrieve whether or not the lifetime of an existing session should be overridden + * + * @return boolean + */ + public function getOverrideLifetime() + { + return $this->_overrideLifetime; + } + + /** + * Open Session + * + * @param string $save_path + * @param string $name + * @return boolean + */ + public function open($save_path, $name) + { + $this->_sessionSavePath = $save_path; + $this->_sessionName = $name; + + return true; + } + + /** + * Close session + * + * @return boolean + */ + public function close() + { + return true; + } + + /** + * Read session data + * + * @param string $id + * @return string + */ + public function read($id) + { + $return = ''; + + $rows = call_user_func_array(array(&$this, 'find'), $this->_getPrimary($id)); + + if (count($rows)) { + if ($this->_getExpirationTime($row = $rows->current()) > time()) { + $return = $row->{$this->_dataColumn}; + } else { + $this->destroy($id); + } + } + + return $return; + } + + /** + * Write session data + * + * @param string $id + * @param string $data + * @return boolean + */ + public function write($id, $data) + { + $return = false; + + $data = array($this->_modifiedColumn => time(), + $this->_dataColumn => (string) $data); + + $rows = call_user_func_array(array(&$this, 'find'), $this->_getPrimary($id)); + + if (count($rows)) { + $data[$this->_lifetimeColumn] = $this->_getLifetime($rows->current()); + + if ($this->update($data, $this->_getPrimary($id, self::PRIMARY_TYPE_WHERECLAUSE))) { + $return = true; + } + } else { + $data[$this->_lifetimeColumn] = $this->_lifetime; + + if ($this->insert(array_merge($this->_getPrimary($id, self::PRIMARY_TYPE_ASSOC), $data))) { + $return = true; + } + } + + return $return; + } + + /** + * Destroy session + * + * @param string $id + * @return boolean + */ + public function destroy($id) + { + $return = false; + + if ($this->delete($this->_getPrimary($id, self::PRIMARY_TYPE_WHERECLAUSE))) { + $return = true; + } + + return $return; + } + + /** + * Garbage Collection + * + * @param int $maxlifetime + * @return true + */ + public function gc($maxlifetime) + { + $this->delete($this->getAdapter()->quoteIdentifier($this->_modifiedColumn, true) . ' + ' + . $this->getAdapter()->quoteIdentifier($this->_lifetimeColumn, true) . ' < ' + . $this->getAdapter()->quote(time())); + + return true; + } + + /** + * Calls other protected methods for individual setup tasks and requirement checks + * + * @return void + */ + protected function _setup() + { + parent::_setup(); + + $this->_setupPrimaryAssignment(); + $this->setLifetime($this->_lifetime); + + $this->_checkRequiredColumns(); + } + + /** + * Initialize table and schema names + * + * @return void + * @throws Zend_Session_SaveHandler_Exception + */ + protected function _setupTableName() + { + if (empty($this->_name) && basename(($this->_name = session_save_path())) != $this->_name) { + /** + * @see Zend_Session_SaveHandler_Exception + */ + + throw new Zend_Session_SaveHandler_Exception('session.save_path is a path and not a table name.'); + } + + if (strpos($this->_name, '.')) { + list($this->_schema, $this->_name) = explode('.', $this->_name); + } + } + + /** + * Initialize session table primary key value assignment + * + * @return void + * @throws Zend_Session_SaveHandler_Exception + */ + protected function _setupPrimaryAssignment() + { + if ($this->_primaryAssignment === null) { + $this->_primaryAssignment = array(1 => self::PRIMARY_ASSIGNMENT_SESSION_ID); + } else if (!is_array($this->_primaryAssignment)) { + $this->_primaryAssignment = array(1 => (string) $this->_primaryAssignment); + } else if (isset($this->_primaryAssignment[0])) { + array_unshift($this->_primaryAssignment, null); + + unset($this->_primaryAssignment[0]); + } + + if (count($this->_primaryAssignment) !== count($this->_primary)) { + /** + * @see Zend_Session_SaveHandler_Exception + */ + + throw new Zend_Session_SaveHandler_Exception( + "Value for configuration option '" . self::PRIMARY_ASSIGNMENT . "' must have an assignment " + . "for each session table primary key."); + } else if (!in_array(self::PRIMARY_ASSIGNMENT_SESSION_ID, $this->_primaryAssignment)) { + /** + * @see Zend_Session_SaveHandler_Exception + */ + + throw new Zend_Session_SaveHandler_Exception( + "Value for configuration option '" . self::PRIMARY_ASSIGNMENT . "' must have an assignment " + . "for the session id ('" . self::PRIMARY_ASSIGNMENT_SESSION_ID . "')."); + } + } + + /** + * Check for required session table columns + * + * @return void + * @throws Zend_Session_SaveHandler_Exception + */ + protected function _checkRequiredColumns() + { + if ($this->_modifiedColumn === null) { + /** + * @see Zend_Session_SaveHandler_Exception + */ + + throw new Zend_Session_SaveHandler_Exception( + "Configuration must define '" . self::MODIFIED_COLUMN . "' which names the " + . "session table last modification time column."); + } else if ($this->_lifetimeColumn === null) { + /** + * @see Zend_Session_SaveHandler_Exception + */ + + throw new Zend_Session_SaveHandler_Exception( + "Configuration must define '" . self::LIFETIME_COLUMN . "' which names the " + . "session table lifetime column."); + } else if ($this->_dataColumn === null) { + /** + * @see Zend_Session_SaveHandler_Exception + */ + + throw new Zend_Session_SaveHandler_Exception( + "Configuration must define '" . self::DATA_COLUMN . "' which names the " + . "session table data column."); + } + } + + /** + * Retrieve session table primary key values + * + * @param string $id + * @param string $type (optional; default: self::PRIMARY_TYPE_NUM) + * @return array + */ + protected function _getPrimary($id, $type = null) + { + $this->_setupPrimaryKey(); + + if ($type === null) { + $type = self::PRIMARY_TYPE_NUM; + } + + $primaryArray = array(); + + foreach ($this->_primary as $index => $primary) { + switch ($this->_primaryAssignment[$index]) { + case self::PRIMARY_ASSIGNMENT_SESSION_SAVE_PATH: + $value = $this->_sessionSavePath; + break; + case self::PRIMARY_ASSIGNMENT_SESSION_NAME: + $value = $this->_sessionName; + break; + case self::PRIMARY_ASSIGNMENT_SESSION_ID: + $value = (string) $id; + break; + default: + $value = (string) $this->_primaryAssignment[$index]; + break; + } + + switch ((string) $type) { + case self::PRIMARY_TYPE_PRIMARYNUM: + $primaryArray[$index] = $value; + break; + case self::PRIMARY_TYPE_ASSOC: + $primaryArray[$primary] = $value; + break; + case self::PRIMARY_TYPE_WHERECLAUSE: + $primaryArray[] = $this->getAdapter()->quoteIdentifier($primary, true) . ' = ' + . $this->getAdapter()->quote($value); + break; + case self::PRIMARY_TYPE_NUM: + default: + $primaryArray[] = $value; + break; + } + } + + return $primaryArray; + } + + /** + * Retrieve session lifetime considering Zend_Session_SaveHandler_DbTable::OVERRIDE_LIFETIME + * + * @param Zend_Db_Table_Row_Abstract $row + * @return int + */ + protected function _getLifetime(Zend_Db_Table_Row_Abstract $row) + { + $return = $this->_lifetime; + + if (!$this->_overrideLifetime) { + $return = (int) $row->{$this->_lifetimeColumn}; + } + + return $return; + } + + /** + * Retrieve session expiration time + * + * @param Zend_Db_Table_Row_Abstract $row + * @return int + */ + protected function _getExpirationTime(Zend_Db_Table_Row_Abstract $row) + { + return (int) $row->{$this->_modifiedColumn} + $this->_getLifetime($row); + } +} diff --git a/library/vendor/Zend/Session/SaveHandler/Exception.php b/library/vendor/Zend/Session/SaveHandler/Exception.php new file mode 100644 index 0000000..2b1876f --- /dev/null +++ b/library/vendor/Zend/Session/SaveHandler/Exception.php @@ -0,0 +1,36 @@ +<?php + +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Session + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ + +/** + * @see Zend_Session_Exception + */ + +/** + * Zend_Session_SaveHandler_Exception + * + * @category Zend + * @package Zend_Session + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Session_SaveHandler_Exception extends Zend_Session_Exception +{} diff --git a/library/vendor/Zend/Session/SaveHandler/Interface.php b/library/vendor/Zend/Session/SaveHandler/Interface.php new file mode 100644 index 0000000..18ed5fe --- /dev/null +++ b/library/vendor/Zend/Session/SaveHandler/Interface.php @@ -0,0 +1,81 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Session + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + * @since Preview Release 0.2 + */ + +/** + * Zend_Session_SaveHandler_Interface + * + * @category Zend + * @package Zend_Session + * @subpackage SaveHandler + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @see http://php.net/session_set_save_handler + */ +interface Zend_Session_SaveHandler_Interface +{ + + /** + * Open Session - retrieve resources + * + * @param string $save_path + * @param string $name + */ + public function open($save_path, $name); + + /** + * Close Session - free resources + * + */ + public function close(); + + /** + * Read session data + * + * @param string $id + */ + public function read($id); + + /** + * Write Session - commit data to resource + * + * @param string $id + * @param mixed $data + */ + public function write($id, $data); + + /** + * Destroy Session - remove data from resource for + * given session id + * + * @param string $id + */ + public function destroy($id); + + /** + * Garbage Collection - remove old session data older + * than $maxlifetime (in seconds) + * + * @param int $maxlifetime + */ + public function gc($maxlifetime); + +} diff --git a/library/vendor/Zend/Session/Validator/Abstract.php b/library/vendor/Zend/Session/Validator/Abstract.php new file mode 100644 index 0000000..f39d20e --- /dev/null +++ b/library/vendor/Zend/Session/Validator/Abstract.php @@ -0,0 +1,70 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Session + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + * @since Preview Release 0.2 + */ + +/** + * @see Zend_Session_Validator_Interface + */ + +/** + * Zend_Session_Validator_Abstract + * + * @category Zend + * @package Zend_Session + * @subpackage Validator + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +abstract class Zend_Session_Validator_Abstract implements Zend_Session_Validator_Interface +{ + + /** + * SetValidData() - This method should be used to store the environment variables that + * will be needed in order to validate the session later in the validate() method. + * These values are stored in the session in the __ZF namespace, in an array named VALID + * + * @param mixed $data + * @return void + */ + protected function setValidData($data) + { + $validatorName = get_class($this); + + $_SESSION['__ZF']['VALID'][$validatorName] = $data; + } + + + /** + * GetValidData() - This method should be used to retrieve the environment variables that + * will be needed to 'validate' a session. + * + * @return mixed + */ + protected function getValidData() + { + $validatorName = get_class($this); + if (isset($_SESSION['__ZF']['VALID'][$validatorName])) { + return $_SESSION['__ZF']['VALID'][$validatorName]; + } + return null; + } + +} diff --git a/library/vendor/Zend/Session/Validator/Exception.php b/library/vendor/Zend/Session/Validator/Exception.php new file mode 100644 index 0000000..03c2a03 --- /dev/null +++ b/library/vendor/Zend/Session/Validator/Exception.php @@ -0,0 +1,42 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Session + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + * @since Preview Release 0.2 + */ + + +/** + * @see Zend_Session_Exception + */ + + +/** + * Zend_Session_Validator_Exception + * + * @category Zend + * @package Zend_Session + * @subpackage Validator + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Session_Validator_Exception extends Zend_Session_Exception +{ + +} + diff --git a/library/vendor/Zend/Session/Validator/HttpUserAgent.php b/library/vendor/Zend/Session/Validator/HttpUserAgent.php new file mode 100644 index 0000000..8431aa2 --- /dev/null +++ b/library/vendor/Zend/Session/Validator/HttpUserAgent.php @@ -0,0 +1,65 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Session + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + * @since Preview Release 0.2 + */ + +/** + * @see Zend_Session_Validator_Abstract + */ + +/** + * Zend_Session_Validator_HttpUserAgent + * + * @category Zend + * @package Zend_Session + * @subpackage Validator + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Session_Validator_HttpUserAgent extends Zend_Session_Validator_Abstract +{ + + /** + * Setup() - this method will get the current user agent and store it in the session + * as 'valid data' + * + * @return void + */ + public function setup() + { + $this->setValidData( (isset($_SERVER['HTTP_USER_AGENT']) + ? $_SERVER['HTTP_USER_AGENT'] : null) ); + } + + /** + * Validate() - this method will determine if the current user agent matches the + * user agent we stored when we initialized this variable. + * + * @return bool + */ + public function validate() + { + $currentBrowser = (isset($_SERVER['HTTP_USER_AGENT']) + ? $_SERVER['HTTP_USER_AGENT'] : null); + + return $currentBrowser === $this->getValidData(); + } + +} diff --git a/library/vendor/Zend/Session/Validator/Interface.php b/library/vendor/Zend/Session/Validator/Interface.php new file mode 100644 index 0000000..ab4eb3e --- /dev/null +++ b/library/vendor/Zend/Session/Validator/Interface.php @@ -0,0 +1,52 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Session + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + * @since Preview Release 0.2 + */ + +/** + * Zend_Session_Validator_Interface + * + * @category Zend + * @package Zend_Session + * @subpackage Validator + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +interface Zend_Session_Validator_Interface +{ + + /** + * Setup() - this method will store the environment variables + * necessary to be able to validate against in future requests. + * + * @return void + */ + public function setup(); + + /** + * Validate() - this method will be called at the beginning of + * every session to determine if the current environment matches + * that which was store in the setup() procedure. + * + * @return boolean + */ + public function validate(); + +} |