/classes/core/Session.class.php
PHP | 238 lines | 129 code | 40 blank | 69 comment | 2 complexity | 98b5eeca575064c765add044b424f140 MD5 | raw file
- <?php
- /**
- * ??????????????
- *
- * PHP version 5
- *
- * @package core
- * @author CharcoalPHP Development Team
- * @copyright 2008 - 2012 CharcoalPHP Development Team
- */
- class Charcoal_Session extends Charcoal_Object
- {
- var $_data;
- /*
- * ???????
- */
- public function __construct()
- {
- $this->_data = array();
- $req_path = Charcoal_Framework::getRequestPath();
- log_info( "session", "request_path=" . $req_path );
- }
- /*
- * ?????????
- */
- public function getName()
- {
- return session_name();
- }
- /*
- * ????????????
- */
- public function getSavePath()
- {
- return session_save_path();
- }
- /*
- * ??????????????????
- */
- public function getCookieParameter( Charcoal_String $key )
- {
- $a = session_get_cookie_params();
- $key = us( $key );
- return $a[ $key ];
- }
- /*
- * ?????????????????????
- */
- public function getCookieParameters()
- {
- return session_get_cookie_params();
- }
- /*
- * ???
- */
- public function clear()
- {
- $this->_data = array();
- log_info( "session", "clear()" );
- }
- /*
- * ID???
- */
- public function regenerateID()
- {
- $old_id = session_id();
- $result = session_regenerate_id( TRUE );
- $new_id = session_id();
- log_info( "session", "regenerateID() old=$old_id new=$new_id result=" . ($result ? "TRUE" : "FALSE") );
- }
- /*
- * ???????
- */
- public function getKeys()
- {
- return array_keys( $this->_data );
- }
- /*
- * ????????
- */
- public function get( Charcoal_String $key )
- {
- $key = us( $key );
- $value = isset($this->_data[ $key ]) ? $this->_data[ $key ] : NULL;
- log_debug( "session", "get($key)=$value" );
- return $value;
- }
- /*
- * ????????
- */
- public function set( Charcoal_String $key, $value )
- {
- $key = us( $key );
- $this->_data[ $key ] = $value;
- log_debug( "session", "set($key," . print_r($value,true) . ")" );
- }
- /*
- * ???????????
- */
- public function remove( Charcoal_String $key )
- {
- $key = us( $key );
- $value = isset($this->_data[ $key ]) ? $this->_data[ $key ] : NULL;
- if ( $value ){
- unset( $this->_data[ $key ] );
- }
- log_debug( "session", "remove($key)=$value" );
- return $value;
- }
- /**
- * ??????????
- */
- public function start()
- {
- session_cache_limiter('private, must-revalidate');
- // session_cache_limiter('private');
- // session_cache_limiter('private_no_expire');
- // session_cache_limiter('nocache');
- session_start();
- log_info( "session", "start() session_id=" . session_id() . " IP=" . $_SERVER["REMOTE_ADDR"] );
- }
- /**
- * ??????????
- */
- public function close()
- {
- session_write_close();
- log_info( "session", "close()" );
- }
- /*
- * ????????
- */
- public function destroy()
- {
- $this->clear();
- session_unset();
- session_destroy();
- log_info( "session", "destroy()" );
- }
- /**
- * ??????????
- */
- public function restore()
- {
- log_info( "session", "restore() start" );
- log_info( "session", "_SESSION:" . print_r($_SESSION,true) );
- log_info( "session", "this->_data:" . print_r($this->_data,true) );
- // ??????
- $this->clear();
- log_info( "session", "_SESSION:" . print_r($_SESSION,true) );
- // ?????????????
- $keys = array_keys( $_SESSION );
- if ( $keys ){
- foreach( $keys as $key ){
- $value = unserialize( $_SESSION[$key] );
- $this->set( s($key), $value );
- log_info( "session", "key:" . print_r($key,true) );
- log_info( "session", "value:" . print_r($value,true) );
- }
- }
- log_info( "session", "_SESSION:" . print_r($_SESSION,true) );
- log_info( "session", "this->_data:" . print_r($this->_data,true) );
- log_info( "session", "restore() end" );
- }
- /**
- * ??????????
- */
- public function save()
- {
- log_info( "session", 'save() start' );
- log_info( "session", "_SESSION:" . print_r($_SESSION,true) );
- log_info( "session", "this->_data:" . print_r($this->_data,true) );
- // ???????
- $_SESSION = array();
- $keys = $this->getKeys();
- log_info( "session", "keys:" . print_r($keys,true) );
- // ?????????????????????
- foreach( $keys as $key ){
- $value = $this->get( s($key) );
- $_SESSION[ $key ] = serialize($value);
- log_info( "session", "key:" . print_r($key,true) );
- log_info( "session", "value:" . print_r($value,true) );
- }
- log_info( "session", "_SESSION:" . print_r($_SESSION,true) );
- log_info( "session", "this->_data:" . print_r($this->_data,true) );
- log_info( "session", 'save() end' );
- }
- /*
- * String expression of this object
- *
- * @return string
- */
- public function toString()
- {
- return Charcoal_System::arrayToString( $this->_data );
- }
- }
- return __FILE__;