diff --git a/data/app_initial.php b/data/app_initial.php index e776174496..5ce99f5ad1 100644 --- a/data/app_initial.php +++ b/data/app_initial.php @@ -47,11 +47,15 @@ // クラスのオートローディングを定義する require_once(CLASS_EX_REALDIR . 'SC_ClassAutoloader_Ex.php'); -spl_autoload_register(array('SC_ClassAutoloader_Ex', 'autoload'), true, true); +spl_autoload_register( + function ($class) { + SC_ClassAutoloader_Ex::autoload($class, __DIR__.'/downloads/plugin/'); + }, + true, true +); SC_Helper_HandleError_Ex::load(); // アプリケーション初期化処理 $objInit = new SC_Initial_Ex(); $objInit->init(); - diff --git a/data/class/SC_ClassAutoloader.php b/data/class/SC_ClassAutoloader.php index 9bb7c0916d..cc2b59c700 100644 --- a/data/class/SC_ClassAutoloader.php +++ b/data/class/SC_ClassAutoloader.php @@ -36,7 +36,7 @@ class SC_ClassAutoloader * LC_* には対応していない。 * @return void */ - public static function autoload($class) + public static function autoload($class, $plugin_upload_realdir = PLUGIN_UPLOAD_REALDIR) { $arrClassNamePart = explode('_', $class); $is_ex = end($arrClassNamePart) === 'Ex'; @@ -66,7 +66,7 @@ public static function autoload($class) // プラグイン向けフックポイント // MEMO: プラグインのローダーがDB接続を必要とするため、SC_Queryがロードされた後のみ呼び出される。 // プラグイン情報のキャッシュ化が行われれば、全部にフックさせることを可能に? - $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance(true); + $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance(true, $plugin_upload_realdir); if (is_object($objPlugin)) { // 元の設定を一時保存 $plugin_class = $class; diff --git a/data/class/helper/SC_Helper_Plugin.php b/data/class/helper/SC_Helper_Plugin.php index dfceb9a260..2c8d3be303 100644 --- a/data/class/helper/SC_Helper_Plugin.php +++ b/data/class/helper/SC_Helper_Plugin.php @@ -45,7 +45,7 @@ class SC_Helper_Plugin * @param bool $plugin_activate_flg プラグインを有効化する場合 true * @return void */ - public function load($plugin_activate_flg = true) + public function load($plugin_activate_flg = true, $plugin_upload_realdir = PLUGIN_UPLOAD_REALDIR) { if (!defined('CONFIG_REALFILE') || !file_exists(CONFIG_REALFILE)) return; // インストール前 if (GC_Utils_Ex::isInstallFunction()) return; // インストール中 @@ -53,11 +53,11 @@ public function load($plugin_activate_flg = true) // 有効なプラグインを取得 $arrPluginDataList = SC_Plugin_Util_Ex::getEnablePlugin(); // pluginディレクトリを取得 - $arrPluginDirectory = SC_Plugin_Util_Ex::getPluginDirectory(); + $arrPluginDirectory = SC_Plugin_Util_Ex::getPluginDirectory($plugin_upload_realdir); foreach ($arrPluginDataList as $arrPluginData) { // プラグイン本体ファイル名が取得したプラグインディレクトリ一覧にある事を確認 if (array_search($arrPluginData['plugin_code'], $arrPluginDirectory) !== false) { - $plugin_file_path = PLUGIN_UPLOAD_REALDIR . $arrPluginData['plugin_code'] . '/' . $arrPluginData['class_name'] . '.php'; + $plugin_file_path = $plugin_upload_realdir . $arrPluginData['plugin_code'] . '/' . $arrPluginData['class_name'] . '.php'; // プラグイン本体ファイルが存在しない場合 if (!file_exists($plugin_file_path)) { // エラー出力 @@ -90,7 +90,7 @@ public function load($plugin_activate_flg = true) * @param bool $plugin_activate_flg プラグインを有効化する場合 true * @return SC_Helper_Plugin SC_Helper_Pluginオブジェクト */ - public static function getSingletonInstance($plugin_activate_flg = PLUGIN_ACTIVATE_FLAG) + public static function getSingletonInstance($plugin_activate_flg = PLUGIN_ACTIVATE_FLAG, $plugin_upload_realdir = PLUGIN_UPLOAD_REALDIR) { if (!isset($GLOBALS['_SC_Helper_Plugin_instance'])) { // プラグインのローダーがDB接続を必要とするため、 @@ -101,7 +101,7 @@ public static function getSingletonInstance($plugin_activate_flg = PLUGIN_ACTIVA } $GLOBALS['_SC_Helper_Plugin_instance'] = new SC_Helper_Plugin_Ex(); - $GLOBALS['_SC_Helper_Plugin_instance']->load($plugin_activate_flg); + $GLOBALS['_SC_Helper_Plugin_instance']->load($plugin_activate_flg, $plugin_upload_realdir); } return $GLOBALS['_SC_Helper_Plugin_instance']; diff --git a/data/class/plugin/SC_Plugin_Util.php b/data/class/plugin/SC_Plugin_Util.php index a543b8c5f0..de7a6a53ac 100644 --- a/data/class/plugin/SC_Plugin_Util.php +++ b/data/class/plugin/SC_Plugin_Util.php @@ -124,11 +124,11 @@ public function deletePluginByPluginId($plugin_id) * * @return array $arrPluginDirectory */ - public function getPluginDirectory() + public function getPluginDirectory($plugin_upload_realdir = PLUGIN_UPLOAD_REALDIR) { $arrPluginDirectory = array(); - if (is_dir(PLUGIN_UPLOAD_REALDIR)) { - if ($dh = opendir(PLUGIN_UPLOAD_REALDIR)) { + if (is_dir($plugin_upload_realdir)) { + if ($dh = opendir($plugin_upload_realdir)) { while (($pluginDirectory = readdir($dh)) !== false) { $arrPluginDirectory[] = $pluginDirectory; } diff --git a/tests/class/fixtures/plugin/FixturePlugin/FixturePlugin.php b/tests/class/fixtures/plugin/FixturePlugin/FixturePlugin.php new file mode 100644 index 0000000000..c294ecfb69 --- /dev/null +++ b/tests/class/fixtures/plugin/FixturePlugin/FixturePlugin.php @@ -0,0 +1,11 @@ +objQuery->nextVal('dtb_plugin_plugin_id'); + $pluginValues = [ + 'plugin_id' => $plugin_id, + 'plugin_name' => 'FixturePlugin', + 'plugin_code' => 'FixturePlugin', + 'class_name' => 'FixturePlugin', + 'plugin_version' => '0.0.0', + 'compliant_version' => '2.17', + 'enable' => 1, + 'create_date' => 'CURRENT_TIMESTAMP', + 'update_date' => 'CURRENT_TIMESTAMP' + ]; + $this->objQuery->insert('dtb_plugin', $pluginValues); + + $plugin_hookpoint_id = $this->objQuery->nextVal('dtb_plugin_hookpoint_plugin_hookpoint_id'); + $hookpointValues = [ + 'plugin_hookpoint_id' => $plugin_hookpoint_id, + 'plugin_id' => $plugin_id, + 'hook_point' => 'loadClassFileChange', + 'callback' => 'loadClassFileChange', + 'update_date' => 'CURRENT_TIMESTAMP' + ]; + $this->objQuery->insert('dtb_plugin_hookpoint', $hookpointValues); + } + + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function testLOading() + { + // __DIR__.'/../fixtures/plugin/ に配置したプラグインをオートロード対象にする + spl_autoload_register(function ($class){ + SC_ClassAutoloader_Ex::autoload($class, __DIR__.'/../fixtures/plugin/'); + }, true, true); + + $objCustomer = new SC_Customer_Ex(); + $this->assertInstanceOf('Fixture_SC_Customer', $objCustomer); + $this->assertEquals('loading', $objCustomer->getValue('loading'), __DIR__.'/../fixtures/plugin/Fixture_SC_Customer がロードされる'); + } +} diff --git a/tests/class/plugin/LoadClassFileChangeTest.php b/tests/class/plugin/LoadClassFileChangeTest.php index a9fb59581c..b77b8e17d8 100644 --- a/tests/class/plugin/LoadClassFileChangeTest.php +++ b/tests/class/plugin/LoadClassFileChangeTest.php @@ -32,6 +32,8 @@ protected function tearDown() /** * loadClassFileChange で拡張したクラスのテストケース. + * @runInSeparateProcess + * @preserveGlobalState disabled */ public function testLoadExtendedClass() {