Go! 是一个 PHP 5.4 库,让 PHP 支持 AOP 面向方面编程方法,无需 PECL 扩展、Runkit、evals 或者 DI 容器支持。可使用 XDebug 轻松调试。
示例代码:
// Aspect/MonitorAspect.phpnamespace Aspect;use GoAopAspect;use GoAopInterceptFieldAccess;use GoAopInterceptMethodInvocation;use GoLangAnnotationAfter;use GoLangAnnotationBefore;use GoLangAnnotationAround;use GoLangAnnotationPointcut;/** * Monitor aspect */class MonitorAspect implements Aspect{ /** * Method that will be called before real method * * @param MethodInvocation $invocation Invocation * @Before("execution(public Example->*(*))") */ public function beforeMethodExecution(MethodInvocation $invocation) { $obj = $invocation->getThis(); echo 'Calling Before Interceptor for method: ', is_object($obj) ? get_class($obj) : $obj, $invocation->getMethod()->isStatic() ? '::' : '->', $invocation->getMethod()->getName(), '()', ' with arguments: ', json_encode($invocation->getArguments()), "<br>n"; }}