Ticket #1692 (assigned 新規開発) — at Version 24

Opened 14 years ago

Last modified 14 years ago

プラグイン機能

Reported by: h_yoshimoto Owned by: h_yoshimoto
Priority: Milestone: EC-CUBE2.12.0
Component: その他 Version: 2.12.0 α
Keywords: Cc:
修正済み: yes

Description (last modified by AMUAMU) (diff)

■プラグイン機能仕様書

 http://downloads.ec-cube.net/src/manual/12.0_plugin/plugin.pdf

 http://downloads.ec-cube.net/src/manual/12.0_plugin/hook_point.pdf
※動的なフックポイント生成に r21743 にて切り替えた為、もし一覧にあって呼出が無いフックポイントがありましたら、御報告を下さい。

●プラグイン・エンジン
プラグイン機能のコア

●フックポイント
フックポイントを使ってプラグインは処理に介入します。

●トランスフォーマー(ヘルパー)
プラグインがテンプレートを変更する際に仕様するインターフェイス

以下のチケットを統合しました
#1603 #1632 #1686 #1687

Change History

comment:1 Changed 14 years ago by h_yoshimoto

  • Description modified (diff)

comment:2 Changed 14 years ago by h_yoshimoto

  • Status changed from new to assigned

comment:3 Changed 14 years ago by h_yoshimoto

  • Version changed from 2.11.4 to 2.12.0 α

comment:4 Changed 14 years ago by h_yoshimoto

  • Description modified (diff)

comment:5 Changed 14 years ago by kajiwara

  • Description modified (diff)

comment:6 follow-up: ↓ 7 Changed 14 years ago by Seasoft

動作未確認ですが、ソース査読にて lc_page_products_list_action_end が2連続実行しているように思います。

comment:7 in reply to: ↑ 6 Changed 14 years ago by h_yoshimoto

Seasoft への返信

動作未確認ですが、ソース査読にて lc_page_products_list_action_end が2連続実行しているように思います。

ありがとうございます。r21669 にて対応させて頂きました。

comment:8 Changed 14 years ago by h_yoshimoto

r21671 にて各プラグインの設定画面を呼び出し方を変更。モジュール同様に認証可否判定を通るようにしました。

comment:9 follow-up: ↓ 11 Changed 14 years ago by h_yoshimoto

プラグイン機能のクラス設計について

現状のSC_Helper_Pluginには
プラグインエンジンとしての役割(各Pageクラスで使用)と
DBからデータ取得などの役割(Pageクラス・エンジン部分で使用)
が混同しています。

そこで、エンジン部分とデータ取得部分を分離させようかと考えています。
以下の仕様で考えていますが、いかがでしょうか?

エンジン部分→SC_Helper_Plugin
データ取得部分→data/plugin/SC_Plugin.phpを作成。

ご懸念される点がございましたら、ご意見頂ければと思います。

問題無ければ進めさせて頂きます。

comment:10 Changed 14 years ago by h_yoshimoto

r21672 にてregistをregisterに変更
合わせてサンプルプラグインも修正

Changed 14 years ago by eccuore

uninstall時の処理追加、addActionでpriority追加、prefilterTransformにreplaceElementのパターンとinsertAfterのパターンを追加

comment:11 in reply to: ↑ 9 Changed 14 years ago by h_yoshimoto

h_yoshimoto への返信

プラグイン機能のクラス設計について

現状のSC_Helper_Pluginには
プラグインエンジンとしての役割(各Pageクラスで使用)と
DBからデータ取得などの役割(Pageクラス・エンジン部分で使用)
が混同しています。

そこで、エンジン部分とデータ取得部分を分離させようかと考えています。
以下の仕様で考えていますが、いかがでしょうか?

エンジン部分→SC_Helper_Plugin
データ取得部分→data/plugin/SC_Plugin.phpを作成。

ご懸念される点がございましたら、ご意見頂ければと思います。

問題無ければ進めさせて頂きます。

r21681 にて対応しました。

comment:12 Changed 14 years ago by h_yoshimoto

r21689 にてプラグインエンジンのインスタンス生成時の処理を統一

comment:13 Changed 14 years ago by h_yoshimoto

21693 r21694 にてフックポイント名を変更

comment:14 Changed 14 years ago by h_yoshimoto

  • Description modified (diff)

comment:15 Changed 14 years ago by h_yoshimoto

  • Description modified (diff)

comment:16 Changed 14 years ago by Yammy

SLTEXT_LEN という TYPO があったので、r21705 で修正しておきました。

comment:17 Changed 14 years ago by adachi

TO:h_yoshimoto

SC_Plugin_Util::deletePluginByPluginIdで、commitし忘れているようにみえるのですが、これはあってます?

    function deletePluginByPluginId($plugin_id) {
        $objQuery =& SC_Query_Ex::getSingletonInstance();
        $objQuery->begin();
        $where = 'plugin_id = ?';
        $objQuery->delete('dtb_plugin', $where, array($plugin_id));
        $objQuery->delete('dtb_plugin_hookpoint', $where, array($plugin_id));
    }

comment:18 follow-up: ↓ 19 Changed 14 years ago by adachi

CategoryContents?でWaringがぽろぽろ

2012/04/09 01:06:21 [/products/list.php] Warning(E_WARNING): Missing argument 3 for SC_Helper_Plugin::addAction(), called in /mnt/NetBeans/version-2_12-dev/data/downloads/plugin/CategoryContents/CategoryContents.php on line 168 and defined on [/mnt/NetBeans/version-2_12-dev/data/class/helper/SC_Helper_Plugin.php(154)] from 192.168.56.1
2012/04/09 01:06:22 [/products/list.php] Warning(E_WARNING): array_key_exists() [<a href='function.array-key-exists'>function.array-key-exists</a>]: The second argument should be either an array or an object on [/mnt/NetBeans/version-2_12-dev/data/class/helper/SC_Helper_Transform.php(483)] from 192.168.56.1

comment:19 in reply to: ↑ 18 Changed 14 years ago by h_yoshimoto

adachi さんへの返信

CategoryContents?でWaringがぽろぽろ

2012/04/09 01:06:21 [/products/list.php] Warning(E_WARNING): Missing argument 3 for SC_Helper_Plugin::addAction(), called in /mnt/NetBeans/version-2_12-dev/data/downloads/plugin/CategoryContents/CategoryContents.php on line 168 and defined on [/mnt/NetBeans/version-2_12-dev/data/class/helper/SC_Helper_Plugin.php(154)] from 192.168.56.1
2012/04/09 01:06:22 [/products/list.php] Warning(E_WARNING): array_key_exists() [<a href='function.array-key-exists'>function.array-key-exists</a>]: The second argument should be either an array or an object on [/mnt/NetBeans/version-2_12-dev/data/class/helper/SC_Helper_Transform.php(483)] from 192.168.56.1

ご報告ありがとうございます。
r21728 にて対応致しました。

comment:20 Changed 14 years ago by h_yoshimoto

  • Description modified (diff)
  • Summary changed from プラグイン機能(α版) to プラグイン機能

comment:21 Changed 14 years ago by AMUAMU

r21742 にて、SC_系のクラス読込をフックする機能を追加しました。

●概要
クラスの読み込み変更は、PHPのオートロード機能に介入する形で行われます。

●使用方法
使用するには他のフックポイントと同様にプラグインのregist関数に定義します。フックポイント名は「loadClassFileChange」

        $objHelperPlugin->addAction('loadClassFileChange', array(&$this, 'loadClassFileChange'), 1);

対応するコールバック関数を定義します。
定義されたコールバック関数には以下のパラメーターが渡されます。
$classname / 読み込む事を要求されたクラスの名前
$classpath / 本来読み込む予定であるクラスファイルのパス
処理例

    function loadClassFileChange(&$classname, &$classpath) {
        if($classname == 'SC_Customer_Ex') { // 変えたいクラス名でフィルタ,*_Exにフィルタ推奨
            // 代替読み込みされるクラスファイルを用意
            $classpath = PLUGIN_UPLOAD_REALDIR . "CategoryContents/SC_MyCustomer.php";
            // 上で指定した代替読み込みされるファイル内のクラス名が、本来の読み込み先と違うクラス名の場合、$classname を変更するクラス名にする。
            $classname = 'SC_MyCustomer';
        }
    }

このコールバック関数では、特別な処理がされますので注意が必要です。
(1)$classname が本来読み込むクラスと別の名前を設定して関数が終わった場合

→ 自動的に、本来読み込む予定だったSC_XXXX_Exのextends を新しく指定された$classname に書き換えます。これにより、下記のようなextends関係になります。

SC_XXXX_Ex -> SC_XXXX の関係から、 SC_XXXX_Ex -> $classname (-> SC_XXXX) と変える。

$classname で新しく指定されたクラスは、_ExではないSC_をextendsしていることが推奨される。

(2)$classname が本来読み込むクラスと同名の場合

新しく指定された$classpath のみが読み込まれます。
_Exは無視されますが、_Ex無視はカスタマイズをする人から分かりにくくなるため(1)の利用方法が望ましいです。

comment:22 Changed 14 years ago by AMUAMU

SC_系のクラス読込をフックする機能の注意点 ・全てのクラスがフックされるわけではないです。
現状ではDB接続が有効になった後に遅延ロードされるクラスのみとなります。
代表的な部分: SC_Customer_Ex 、SC_View_Ex、SC_SiteView_Ex、SC_AdminView_Ex、SC_Helper_Customer_Ex、SC_PageNavi_Ex、SC_CheckError_Ex、SC_Product_Ex、SC_FormParam_Ex、SC_Cookie_Ex、SC_SiteSession_Ex、SC_Helper_Purchase_Ex、SC_SendMail_Ex、SC_Helper_Mail_Ex、PEARモジュール系、などなど

comment:23 Changed 14 years ago by AMUAMU

補足:クラス読込をフックする機能は、動作の根幹に介入する処理のため慎重に取り扱いをしましょう

Changed 14 years ago by AMUAMU

SC系クラスフックのサンプル

comment:24 Changed 14 years ago by AMUAMU

  • Description modified (diff)
Note: See TracTickets for help on using tickets.