aop-io / php-aop
实现了 AOP(面向方面编程)简化子集,并为 PHP 提供了 AOP 特性。
v0.1
2014-08-14 15:01 UTC
Requires
- php: >=5.4
Suggests
- aop-io/pecl-aop-interceptor: Interceptor using the PECL AOP extension.
This package is auto-updated.
Last update: 2024-09-05 22:37:31 UTC
README
实现了 AOP(面向方面编程)简化子集,并为 PHP 应用程序提供了 AOP 特性。
只有一个依赖项,即 代码拦截器。
AOP.io 的 PHP 库提供了一层易于使用的抽象层,以便于 AOP 开发,因此它可以与多个 PHP 代码拦截器一起工作。
首先实现的拦截器使用 PECL AOP-PHP 扩展。
计划实现其他拦截器。如果您想创建一个拦截器,请参阅 骨架。
入门
安装
-
安装一个拦截器,例如: PECL AOP-PHP 扩展。
-
下载 PHP AOP.io 库(并配置您的自动加载器)或使用 composer
require: "aop-io/php-aop"
。
用法
use Aop\Aop; // Init new Aop(); function hello($name) { return $name } // Interception of kind 'around' Aop::addAround('hello()', function($joinPoint) { // In this context, // $joinPoint is an instance of \Aop\JoinPoint\AroundFunctionJoinPoint // get an array with all arguments values var_dump($joinPoint->getArgs()); // (array) 0 => World ! // change the return value $joinPoint->setReturnValue('Hello Nico !'); // Proceed the execution of the function ( hello() ) $joinPoint->proceed(); }); echo hello('World !'); // Hello Nico !
许可
MIT (c) 2013, Nicolas Tallefourtane.