php面向切面编程实现
切面编程类似于一层一层的,走完一层在进行另外一层,就例如权限验证,在所有业务逻辑之前都需要进行权限验证,权限后才能执行其他的,这就是切面
话不多说上代码
···php
class BIZ
{
public function foobar(num);
echo "\n业务逻辑 do something";
}
}
class AOP{
private instance){
//this->instance = $instance;
}
public function __call($method,$argument) {
if (!method_exists($this->instance, $method)) {
throw new Exception('未定义的方法:' . $method);
}
echo "\n权限检查";
$callBack = array($this->instance,$method);
$return = call_user_func($callBack,$argument);
echo "\n日志记录";
return $return;
}
}
class Factory
{
public static function getBizInstance()
{
return new AOP(new BIZ());
}
}
try {
obj);
e) {
echo 'Exception '.$e->getMessage();
}
···







网友评论