时间:2021-07-01 10:21:17 帮助过:14人阅读
'; } } //业务逻辑类的包装类 class AOP { private $instance; public function __construct($instance) { $this->instance = $instance; } public function __call($method, $argument) { if(! method_exists($this->instance, $method)) { throw new Exception('未定义的方法:' . $method); } echo '权限检查
'; $callBack = array($this->instance, $method); $return = call_user_func_array($callBack, $argument); echo '日志记录
'; return $return; } } //工厂方法 class Factory { public function getBizInstance() { return new AOP(new BIZ()); } } //客户端调用演示 header("Content-Type: text/html; charset=gbk"); try { $obj = Factory::getBizInstance(); $obj->foobar(); } catch(Exception $e) { echo 'Caught exception: ', $e->getMessage(); } ?> 屏幕显示: 权限检查 业务逻辑 日志记录