Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

プラグインを任意のディレクトリに配置できるように修正 #360

Merged
merged 4 commits into from
May 28, 2020

Conversation

nanasess
Copy link
Contributor

従来、プラグインは data/downloads/plugin 以下に配置する必要があったが、この修正で任意のディレクトリに配置可能となる。

以下のようなケースで有用

  • テストケースの中で loadClassFileChange を利用したい場合
  • プラグインを Composer で管理したい場合

data/app_initial.php では、PLUGIN_UPLOAD_REALDIR がまだ定義されていないため、定数を使用せずにデフォルトのプラグインディレクトリを設定している

@nobuhiko
Copy link
Contributor

Composer で管理したい場合は本体に手を入れる必要があるということでしょうか?

@nanasess
Copy link
Contributor Author

nanasess commented Dec 24, 2019

@nobuhiko そうですね。今のところは autoload の定義を app_initial.php とかに書いておく必要があります

// vendor/nanasess 以下のプラグインを読み込む
spl_autoload_register(
     function ($class) {
         SC_ClassAutoloader_Ex::autoload($class, __DIR__.'/vendor/nanasess/');
     },
     true, true
 );

plugin_info.php とかを自動的に探しにいってもいいですが、 ボトルネックの方が大きいかなと

@nanasess
Copy link
Contributor Author

@nobuhiko プラグイン側の composer.json に autoload の定義を書いて、その中で spl_autoload_register() をコールしてやれば、本体に手を入れなくても Composer で管理できそうです。

プラグインのcomposer.json

    "autoload": {
        "files": [
            "bootstrap.php"
        ]
    },

bootstrap.php

<?php
spl_autoload_register(
     function ($class) {
         SC_ClassAutoloader_Ex::autoload($class, __DIR__.'/../');
     },
     true, true
 );

@nobuhiko
Copy link
Contributor

@nanasess 自動的に探しには重いので論外として、置くだけじゃ結局動かないのがなんとも

@nanasess
Copy link
Contributor Author

@nobuhiko この修正は、メソッド内で定数を使用するのをやめて、テストしやすくするのが主目的なので、、プラグインを Composer で完全に管理できるようにするには、プラグインインストーラまわりも手を入れる必要がありそうです

spl_autoload_register(array('SC_ClassAutoloader_Ex', 'autoload'), true, true);
spl_autoload_register(
function ($class) {
SC_ClassAutoloader_Ex::autoload($class, __DIR__.'/downloads/plugin/');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここは PLUGIN_UPLOAD_REALDIR じゃないんですか?
もしくは引数なしか

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PLUGIN_UPLOAD_REALDIR が定義される前のタイミングなので、やむなく😥

@okazy okazy merged commit 1b7d82b into EC-CUBE:master May 28, 2020
@okazy
Copy link
Contributor

okazy commented May 28, 2020

ありがとうございます。マージしました。

@nanasess nanasess deleted the improve/plugin-loader branch October 3, 2022 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants