クラスによって定義された、Webアプリと対話するためのAPIがあります。公的にアクセス可能な各メソッドは、実行する前に認証を行う必要があります。各メソッドで同じ行を何度も繰り返すのではなく、magic__call関数を使用したいと思います。ただし、これはプライベートメソッドまたは保護されたメソッドでのみ機能します。Zend_Json_Serverを使用するには、パブリックメソッドである必要があります。
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.
}
}
これらのパブリック関数にフックして、呼び出される前に実行をキャンセルすることは可能ですか?