svnno****@sourc*****
svnno****@sourc*****
2009年 4月 15日 (水) 12:49:23 JST
Revision: 35 http://svn.sourceforge.jp/view?root=frameworkspider&view=rev&rev=35 Author: m_nakashima Date: 2009-04-15 12:49:23 +0900 (Wed, 15 Apr 2009) Log Message: ----------- Modified Paths: -------------- current/DATA/lib/spider/HttpRequest.class.php -------------- next part -------------- Modified: current/DATA/lib/spider/HttpRequest.class.php =================================================================== --- current/DATA/lib/spider/HttpRequest.class.php 2009-04-14 12:30:21 UTC (rev 34) +++ current/DATA/lib/spider/HttpRequest.class.php 2009-04-15 03:49:23 UTC (rev 35) @@ -146,9 +146,9 @@ $scope = dirname($_SERVER['REQUEST_URI']); } if( SPIDER_SESSION_SCOPE_GLOBAL == $scope ) { - $key = 'spider_GLOBAL.'.$key; + $key = $this->_getGlobalSessionKey( $key ); } else { - $key = str_replace('/','.s.',$scope).'.s.'.$key; + $key = $scope.'/'.$key; } $session_var = new spider_HttpSessionVar( $value, $scope ); $_SESSION[$key] = serialize( $session_var ); @@ -158,18 +158,24 @@ * @param $key */ function getSession( $key ) { - $value = null; $this->optimizeSession(); - $target_key = $this->getSessionCurrentScope().'.s.'.$key; - if( isset( $_SESSION ) && isset($_SESSION[$target_key]) ) { - $value = $_SESSION[$target_key]; - } else { - $target_key = 'spider_GLOBAL.'.$key; + $value = null; + $current_scope = dirname( $_SERVER['REQUEST_URI'] ); + while( strlen($current_scope) > 0 ) { + $target_key = $current_scope.'/'.$key; if( isset( $_SESSION ) && isset($_SESSION[$target_key]) ) { $value = $_SESSION[$target_key]; + return $value; } + $current_scope = dirname( $current_scope ); } - return $value; + $target_key = $this->_getGlobalSessionKey( $key ); + if( isset( $_SESSION ) && isset($_SESSION[$target_key]) ) { + $value = $_SESSION[$target_key]; + return $value; + } + + return null; } /** * セッション変数が登録されているか確認します @@ -177,15 +183,19 @@ */ function existsSession( $key ) { $this->optimizeSession(); - $target_key = $this->getSessionCurrentScope().'.s.'.$key; - if( isset( $_SESSION ) && isset($_SESSION[$target_key]) ) { - return true; - } else { - $target_key = 'spider_GLOBAL.'.$key; + $current_scope = dirname( $_SERVER['REQUEST_URI'] ); + while( strlen($current_scope) > 0 ) { + $target_key = $current_scope.'/'.$key; if( isset( $_SESSION ) && isset($_SESSION[$target_key]) ) { return true; } + $current_scope = dirname( $current_scope ); } + $target_key = $this->_getGlobalSessionKey( $key ); + if( isset( $_SESSION ) && isset($_SESSION[$target_key]) ) { + $value = $_SESSION[$target_key]; + return true; + } return false; } /** @@ -193,20 +203,17 @@ */ function optimizeSession() { if( isset( $_SESSION ) && is_array( $_SESSION ) ) { - $current_scope = $this->getSessionCurrentScope(); + $current_scope = dirname( $_SERVER['REQUEST_URI'] ); foreach( $_SESSION as $key => $value ) { - if( preg_match('/^spider_GLOBAL\\./',$key) == 0 + if( preg_match('/^spider\\_GLOBAL\\./',$key) == 0 && preg_match('/^'.CharUtility::escape_regx_str($current_scope).'/',$key) == 0 ) { unset( $_SESSION[$key] ); } } } } - /** - * リクエストURIからセッションスコープを取得します - */ - function getSessionCurrentScope() { - return str_replace('/','.s.',dirname($_SERVER['REQUEST_URI'])); + function _getGlobalSessionKey( $key ) { + return 'spider_GLOBAL.'.$key; } } ?>