我正在使用PHP 5.2.6使用Zend_JSON_Server
和Zend_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);
此代码还将使用webservice宣布internalUseOnly
为可访问函数:
{ "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
,但两者都被Reflection忽略了。还有其他选项可以从我的服务地图中删除这些功能吗?
提前致谢!
的更新 的
我发现的一个解决方案是使用重载和动态函数调用再次访问私有/受保护的方法。但由于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!'); }
}
答案 0 :(得分:0)
使用__前缀您的方法。 Zend \ Server \ Reflection \ ReflectionClass忽略以__开头的方法。至少在ZF2中。