我有一个API用于与我的Web应用程序交互,由类定义。每个可公开访问的方法在运行前都需要进行身份验证。而不是在每种方法中重复使用同一条线,我想使用magic __call函数。但是,它只能用于私有或受保护的方法,并且我需要公开才能使用Zend_Json_Server。__call相当于公共方法
class MY_Api
{
public function __call($name, $arguments)
{
//code here that checks arguments for valid auth token and returns an error if false
}
public function myFunction($param1, $param2, $param3)
{
//do stuff when the user calls the myFunction and passes the parameters
//this function must remain public so that Zend_Json_Server can parse it
//but I want it intercepted by a magic method so that the authentication
//can be checked and the system bails before it even gets to this function.
}
}
是否有可能钩到这些公共职能,并可能取消其执行被调用之前?
您使用的是Zend ACL吗? –
还没有。我不确定这个应用程序的这个部分是否合适。这是一个休息API,所以他们不登录并设置会话,而是传递一个令牌。 –
什么是调用公共方法,并且该调用方可以调用身份验证方法? – webbiedave