yakczh
V2EX  ›  问与答

php 怎么实现 aop 呢?

  •  
  •   yakczh · Jul 21, 2015 · 1435 views
    This topic created in 3983 days ago, the information mentioned may be changed or developed.

    大部分框架是通过硬编码还实现的 比如
    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";
    

    }

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

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3196 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 12:38 · PVG 20:38 · LAX 05:38 · JFK 08:38
    ♥ Do have faith in what you're doing.