minor提供了一个类似于java中invocationhandler接口和一个proxy类的代理模式的实现,具体可参考我的这篇文章:http://www.cnblogs.com/orlion/p/5350752.html
6.1.1 使用
class foocontroller extends controller{ publicfunction bar($productname) { $log = new loghandler(); $shop = new shop(); $shopproxy = proxy::newproxyinstance($shop, $log); $shopproxy->buy($productname); }}
phpnamespace app\lib;use minor\proxy\invocationhandler;class loghandler implements invocationhandler{ publicfunction invoke($target, \reflectionmethod $method, array$args = []) { $this->before(); $result = $method->invokeargs($target, $args); $this->after(); return$result; } publicfunction before() { echo '[loghandler] before
'; } publicfunction after() { echo '[loghandler] after
'; }}
phpnamespace app\lib;class shop{ private$mail = null; publicfunction boot(mailprovider $mail) { $this->mail = $mail; } publicfunction buy($productname) { echo '[shop] buy ' . $productname . '
'; !is_null($this->mail) && $this->mail->send('demouser'); }}
以上就介绍了无权代理与表见代理 minor6代理,包括了无权代理与表见代理方面的内容,希望对php教程有兴趣的朋友有所帮助。