From 2f67b7c6f9db26b199e8b0a83d7839710ef7f562 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Mon, 23 Dec 2019 09:52:42 +0900 Subject: [PATCH 1/4] =?UTF-8?q?=E3=83=97=E3=83=A9=E3=82=B0=E3=82=A4?= =?UTF-8?q?=E3=83=B3=E3=82=92=E4=BB=BB=E6=84=8F=E3=81=AE=E3=83=87=E3=82=A3?= =?UTF-8?q?=E3=83=AC=E3=82=AF=E3=83=88=E3=83=AA=E3=81=AB=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - PLUGIN_UPLOAD_REALDIR を引数で渡せられるよう修正 --- data/app_initial.php | 8 ++++++-- data/class/SC_ClassAutoloader.php | 4 ++-- data/class/helper/SC_Helper_Plugin.php | 10 +++++----- data/class/plugin/SC_Plugin_Util.php | 6 +++--- 4 files changed, 16 insertions(+), 12 deletions(-) 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; } From eac1498481b73c96ab3a015b6778901d798c92f8 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Mon, 23 Dec 2019 09:58:44 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=B1?= =?UTF-8?q?=E3=83=BC=E3=82=B9=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/FixturePlugin/FixturePlugin.php | 13 ++++++ .../FixturePlugin/Fixture_SC_Customer.php | 9 ++++ .../LoadClassFileChangeCustomDirTest.php | 44 +++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 tests/class/fixtures/plugin/FixturePlugin/FixturePlugin.php create mode 100644 tests/class/fixtures/plugin/FixturePlugin/Fixture_SC_Customer.php create mode 100644 tests/class/plugin/LoadClassFileChangeCustomDirTest.php diff --git a/tests/class/fixtures/plugin/FixturePlugin/FixturePlugin.php b/tests/class/fixtures/plugin/FixturePlugin/FixturePlugin.php new file mode 100644 index 0000000000..313539b052 --- /dev/null +++ b/tests/class/fixtures/plugin/FixturePlugin/FixturePlugin.php @@ -0,0 +1,13 @@ +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); + } + + 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 がロードされる'); + } +} From 055240c1169cb473e42731cf1b2f31c40d9c67fe Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Mon, 23 Dec 2019 13:52:03 +0900 Subject: [PATCH 3/4] Add @runInSeparateProcess --- tests/class/plugin/LoadClassFileChangeCustomDirTest.php | 7 +++++++ tests/class/plugin/LoadClassFileChangeTest.php | 2 ++ 2 files changed, 9 insertions(+) diff --git a/tests/class/plugin/LoadClassFileChangeCustomDirTest.php b/tests/class/plugin/LoadClassFileChangeCustomDirTest.php index 245b941ea5..894e42bfbc 100644 --- a/tests/class/plugin/LoadClassFileChangeCustomDirTest.php +++ b/tests/class/plugin/LoadClassFileChangeCustomDirTest.php @@ -1,5 +1,8 @@ objQuery->insert('dtb_plugin_hookpoint', $hookpointValues); } + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + */ public function testLOading() { // __DIR__.'/../fixtures/plugin/ に配置したプラグインをオートロード対象にする 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() { From dcc550d68c895155efa5add95935f0d3d33cb9e2 Mon Sep 17 00:00:00 2001 From: Kentaro Ohkouchi Date: Mon, 23 Dec 2019 13:58:33 +0900 Subject: [PATCH 4/4] Remove --- tests/class/fixtures/plugin/FixturePlugin/FixturePlugin.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/class/fixtures/plugin/FixturePlugin/FixturePlugin.php b/tests/class/fixtures/plugin/FixturePlugin/FixturePlugin.php index 313539b052..c294ecfb69 100644 --- a/tests/class/fixtures/plugin/FixturePlugin/FixturePlugin.php +++ b/tests/class/fixtures/plugin/FixturePlugin/FixturePlugin.php @@ -3,8 +3,6 @@ class FixturePlugin extends SC_Plugin_Base { public function loadClassFileChange(&$classname, &$classpath) { - var_dump($classpath); - if ($classname === "SC_Customer_Ex") { $classpath = "FixturePlugin/Fixture_SC_Customer.php"; $classname = "Fixture_SC_Customer";