PHP Soap Server如何知道被调用的方法

标签 php soap soapserver

在 PHP 中,我想知道 SOAP 调用的方法是什么。这是一个示例以了解...

$soapserver = new SoapServer();
$soapserver->setClass('myClass');
$soapserver->handle();

我想知道的是handle()中会执行的方法名

谢谢!!

最佳答案

在我看来,在这种情况下访问被调用操作名称的最简洁、最优雅的方法是使用某种WrapperSurrogate 设计模式。根据您的意图,您可以使用 DecoratorProxy .

举个例子,假设我们想动态地向我们的 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();

我们将执行以下操作:

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();

如果您想控制对处理程序操作的访问,例如,为了强加访问权限,请使用代理设计模式。

关于PHP Soap Server如何知道被调用的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10705298/

相关文章:

java - SoapUI 找不到我的网络服务

java - 将Web服务请求转换为内部表示?

PHP SoapClient : SoapFault exception Could not connect to host

php - 努力接收 Paypal 沙盒 IPN 发布数据

javascript - 当查询使用 SQL 变量时 Mysqli PHP 准备好的语句

php - 产品数据库结构 : How to store a list of options for each product?

python - 如何使用 Python/SUDS 将键/值对发送到 Web 服务?

php - 反转输出顺序

web-services - 使用 wsdl 的 Perl Soap 服务

php - 扩展 php SoapClient 以进行 siteminder 身份验证