PHP AOP 扩展 Xaop 现在支持属性 AOP 模式啦

栏目: Java · 发布时间: 7年前

内容简介:支持属性AOP模式之前,Xaop仅支持方法的切入(文档注释注解模式 与 方法注入两种模式的 AOP),现在已经支持属性的AOP啦,下面来一个demo示例:属性切入AOP模式下,回调函数支持匿名函数与数组模式的回调函数也就是如下两种模式都支持:回调函数包含有两个参数:

支持属性AOP模式之前,Xaop仅支持方法的切入(文档注释注解模式 与 方法注入两种模式的 AOP),现在已经支持属性的AOP啦,下面来一个demo示例:

class Swing
{
    public $di;
}

Xaop::addPropertyBeforeReadAop(Swing::class, "di", function($object, $prop){
    var_dump($object, $prop);
    echo 'hello';
});
Xaop::addPropertyAfterReadAop(Swing::class, "di", function(){
    echo 'afterRead';
});

$swing = new Swing();
$swing->di;

属性切入AOP模式下,回调函数支持匿名函数与数组模式的回调函数也就是如下两种模式都支持:

Xaop::addPropertyBeforeReadAop(Swing::class, "di", function($object, $prop){
    var_dump($object, $prop);
    echo 'hello';
});

Xaop::addPropertyBeforeReadAop(Swing::class, "di", [ Swing::class, "_before" ]);

回调函数包含有两个参数: $object , $propertyName 分别表示 属性所属的类的对象属性方法名称。

在属性AOP模式下,没有实现环绕模式的原因在于考虑到可以使用魔术方法 "__get" 与 "__set" 来实现,因此业务上可以避免两次问题。


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Writing Windows VxDs and Device Drivers, Second Edition

Writing Windows VxDs and Device Drivers, Second Edition

Karen Hazzah / CMP / 1996-01-12 / USD 54.95

Software developer and author Karen Hazzah expands her original treatise on device drivers in the second edition of "Writing Windows VxDs and Device Drivers." The book and companion disk include the a......一起来看看 《Writing Windows VxDs and Device Drivers, Second Edition》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码