Ignore:
Timestamp:
2012/06/12 15:07:25 (12 years ago)
Author:
Seasoft
Message:

#1858 (SC_Query#getSingletonInstance グローバル変数の使用を避ける)

  • セッター・ゲッターを提供。
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_12-dev/data/class/SC_Query.php

    r21904 r21914  
    3939    var $order = ''; 
    4040    var $force_run = false; 
    41     static $arrInstance = array(); 
     41    /** シングルトン動作のためのインスタンスプール配列。キーは DSN の識別情報。 */ 
     42    static $arrPoolInstance = array(); 
    4243 
    4344    /** 
     
    9899     * @return SC_Query シングルトンの SC_Query インスタンス 
    99100     */ 
    100     function getSingletonInstance($dsn = '', $force_run = false, $new = false) { 
    101         $key_str = serialize($dsn); 
    102         if (!isset(SC_Query_Ex::$arrInstance[$key_str])) { 
    103             SC_Query_Ex::$arrInstance[$key_str] =& new SC_Query_Ex($dsn, $force_run, $new); 
     101    static function getSingletonInstance($dsn = '', $force_run = false, $new = false) { 
     102        $objThis = SC_Query_Ex::getPoolInstance($dsn); 
     103        if (is_null($objThis)) { 
     104            $objThis = SC_Query_Ex::setPoolInstance(new SC_Query_Ex($dsn, $force_run, $new), $dsn); 
    104105        } 
    105106        /* 
     
    109110         * 厳密な意味でのシングルトンではないが、パフォーマンス的に大差は無い。 
    110111         */ 
    111         return clone SC_Query_Ex::$arrInstance[$key_str]; 
     112        return clone $objThis; 
    112113    } 
    113114 
     
    11061107        GC_Utils_Ex::gfPrintLog($msg, DB_LOG_REALFILE); 
    11071108    } 
     1109 
     1110    /** 
     1111     * インスタンスをプールする 
     1112     * 
     1113     * @param SC_Query $objThis プールするインスタンス 
     1114     * @param string $dsn データソース名 
     1115     * @return SC_Query プールしたインスタンス 
     1116     */ 
     1117    static function setPoolInstance(&$objThis, $dsn = '') { 
     1118        $key_str = serialize($dsn); 
     1119        return SC_Query_Ex::$arrPoolInstance[$key_str] = $objThis; 
     1120    } 
     1121 
     1122    /** 
     1123     * プールしているインスタンスを取得する 
     1124     * 
     1125     * @param string $dsn データソース名 
     1126     * @return SC_Query|null 
     1127     */ 
     1128    static function getPoolInstance($dsn = '') { 
     1129        $key_str = serialize($dsn); 
     1130        if (isset(SC_Query_Ex::$arrPoolInstance[$key_str])) { 
     1131            return SC_Query_Ex::$arrPoolInstance[$key_str]; 
     1132        } 
     1133    } 
    11081134} 
Note: See TracChangeset for help on using the changeset viewer.