微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Go! PHP的AOP库

程序名称:Go!

授权协议: MIT

操作系统: 跨平台

开发语言: PHP

Go! 介绍

Go! 是一个 PHP 5.4 库,让 PHP 支持 AOP 面向方面编程方法,无需 PECL 扩展、Runkit、evals 或者 DI 容器支持。可使用
XDebug 轻松调试。

示例代码

// Aspect/MonitorAspect.PHP

namespace Aspect;

use Go\Aop\Aspect;
use Go\Aop\Intercept\FieldAccess;
use Go\Aop\Intercept\MethodInvocation;
use Go\Lang\Annotation\After;
use Go\Lang\Annotation\Before;
use Go\Lang\Annotation\Around;
use Go\Lang\Annotation\pointcut;

/**
 * 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";
    }
}

Go! 官网

https://github.com/lisachenko/go-aop-php

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐