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

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

内容简介:支持属性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" 来实现,因此业务上可以避免两次问题。


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

查看所有标签

猜你喜欢:

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

An Introduction to the Analysis of Algorithms

An Introduction to the Analysis of Algorithms

Robert Sedgewick、Philippe Flajolet / Addison-Wesley Professional / 1995-12-10 / CAD 67.99

This book is a thorough overview of the primary techniques and models used in the mathematical analysis of algorithms. The first half of the book draws upon classical mathematical material from discre......一起来看看 《An Introduction to the Analysis of Algorithms》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具