Open kiy0taka opened 1 year ago
以下のようにdecorateし、Symfony\EventDispatcherの実装を差し替える
Eccube\EventDispatcher\EventDispatcher: decorates: event_dispatcher decoration_priority: -10
https://github.com/EC-CUBE/next-poc/pull/36
呼び出し側はEccube\EventDispatcherのアダプタ経由でdispatchを呼び出す
public function index(Request $request, \Eccube\EventDispatcher\EventDispatcherAdapter $dispatcher) { ... // FRONT_CONTACT_INDEX_INITIALIZE $event = new EventArgs( [ 'builder' => $builder, ], $request ); $this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_CONTACT_INDEX_INITIALIZE);
拡張側は、Eccube\EventDispatcher\EventSubscriberInterfaceをimplementする
class SampleListener implements \Eccube\EventDispatcher\EventSubscriberInterface { public function onRequest(\Eccube\EventDispatcher\Event $event) { // dump($event); // exit; }
アダプタを作成
EventSubscriberInterfaceを継承したEccubeEventSubscriberInterfaceを作成
interface EccubeEventSubscriberInterface extends EventSubscriberInterface; class Subscriber implements EccubeEventSubscriberInterface { public function getEventSubscriber() { return [KernelEvent::Terminate => 'onTerminate'] } }
RegisterListenersPassでEventSubscriberInterfaceのチェックをしてるので一旦インターフェースの継承で。 https://github.com/symfony/event-dispatcher/blob/6.2/DependencyInjection/RegisterListenersPass.php#L124
KernelEventsの隠蔽も必要
プラグインでも利用しているイベントを洗い出して、イベントごとにEventListenerを用意してもいいかも。
Syfonyイベント
kernel.controller:11 kernel.controller_arguments:11 kernel.request:8 kernel.response:12 kernel.view:3 knp_pager.items:1 security.interactive_login:6 Symfony\Component\Security\Http\Event\CheckPassportEvent:1 Symfony\Component\Security\Http\Event\LoginFailureEvent:1 Symfony\Component\Security\Http\Event\LoginSuccessEvent:3 Symfony\Component\Security\Http\Event\LogoutEvent:3
プラグインでの使用イベント
@CustomerGroup42/admin/Customer/Group/edit.twig:2 @CustomerGroup42/admin/config.twig:1 @EccubePaymentLite42/default/Mypage/edit_credit_card.twig:1 @EccubePaymentLite42/default/Mypage/regular_cancel.twig:2 @EccubePaymentLite42/default/Mypage/regular_complete.twig:2 @EccubePaymentLite42/default/Mypage/regular_cycle.twig:2 @EccubePaymentLite42/default/Mypage/regular_detail.twig:2 @EccubePaymentLite42/default/Mypage/regular_list.twig:1 @EccubePaymentLite42/default/Mypage/regular_next_delivery_date.twig:2 @EccubePaymentLite42/default/Mypage/regular_product_quantity.twig:2 @EccubePaymentLite42/default/Mypage/regular_resume.twig:2 @EccubePaymentLite42/default/Mypage/regular_shipping.twig:2 @EccubePaymentLite42/default/Mypage/regular_skip.twig:2 @EccubePaymentLite42/default/Mypage/regular_suspend.twig:2 @GmoPaymentGateway42/mypage_card.twig:2 @GmoPaymentGatewaySubs42/mypage_subs_order.twig:1 @GmoPaymentGatewaySubs42/mypage_subs_orders.twig:1 @IplPeriodicPurchase42/mypage/cancel.twig:1 @IplPeriodicPurchase42/mypage/complete.twig:1 @IplPeriodicPurchase42/mypage/cycle.twig:1 @IplPeriodicPurchase42/mypage/history.twig:1 @IplPeriodicPurchase42/mypage/index.twig:1 @IplPeriodicPurchase42/mypage/next_shipping.twig:1 @IplPeriodicPurchase42/mypage/products.twig:1 @IplPeriodicPurchase42/mypage/resume.twig:1 @IplPeriodicPurchase42/mypage/shipping.twig:1 @IplPeriodicPurchase42/mypage/skip.twig:1 @IplPeriodicPurchase42/mypage/suspend.twig:1 @MailMagazine42/admin/history_condition.twig:3 @MailMagazine42/admin/index.twig:3 @ProductItem42/admin/Product/template_detail.twig:1 @ProductPlus42/admin/Product/edit.twig:1 @RakutenCard42/mypage_register_card.twig:1 @SlnPayment42/sln_edit_card.twig:1 @SlnRegular4/Mypage/regular_history.twig:1 @SlnRegular4/Mypage/regular_order.twig:1 @SoftbankPayment42/default/mypage/credit/edit.twig:1 @SoftbankPayment42/default/mypage/credit/index.twig:1 @YamatoPayment42/mypage/credit.twig:1 @admin/Content/block.twig:1 @admin/Content/block_edit.twig:1 @admin/Content/layout_list.twig:1 @admin/Content/news.twig:3 @admin/Content/news_edit.twig:3 @admin/Content/page.twig:1 @admin/Content/page_edit.twig:2 @admin/Customer/edit.twig:14 @admin/Customer/index.twig:6 @admin/Order/edit.twig:36 @admin/Order/index.twig:19 @admin/Order/mail.twig:1 @admin/Order/mail_confirm.twig:1 @admin/Order/order_item_prototype.twig:1 @admin/Order/search_product.twig:2 @admin/Order/shipping.twig:9 @admin/Product/category.twig:8 @admin/Product/csv_product.twig:1 @admin/Product/index.twig:12 @admin/Product/product.twig:42 @admin/Product/product_class.twig:15 @admin/Product/tag.twig:1 @admin/Setting/Shop/delivery_edit.twig:9 @admin/Setting/Shop/payment.twig:3 @admin/Setting/Shop/payment_edit.twig:8 @admin/Setting/Shop/shop_master.twig:4 @admin/Setting/System/log.twig:1 @admin/Setting/System/masterdata.twig:1 @admin/Store/plugin.twig:1 @admin/alert.twig:1 @admin/default_frame.twig:1 @admin/index.twig:4 @admin/login.twig:1 Block/cart.twig:2 Block/header.twig:1 Block/paypal_logo.twig:1 Cart/index.twig:22 Contact/complete.twig:3 Contact/confirm.twig:7 Contact/index.twig:9 Coupon42/Resource/template/default/shopping_coupon.twig:1 Entry/activate.twig:3 Entry/complete.twig:3 Entry/confirm.twig:6 Entry/index.twig:9 Forgot/complete.twig:3 Forgot/index.twig:5 Forgot/reset.twig:3 Help/about.twig:3 Help/agreement.twig:3 Help/guide.twig:3 Help/privacy.twig:3 Help/tradelaw.twig:3 JoolenCategoryBannerText42/Resource/template/default/banner_text.twig:1 JoolenCategoryIcon42/Resource/template/default/category_icon_pc.twig:1 JoolenCategoryIcon42/Resource/template/default/category_icon_sp.twig:1 JoolenNoUseOfPointsForProduct42/Resource/template/default/Shopping/shopping_js.twig:1 Mail/order.html.twig:2 Mail/order.twig:2 Mail/shipping_notify.html.twig:2 Mail/shipping_notify.twig:2 Mypage/change.twig:21 Mypage/change_complete.twig:14 Mypage/coupon_list.twig:1 Mypage/delivery.twig:17 Mypage/delivery_edit.twig:17 Mypage/favorite.twig:18 Mypage/history.twig:33 Mypage/index.twig:22 Mypage/login.twig:12 Mypage/point_log.twig:1 Mypage/withdraw.twig:17 Mypage/withdraw_complete.twig:4 Mypage/withdraw_confirm.twig:5 OricoPaymentPlus2/Resource/template/default/Mypage/vt4g_account_id.twig:1 OricoPaymentPlus2/Resource/template/default/Mypage/vt4g_subsc_payment.twig:1 OricoPaymentPlus2/Resource/template/default/Mypage/vt4g_subsc_payment_history.twig:1 Product/detail.twig:47 Product/list.twig:38 Shopping/complete.twig:8 Shopping/confirm.twig:42 Shopping/index.twig:53 Shopping/login.twig:18 Shopping/nonmember.twig:6 Shopping/shipping.twig:3 Shopping/shipping_edit.twig:4 Shopping/shipping_multiple.twig:6 Shopping/shipping_multiple_edit.twig:3 Shopping/shopping_error.twig:4 Symfony\Component\Security\Http\Event\CheckPassportEvent:1 Symfony\Component\Security\Http\Event\LoginFailureEvent:1 Symfony\Component\Security\Http\Event\LoginSuccessEvent:3 Symfony\Component\Security\Http\Event\LogoutEvent:3 VeriTrans4G2/Resource/template/default/Mypage/vt4g_account_id.twig:1 VeriTrans4G2/Resource/template/default/Mypage/vt4g_subsc_payment.twig:1 VeriTrans4G2/Resource/template/default/Mypage/vt4g_subsc_payment_history.twig:1 admin.admin.index.order:1 admin.admin.index.sales:1 admin.content.block.delete.complete:2 admin.content.block.edit.complete:2 admin.content.news.edit.complete:4 admin.content.page.delete.complete:1 admin.content.page.edit.complete:1 admin.content.page.edit.initialize:1 admin.customer.csv.export:2 admin.customer.delete.complete:4 admin.customer.edit.index.complete:7 admin.customer.edit.index.initialize:4 admin.customer.index.initialize:2 admin.customer.index.search:1 admin.order.csv.export.order:5 admin.order.csv.export.shipping:2 admin.order.edit.index.complete:10 admin.order.edit.index.initialize:3 admin.order.edit.index.progress:1 admin.order.edit.search.customer.search:1 admin.order.edit.search.product.complete:1 admin.order.edit.search.product.search:2 admin.order.index.initialize:2 admin.order.index.search:3 admin.order.mail.index.initialize:2 admin.product.category.delete.complete:3 admin.product.category.index.complete:5 admin.product.copy.complete:15 admin.product.csv.export:6 admin.product.delete.complete:5 admin.product.edit.complete:14 admin.product.edit.initialize:3 admin.product.index.initialize:1 admin.product.index.search:1 admin.setting.shop.delivery.edit.complete:3 admin.setting.shop.payment.delete.complete:1 admin.setting.shop.payment.edit.complete:2 admin.setting.system.log.index.initialize:1 admin.setting.system.member.delete.complete:1 csvimportproductext.admin.product.csv.import.product.check:9 csvimportproductext.admin.product.csv.import.product.descriptions:9 csvimportproductext.admin.product.csv.import.product.process:10 default/index.twig:1 default_frame.twig:4 deliverycool.delivery_free.condition:1 deliverydate.getformdeliverydates:1 deliveryplus.service.delivery.select:1 expresslink.admin.order.csv.export.initialize:2 front.cart.buystep.complete:3 front.cart.buystep.initialize:1 front.contact.index.complete:3 front.contact.index.initialize:2 front.entry.activate.complete:4 front.entry.index.complete:10 front.entry.index.initialize:2 front.forgot.index.complete:1 front.mypage.change.index.complete:7 front.mypage.change.index.initialize:2 front.mypage.delivery.edit.complete:2 front.mypage.delivery.edit.initialize:1 front.mypage.mypage.favorite.search:1 front.mypage.mypage.index.search:4 front.mypage.mypage.order.initialize:1 front.mypage.withdraw.index.complete:7 front.mypage.withdraw.index.initialize:1 front.product.cart.add.complete:2 front.product.cart.add.initialize:3 front.product.detail.initialize:5 front.product.index.initialize:3 front.product.index.search:9 front.shopping.complete.initialize:11 front.shopping.login.initialize:1 front.shopping.nonmember.complete:1 front.shopping.shipping.complete:1 front.shopping.shipping.edit.complete:1 front.shopping.shipping.edit.initialize:1 front.shopping.shipping.multiple.complete:3 front.shopping.shipping.multiple.initialize:1 index.twig:6 kernel.controller:11 kernel.controller_arguments:11 kernel.request:8 kernel.response:12 kernel.view:3 knp_pager.items:1 mail.admin.customer.confirm:2 mail.admin.order:1 mail.contact:1 mail.customer.confirm:2 mail.order:3 plugin.contact.index.complete:1 point_ex_dx.hook_states:1 pointexpired.service.getperiod:1 security.interactive_login:6 sln.service.regular.mypage_history.change_payids:1 sln.service.regular.nextorder.complete:1 workflow.order.completed:1 workflow.order.transition.back_to_in_progress:5 workflow.order.transition.cancel:6 workflow.order.transition.cancel_return:3 workflow.order.transition.pay:1 workflow.order.transition.return:4 workflow.order.transition.ship:5
Symfony\Component\EventDispatcher\EventDispatcher
以下のようにdecorateし、Symfony\EventDispatcherの実装を差し替える
https://github.com/EC-CUBE/next-poc/pull/36
呼び出し側はEccube\EventDispatcherのアダプタ経由でdispatchを呼び出す
拡張側は、Eccube\EventDispatcher\EventSubscriberInterfaceをimplementする
Symfony\Component\EventDispatcher\EventDispatcherInterface
アダプタを作成
Symfony\Component\EventDispatcher\EventSubscriberInterface
EventSubscriberInterfaceを継承したEccubeEventSubscriberInterfaceを作成
RegisterListenersPassでEventSubscriberInterfaceのチェックをしてるので一旦インターフェースの継承で。 https://github.com/symfony/event-dispatcher/blob/6.2/DependencyInjection/RegisterListenersPass.php#L124
KernelEventsの隠蔽も必要
プラグインでも利用しているイベントを洗い出して、イベントごとにEventListenerを用意してもいいかも。
Syfonyイベント
プラグインでの使用イベント