[21742] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[22206] | 5 | * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved. |
---|
[21742] | 6 | * |
---|
| 7 | * http://www.lockon.co.jp/ |
---|
| 8 | * |
---|
| 9 | * This program is free software; you can redistribute it and/or |
---|
| 10 | * modify it under the terms of the GNU General Public License |
---|
| 11 | * as published by the Free Software Foundation; either version 2 |
---|
| 12 | * of the License, or (at your option) any later version. |
---|
| 13 | * |
---|
| 14 | * This program is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this program; if not, write to the Free Software |
---|
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | /** |
---|
| 25 | * クラスのオートローディングクラス |
---|
| 26 | * |
---|
| 27 | * @package Page |
---|
| 28 | * @author LOCKON CO.,LTD. |
---|
| 29 | * @version $Id$ |
---|
| 30 | */ |
---|
[22856] | 31 | class SC_ClassAutoloader |
---|
[22567] | 32 | { |
---|
[21742] | 33 | /** |
---|
| 34 | * クラスのオートローディング本体 |
---|
| 35 | * |
---|
| 36 | * LC_* には対応していない。 |
---|
| 37 | * @return void |
---|
| 38 | */ |
---|
[22567] | 39 | public static function autoload($class) |
---|
| 40 | { |
---|
[21742] | 41 | $arrClassNamePart = explode('_', $class); |
---|
| 42 | $is_ex = end($arrClassNamePart) === 'Ex'; |
---|
| 43 | $count = count($arrClassNamePart); |
---|
| 44 | $classpath = $is_ex ? CLASS_EX_REALDIR : CLASS_REALDIR; |
---|
| 45 | |
---|
| 46 | if (($arrClassNamePart[0] === 'GC' || $arrClassNamePart[0] === 'SC') && $arrClassNamePart[1] === 'Utils') { |
---|
| 47 | $classpath .= $is_ex ? 'util_extends/' : 'util/'; |
---|
[21991] | 48 | } elseif ($arrClassNamePart[0] === 'SC' && $is_ex === true && $count >= 4) { |
---|
[21742] | 49 | $arrClassNamePartTemp = $arrClassNamePart; |
---|
| 50 | // FIXME クラスファイルのディレクトリ命名が変。変な現状に合わせて強引な処理をしてる。 |
---|
| 51 | $arrClassNamePartTemp[1] = $arrClassNamePartTemp[1] . '_extends'; |
---|
| 52 | $classpath .= strtolower(implode('/', array_slice($arrClassNamePartTemp, 1, -2))) . '/'; |
---|
[21991] | 53 | } elseif ($arrClassNamePart[0] === 'SC' && $is_ex === false && $count >= 3) { |
---|
[21742] | 54 | $classpath .= strtolower(implode('/', array_slice($arrClassNamePart, 1, -1))) . '/'; |
---|
[21991] | 55 | } elseif ($arrClassNamePart[0] === 'SC') { |
---|
[21742] | 56 | // 処理なし |
---|
| 57 | } |
---|
| 58 | // PEAR用 |
---|
| 59 | // FIXME トリッキー |
---|
| 60 | else { |
---|
| 61 | $classpath = ''; |
---|
| 62 | $class = str_replace('_', '/', $class); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | $classpath .= "$class.php"; |
---|
| 66 | |
---|
| 67 | // プラグイン向けフックポイント |
---|
| 68 | // MEMO: プラグインのローダーがDB接続を必要とするため、SC_Queryがロードされた後のみ呼び出される。 |
---|
| 69 | // プラグイン情報のキャッシュ化が行われれば、全部にフックさせることを可能に? |
---|
[21915] | 70 | $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance(true); |
---|
| 71 | if (is_object($objPlugin)) { |
---|
[21742] | 72 | // 元の設定を一時保存 |
---|
| 73 | $plugin_class = $class; |
---|
| 74 | $plugin_classpath = $classpath; |
---|
[22083] | 75 | |
---|
[21742] | 76 | $objPlugin->doAction('loadClassFileChange', array(&$plugin_class, &$plugin_classpath)); |
---|
[22083] | 77 | |
---|
[21742] | 78 | // FIXME: トリッキーな処理で _Ex ファイルを無視しないようにする(無視するとユーザーカスタマイズで分かりにくい) |
---|
| 79 | // SC_XXXX_Ex がロードされる場合にextendsのchainを |
---|
| 80 | // SC_XXXX_Ex -> SC_XXXX から、 SC_XXXX_Ex -> $class (-> SC_XXXX) と変える。 |
---|
| 81 | // そうでない場合は、直接置き換えと想定して帰ってきたクラスをロードする |
---|
[22083] | 82 | if (is_array($plugin_class) && count($plugin_class) > 0) { |
---|
| 83 | $arrPluginClassName = $plugin_class; |
---|
| 84 | $arrPluginClassPath = $plugin_classpath; |
---|
| 85 | |
---|
| 86 | foreach ($arrPluginClassName as $key => $plugin_class) { |
---|
| 87 | $plugin_classpath = $arrPluginClassPath[$key]; |
---|
| 88 | |
---|
| 89 | if ($is_ex) { |
---|
| 90 | // Ex ファイルへのフックの場合のみチェイン変更する。 |
---|
| 91 | |
---|
| 92 | if ($parent_classname) { |
---|
| 93 | $exp = "/(class[ ]+{$plugin_class}[ ]+extends +)[a-zA-Z_\-]+( *{?)/"; |
---|
| 94 | $replace = '$1' . $parent_classname . '$2'; |
---|
| 95 | |
---|
| 96 | $base_class_str = file_get_contents($plugin_classpath); |
---|
| 97 | $base_class_str = str_replace(array('<?php', '?>'), '', $base_class_str); |
---|
| 98 | $base_class_str = preg_replace($exp, $replace, $base_class_str, 1); |
---|
| 99 | eval($base_class_str); |
---|
| 100 | } else { |
---|
| 101 | include $plugin_classpath; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | $parent_classname = $plugin_class; |
---|
| 105 | } else { |
---|
| 106 | include $plugin_classpath; |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | |
---|
[21742] | 110 | if ($is_ex) { |
---|
[22083] | 111 | $exp = "/(class[ ]+{$class}[ ]+extends +)[a-zA-Z_\-]+( *{?)/"; |
---|
| 112 | $replace = '$1' . $parent_classname . '$2'; |
---|
[21742] | 113 | $base_class_str = file_get_contents($classpath); |
---|
| 114 | $base_class_str = str_replace(array('<?php', '?>'), '', $base_class_str); |
---|
| 115 | $base_class_str = preg_replace($exp, $replace, $base_class_str, 1); |
---|
| 116 | eval($base_class_str); |
---|
[23124] | 117 | |
---|
[21742] | 118 | return; |
---|
| 119 | } |
---|
| 120 | } |
---|
| 121 | } |
---|
[23028] | 122 | if (file_exists($classpath)) { |
---|
| 123 | include $classpath; |
---|
| 124 | } else { |
---|
| 125 | $arrPath = explode(PATH_SEPARATOR, get_include_path()); |
---|
| 126 | foreach ($arrPath as $path) { |
---|
| 127 | if (file_exists($path . '/' .$classpath)) { |
---|
| 128 | include $classpath; |
---|
| 129 | break; |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | } |
---|
[21742] | 133 | } |
---|
| 134 | } |
---|