V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
yakczh
V2EX  ›  问与答

php 怎么实现 aop 呢?

  •  
  •   yakczh · 2015-07-21 11:30:12 +08:00 · 1087 次点击
    这是一个创建于 3203 天前的主题,其中的信息可能已经有所发展或是发生改变。

    大部分框架是通过硬编码还实现的 比如
    public function run()

    {

    if($this->hasEventHandler('onBeginRequest'))

    $this->onBeginRequest(new CEvent($this));

    $this->processRequest();

    if($this->hasEventHandler('onEndRequest'))

    $this->onEndRequest(new CEvent($this));

    }

    如果要加入其他事件,或者扩展参数,就无能为力了
    怎么样才能自动实现在一个方法中 动态注入一段代码呢?

    比如 function test(){

    echo "orgin call";
    

    }

    在这个方法上,如何执行一段打印日志的代码,而不用修改原来的代码

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   994 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 19:19 · PVG 03:19 · LAX 12:19 · JFK 15:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.