[Frameworkspider-svn] spider-commit [33]

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 4月 14日 (火) 21:26:53 JST


Revision: 33
          http://svn.sourceforge.jp/view?root=frameworkspider&view=rev&rev=33
Author:   m_nakashima
Date:     2009-04-14 21:26:53 +0900 (Tue, 14 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-13 06:49:56 UTC (rev 32)
+++ current/DATA/lib/spider/HttpRequest.class.php	2009-04-14 12:26:53 UTC (rev 33)
@@ -10,6 +10,8 @@
  * @author Multimedia Digital Contents Systems.Co.,Ltd. m.nakashima <m_nakas****@md-sy*****>
  * @since PHP 4.3
  */
+define( 'SPIDER_SESSION_SCOPE_GLOBAL', 'GLOBAL' );
+define( 'SPIDER_SESSION_SCOPE_AUTO', 'AUTO' );
 require_once(dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'util'.DIRECTORY_SEPARATOR.'CharUtility.class.php');
 class spider_HttpRequest {
 	/** Attributes			*/
@@ -132,5 +134,79 @@
 	function redirectTo($url) {
 		$this->redirect_url	= $url;
 	}
+	/**
+	 * セッション変数を設定します
+	 * @param $key
+	 * @param $value
+	 * @param $scopse GLOBALまたは有効フォルダURI
+	 */
+	function setSession( $key, $value, $scope=SPIDER_SESSION_SCOPE_AUTO ) {
+		$this->optimizeSession();
+		if( $scope == SPIDER_SESSION_SCOPE_AUTO ) {
+			$scope	= dirname($_SERVER['REQUEST_URI']);
+		}
+		if( SPIDER_SESSION_SCOPE_GLOBAL == $scope ) {
+			$key	= 'spider_GLOBAL.'.$key;
+		} else {
+			$key	= str_replace('/','.s.',$scope).'.s.'.$key;
+		}
+		$session_var	= new spider_HttpSessionVar( $value, $scope );
+		$_SESSION[$key]	= serialize( $session_var );
+	}
+	/**
+	 * セッション変数を取得します
+	 * @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;
+			if( isset( $_SESSION ) && isset($_SESSION[$target_key]) ) {
+				$value	= $_SESSION[$target_key];
+			}
+		}
+		return $value;
+	}
+	/**
+	 * セッション変数が登録されているか確認します
+	 * @param $key
+	 */
+	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;
+			if( isset( $_SESSION ) && isset($_SESSION[$target_key]) ) {
+				return true;
+			}
+		}
+		return false;
+	}
+	/**
+	 * セッション登録済み情報を最適化します
+	 */
+	function optimizeSession() {
+		if( isset( $_SESSION ) && is_array( $_SESSION ) ) {
+			$current_scope	= $this->getSessionCurrentScope();
+			foreach( $_SESSION as $key => $value ) {
+				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']));
+	}
 }
 ?>



Frameworkspider-svn メーリングリストの案内
Back to archive index