LoginSignup
6
6

More than 5 years have passed since last update.

EC-CUBE3プラグイン機構

Last updated at Posted at 2015-07-07

プラグイン機構

プラグインの種類

  • ミドルウェア
    • before()
    • after()
  • FormEvent
    • PRE_SET_DATA
    • POST_SET_DATA
    • PRE_SUBMIT
    • SUBMIT
    • POST_SUBMIT
  • EccubeEvent
    • OrderService::commit()
  • ExtRouting
  • ExtController
  • ExtView

設定ファイル

利用方法

利用するプラグイン機構を必要に応じて記載する。
複数組み合わせることも可能

# /app/plugin/{plugin_name}/config.yml
name: SampleEvent
enable: false
service: 
    - SamplePluginServiceProvider
orm.path:
    - /Resource/doctrine
form:
    onPreSetData:
        SampleForm
  • name
    • 必須
    • プラグイン名(たしか、現状ではディレクトリ名と合わせる必要がある)
  • enable
    • 必須
    • 有効化フラグ(true: 有効 / false: 無効)
  • service
    • 複数指定可能
    • SilexのServiceとして登録したいものをまとめたファイルを指定。( .php は不要)
    • Silex\ServiceProviderInterface を継承している必要がある
    • 新規ページ追加や、既存URL誘導の変更を想定
  • orm.path
    • 複数指定可能
    • プラグインとして追加したいテーブルの定義(metadata)ファイルの配置場所を指定
    • プラグインインストール時に読み込まれ、作成されることを想定
  • form
    • FormEvent利用の記載がされているファイルを指定( .php は不要)
    • 各methodは Symfony\Component\Form\FormEvent 型の引数をとる
    • 現状では、実装上の問題があり、複数のファイルから呼ばれる別methodも同一のファイルに記載する必要がある
# /app/Plugin/{plugin_name}/event.yml
eccube.event.render.admin_product_category_edit.before:
    - [onRenderAdminProductCategoryEditBefore, NORMAL]
eccube.event.controller.admin_product_category_edit.after:
    - [onAdminProductCategoryEditAfter, NORMAL]
eccube.event.render.product_list.before:
    - [onRenderProductListBefore, NORMAL]

  • 2.13系のHookPointの役割を想定

インストール

2015/05/25現在では、インストールの仕組みがなく、

vendor/bin/doctrine orm:schema-tool:update にてプラグイン用のテーブルを作成することを想定している。

initialize.php などを規定し、インストールさせるのが妥当?

ミドルウェア

各ルーティングに処理が渡る前後と、全ルーティングに処理が渡る前後で利用できるフックポイントを用意。
全体、もしくは各ルーティングの前後処理を入れる際に利用する。
想定処理が共通化されないため、引数をとっていない。

発火順は以下のとおり。
* eccube.app.before
* eccube.event.{_route}.before
* eccube.event.{_route}.after
* eccube.app.after

利用方法
public static function getSubscribedEvents()
{
    // イベントを登録
    return array(
        'eccube.event.controller.cart.before' => array(
            // メソッド名, 優先順位
            array('onCartIndexBefore', 10),
        ),
);

public function onCartIndexBefore()
{
    // 処理
}

FormEvent

Formに対する動作を監視し、発火するEventを定義することができる。

利用方法

ミドルウェア とかぶるため割愛

EccubeEvent

EC-CUBEとして独自においた、処理の中間でも発火するイベント。
現状、決済プラグインからの利用を想定し、 OrderService::commit() のみ置いている。

利用方法

ミドルウェア とかぶるため割愛

ExtRouting

ルーティングの拡張を行う。
プラグイン同時のServiceProviderを定義し、ルーティングに割り込ませる。
EC-CUBE本体のルーティングより優先して読み込まれる。
ルーティングの仕組み自体が、マッチング時点で他を読み込まなくなる仕様のため、
同一のルーティングを拡張しようとした場合は、先に読み込まれたものが優先されてしまう。

利用方法
class SampleServiceProvider implements ServiceProviderInterface
{
    public function register(BaseApplication $app)
    {
        $app->match('/payment/install', '\\Plugin\\Sample\\Controller\\SampleController::index')->bind('sample_index');

ExtController

同上

ExtView

レンダ前ミドルウェア eccube.{_route}.render.before を利用する、実際にレスポンスに乗る直前のソースを加工することができる。

6
6
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6