Gui*_*ile 3 php soap soapserver
在PHP中,我想知道SOAP调用的方法是什么.这是一个要了解的样本......
$soapserver = new SoapServer();
$soapserver->setClass('myClass');
$soapserver->handle();
Run Code Online (Sandbox Code Playgroud)
我想知道的是将在handle()中执行的方法的名称
谢谢 !!
在我看来,在这种情况下访问被调用操作名称的最干净,最优雅的方法是使用某种Wrapper或Surrogate设计模式.根据您的意图您可以使用Decorator或Proxy.
举个例子,假设我们想在Handler不触及类本身的情况下动态地为对象添加一些额外的功能.这样可以使Handler班级更加清洁,从而更加专注于直接责任.这样的功能可以是记录方法及其参数或实现某种缓存机制.为此,我们将使用Decorator设计模式.而不是这样做:
class MyHandlerClass
{
public function operation1($params)
{
// does some stuff here
}
public function operation2($params)
{
// does some other stuff here
}
}
$soapserver = new SoapServer(null, array('uri' => "http://test-uri/"));
$soapserver->setClass('MyHandlerClass');
$soapserver->handle();
Run Code Online (Sandbox Code Playgroud)
我们将执行以下操作:
class MyHandlerClassDecorator
{
private $decorated = null;
public function __construct(MyHandlerClass $decorated)
{
$this->decorated = $decorated;
}
public function __call($method, $params)
{
// do something with the $method and $params
// then call the real $method
if (method_exists($this->decorated, $method)) {
return call_user_func_array(
array($this->decorated, $method), $params);
} else {
throw new BadMethodCallException();
}
}
}
$soapserver = new SoapServer(null, array('uri' => "http://test-uri/"));
$soapserver->setObject(new MyHandlerClassDecorator(new MyHandlerClass()));
$soapserver->handle();
Run Code Online (Sandbox Code Playgroud)
例如,如果要控制对Handler操作的访问,为了强制访问权限,请使用Proxy设计模式.