在Zend中使用反射时如何忽略/跳过函数和方法


How to ignore/skip functions and methods when using Reflection in Zend

我正在使用PHP 5.2.6构建一个使用Zend_JSON_ServerZend_XmlRpc_Server的多协议web服务。我现在面临的问题是,服务器现在宣布每一个方法从我的类和它的父。

class MyClass extends MyInterface {
  /**
   * To be published and accessible
   **/
  public function externalUse() {}
}
class MyInterface {
  /**
   * This method should not be published using the webservice,
   * but needs to be of type "public" for internal use
   * @access private
   * @ignore
   **/
   public function internalUseOnly() {}
}
$server = new Zend_Json_Server();
$server->setClass('MyClass');
// show service map
header('Content-Type: text/plain');
$server->setTarget('/service.json')
       ->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2);
$smd = $server->getServiceMap();
die($smd);

此代码还将宣布internalUseOnly为使用webservice的可访问函数:

{ "SMDVersion" : "2.0",
  "contentType" : "application/json",
  "envelope" : "JSON-RPC-2.0",
  "methods" : { "externalUse" : { "envelope" : "JSON-RPC-2.0",
          "parameters" : [  ],
          "returns" : "null",
          "transport" : "POST"
        },
      "internalUseOnly" : { "envelope" : "JSON-RPC-2.0",
          "parameters" : [  ],
          "returns" : "null",
          "transport" : "POST"
        }
    },
  "services" : { "externalUse" : { "envelope" : "JSON-RPC-2.0",
          "parameters" : [  ],
          "returns" : "null",
          "transport" : "POST"
        },
      "internalUseOnly" : { "envelope" : "JSON-RPC-2.0",
          "parameters" : [  ],
          "returns" : "null",
          "transport" : "POST"
        }
    },
  "target" : "/service.json",
  "transport" : "POST"
}

您可以看到,我已经尝试了@ignore@access private,但两者都被反射忽略了。是否有其他选项可以从服务映射中删除这些功能?

提前感谢!


更新

我发现的一个解决方案是使用重载和动态函数调用再次访问私有/受保护的方法。但由于call_user_func不是已知的快速方法之一,这只是一个修补程序。

class MyInterface {
    public function __call($method, $params) {
        $method = '_' . $method;
        if (method_exists($this, $method)) {
            call_user_func(array($this, $method), $params);
        }
    }
  /**
   * This method should not be published using the webservice,
   * but needs to be of type "public" for internal use
   * @ignore
   * @access private
   * @internal
   **/
  protected function _internalUseOnly() { die('internal use only!'); }
}

用__作为方法的前缀。Zend'Server'Reflection'ReflectionClass忽略以__开头的方法。