Changeset 22083


Ignore:
Timestamp:
2012/11/07 21:04:04 (11 years ago)
Author:
shutta
Message:

#1962 (プラグイン: SC_系のクラスを優先度順にフック(継承)できるように改善)

Location:
branches/version-2_12-dev/data/class
Files:
2 edited

Legend:

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

    r21991 r22083  
    7272            $plugin_class = $class; 
    7373            $plugin_classpath = $classpath; 
     74 
    7475            $objPlugin->doAction('loadClassFileChange', array(&$plugin_class, &$plugin_classpath)); 
     76 
    7577            // FIXME: トリッキーな処理で _Ex ファイルを無視しないようにする(無視するとユーザーカスタマイズで分かりにくい) 
    7678            //        SC_XXXX_Ex がロードされる場合にextendsのchainを 
    7779            //        SC_XXXX_Ex -> SC_XXXX から、 SC_XXXX_Ex -> $class (-> SC_XXXX) と変える。 
    7880            //        そうでない場合は、直接置き換えと想定して帰ってきたクラスをロードする 
    79             if ($plugin_class !== $class) { 
     81            if (is_array($plugin_class) && count($plugin_class) > 0) { 
     82                $arrPluginClassName = $plugin_class; 
     83                $arrPluginClassPath = $plugin_classpath; 
     84 
     85                foreach ($arrPluginClassName as $key => $plugin_class) { 
     86                    $plugin_classpath = $arrPluginClassPath[$key]; 
     87 
     88                    if ($is_ex) { 
     89                        // Ex ファイルへのフックの場合のみチェイン変更する。 
     90 
     91                        if ($parent_classname) { 
     92                            $exp = "/(class[ ]+{$plugin_class}[ ]+extends +)[a-zA-Z_\-]+( *{?)/"; 
     93                            $replace = '$1' . $parent_classname . '$2'; 
     94 
     95                            $base_class_str = file_get_contents($plugin_classpath); 
     96                            $base_class_str = str_replace(array('<?php', '?>'), '', $base_class_str); 
     97                            $base_class_str = preg_replace($exp, $replace, $base_class_str, 1); 
     98                            eval($base_class_str); 
     99                        } else { 
     100                            include $plugin_classpath; 
     101                        } 
     102 
     103                        $parent_classname = $plugin_class; 
     104                    } else { 
     105                        include $plugin_classpath; 
     106                    } 
     107                } 
     108 
    80109                if ($is_ex) { 
    81                     // Ex ファイルへのフックの場合のみチェイン変更する。 
    82                     $exp = "/(class[ ]+{$class}[ ]+extends +)[a-zA-Z_\-]+( *{)/"; 
    83                     $replace = '$1' . $plugin_class . '$2'; 
     110                    $exp = "/(class[ ]+{$class}[ ]+extends +)[a-zA-Z_\-]+( *{?)/"; 
     111                    $replace = '$1' . $parent_classname . '$2'; 
    84112                    $base_class_str = file_get_contents($classpath); 
    85113                    $base_class_str = str_replace(array('<?php', '?>'), '', $base_class_str); 
    86114                    $base_class_str = preg_replace($exp, $replace, $base_class_str, 1); 
    87                     include $plugin_classpath; 
    88115                    eval($base_class_str); 
    89116                    return; 
    90                 } else { 
    91                     include $plugin_classpath; 
    92117                } 
    93118            } 
  • branches/version-2_12-dev/data/class/helper/SC_Helper_Plugin.php

    r22018 r22083  
    105105        } 
    106106 
     107        if ($hook_point == 'loadClassFileChange') { 
     108            $arrSaveArgs = $arrArgs; 
     109            $arrClassName = array(); 
     110            $arrClassPath = array(); 
     111        } 
     112 
    107113        if (array_key_exists($hook_point, $this->arrRegistedPluginActions) 
    108114            && is_array($this->arrRegistedPluginActions[$hook_point])) { 
     
    113119                foreach ($arrFuncs as $func) { 
    114120                    if (!is_null($func['function'])) { 
    115                         call_user_func_array($func['function'], $arrArgs); 
     121                        if ($hook_point == 'loadClassFileChange') { 
     122                            $classname = $arrSaveArgs[0]; 
     123                            $classpath = $arrSaveArgs[1]; 
     124                            $arrTempArgs = array(&$classname, &$classpath); 
     125 
     126                            call_user_func_array($func['function'], $arrTempArgs); 
     127 
     128                            if ($classname !== $arrSaveArgs[0]) { 
     129                                $arrClassName[] = $classname; 
     130                                $arrClassPath[] = $classpath; 
     131                            } 
     132                        } else { 
     133                            call_user_func_array($func['function'], $arrArgs); 
     134                        } 
    116135                    } 
     136                } 
     137            } 
     138 
     139            if ($hook_point == 'loadClassFileChange') { 
     140                if (count($arrClassName) > 0) { 
     141                    $arrArgs[0] = $arrClassName; 
     142                    $arrArgs[1] = $arrClassPath; 
    117143                } 
    118144            } 
Note: See TracChangeset for help on using the changeset viewer.