a “plugin” refers to a special class that’s listening for any public method call to another object.
We say any public method, but that’s not quite accurate. If the public method uses the final
keyword, or the class itself uses the final
keyword, you won’t be able to use a plugin. 

创建 plugin:



在 var/generation 下自定生成。

将有和父类一样的行为。

Plugins: After Methods:改变返回值

#File: app/code/Pulsestorm/TutorialPlugin/Model/Example/Plugin.php
<?php
namespace Pulsestorm\TutorialPlugin\Model\Example;
class Plugin
{public function afterGetMessage($subject, $result){echo "Calling " , __METHOD__,"\n";return $result;}
}

驼峰命名,
第一个参数,为 Interceptor.php
第二个参数 , $result 是原先方法访问的结果。

Since we returned $result above, our after plugin method didn’t change any behavior.
Let’s try actually changing something.Edit your afterGetMessage method so it matches the following
#File: app/code/Pulsestorm/TutorialPlugin/Model/Example/Plugin.php
public function afterGetMessage($subject, $result)
{        return 'We are so tired of saying hello';
} 

You just used a plugin to change the value returned by the getMessage method.
通过 plugin 改变返回结果。

Plugins: Before Methods:改变参数

#File: app/code/Pulsestorm/TutorialPlugin/Model/Example/Plugin.php
<?php
namespace Pulsestorm\TutorialPlugin\Model\Example;
class Plugin
{   public function beforeGetMessage($subject, $thing='World', $should_lc=false){echo "Calling " . __METHOD__,"\n";}
}

第一个参数: Interceptor.php
显而易见,没有$resutl 参数,
后面的参数匹配原先方法的参数,包括默认值

 return 数组;来改变传入的参数。


Plugins: Around Methods

第一个参数是,Interceptor.php
第二个参数是 php 匿名函数
...



同时重写一个方法:


注意:

First, the interceptor class that makes this all possible is generated code, which means
if the class you’re observing with a plugin
changes — you’ll need to regenerate the interceptor.
如果需要观察plugin改变带来的变化,需要重新生成拦截器
Next, with plugins (vs. rewrites) you lose the ability to change the behavior of a protectedmethod. Some will see this as acon (less flexibility), and some will see this a pro (respecting the protected access levels). It you need to change the behaviorof a protected method, class preferences or argument replacement are more suitable tools.
如果 需要改变 protected 方法,class preference 或者 argument replacement是更好的选择。

24.Plugin System相关推荐

  1. (24)System Verilog多个线程间通信(信箱)

    (24)System Verilog多个线程间通信(信箱) 1.1 目录 1)目录 2)FPGA简介 3)System Verilog简介 4)System Verilog多个线程间通信(信箱) 5) ...

  2. (24)System Verilog设计十进制计数器

    (24)System Verilog设计十进制计数器 1.1 目录 1)目录 2)FPGA简介 3)System Verilog简介 4)System Verilog设计十进制计数器 1.十进制计数器 ...

  3. Kubernetes CKS【24】---System Hardening - Kernel Hardening Tools(seccomp)

    文章目录 1. Seccomp介绍 2. 目标 3. Seccomp for Docker Nginx 4. 启用 RuntimeDefault 5. 创建 Seccomp 文件 6. Kind 创建 ...

  4. java计算24小时之内_java的系统时间,怎么计算从现在到凌晨还剩下多少时间?

    Apache commons-lang3 long milliSecondsLeftToday = 86400000 -DateUtils.getFragmentInMilliseconds(Cale ...

  5. Android Studio 自定义Gradle Plugin

    一.简介 之前公司的一个项目需要用到Gradle插件来修改编译后的class文件,今天有时间就拿出来整理一下,学习一下Gradle插件的编写还是一件十分有意义的事. 二.Gradle插件类型 一种是直 ...

  6. C#中获取当前时间:System.DateTime.Now.ToString()用法

    //2008年4月24日 System.DateTime.Now.ToString("D"); //2008-4-24 System.DateTime.Now.ToString(& ...

  7. java学习--基础知识进阶第五天--API、 Object类 System类、日期相关类、包装类正则表达式...

    今日内容介绍 u  Object类 & System类 u  日期相关类 u  包装类&正则表达式 第1章 Object类 & System类 1.1 Object类 1.1. ...

  8. 华为擎云 W510 鲲鹏 920 24 核工作站使用体验

    有幸搞到了一台华为擎云W510主机,鲲鹏920 24核 ARM64 处理器,8G内存,AMD R5-230 1GB 亮机卡. 自带的 UOS专业版系统激活过期了,想着装别的系统吧,结果发现 Ubunt ...

  9. c语言实现简单的24点游戏

    题目叙述:24点游戏是经典的纸牌益智游戏. 常见游戏规则: 从扑克中每次取出4张牌.使用加减乘除,第一个能得出24者为赢.(其中,J代表11,Q代表12,K代表13,A代表1),按照要求编程解决24点 ...

  10. yyyymmddhhmmss时间格式12小时制24小时制区别

    yyyymmddhhmmss时间格式12小时制24小时制区别,直接看代码:注意字母的大小写 public static void main(String[] args) {String s1 = fo ...

最新文章

  1. SpringMVC-方法四种类型返回值总结,你用过几种?
  2. 课时57.HTML被废弃的标签(掌握)
  3. Python 多版本共存问题
  4. 用TensorFlow做Kaggle“手写识别”达到98%准确率-详解
  5. 常年“盘踞”数据库前五的 MongoDB,在中国有哪些新动向?
  6. java的import和python的import对比_Java中的Import和Pacakge作用生动详解(感觉python中的import作用差不多)...
  7. ASP.NET Web API 提升性能的方法实践
  8. 程序员面试金典——7.2碰撞的蚂蚁
  9. pci串行端口找不到驱动程序_科普:PCI-E插槽都有哪些样子?
  10. 网络_连接路由器的每台电脑使用固定IP的方法(TP-LINK)
  11. caffe 官方例程之R-CNN(物体检测)
  12. 读《人工智能,李开复王咏刚》
  13. 平面设计个人简历模板
  14. c语言汉字属于什么类型_带你学习C语言—数据类型
  15. 数据分析之 AB测试(AB Test)
  16. 西安交大计算机考研分数线2020院线,2020西安交通大学考研复试分数线已公布
  17. Python初学者之路--range函数、切片、if-elif语句
  18. Nginx源码阅读:ngx_palloc 内存池
  19. java毕业设计商品供应管理系统mybatis+源码+调试部署+系统+数据库+lw
  20. Windows Mobile 开发常见问题集(转自zsu_darkwind的专栏)

热门文章

  1. Android 使用SwipeBackLayout实现滑动返回上一级页面——实战来袭
  2. OFbiz--HelloWorld
  3. 用标准C编写COM dll
  4. tyvj p1016 装箱问题( 简单DP 01背包)
  5. IT男,程序猿在婚恋市场有多受欢迎?
  6. MySQL技术内幕 InnoDB存储引擎【二】后台线程
  7. [Codeforces]860E Arkady and a Nobody-men
  8. 最全的HTTP1.1状态码
  9. 【看别人的,学习】文本增强,再也不怕用户要修改标准界面的字段描述了
  10. nodeAPI--TCP