在PHP中记录所有Soap请求和响应

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了在PHP中记录所有Soap请求和响应脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
有谁知道如何使用 PHP内置的SOApClient记录所有请求和响应?事实上,我可以使用SoapClient :: __ getLastRequest()和SoapClient :: __ getLastResponse()手动记录所有内容但是我们的系统中有很多肥皂请求,我正在寻找其他可能性. @H_404_1@注意:我正在使用wsdl模式,所以使用隧道全部通过SoapClient :: __ soapCall()的方法不是一个选项

我是第二个Aleksanders和Stefans的建议,但不会将SoapClient子类化.相反,我会将常规SoapClient包装在装饰器中,因为日志记录不是SoapClient的直接关注点.此外,松散耦合使您可以在UnITtests中使用模拟轻松替换SoapClient,因此您可以专注于测试日志记录功能.如果您只想记录特定的调用,可以添加一些逻辑,通过$action或您认为合适的任何内容来过滤请求和响应. @H_404_1@编辑自Stefan建议添加一些代码后,装饰器可能看起来像这样,虽然我不确定__call()方法(参见Stefans注释)

class SoapClientLOGger
{
    PRotected $soapClient;

    // wrapping the SoapClient instance with the decorator
    public function __construct(SoapClient $client)
    {
        $this->soapClient = $client;
    }

    // overloading __doRequest with your logging code
    function __doRequest($request,$location,$action,$version,$one_way = 0) 
    {
         $this->log($request,$version);

         $response = $this->soapClient->__doRequest($request,$one_way);

         $this->log($response,$version);
         return $response;
    }

    public function log($request,$version)
    {
        // here you Could add filterings to log only items,e.g.
        if($action === 'foo') {
            // code to log item
        }
    }

    // route all other method calls directly to soapClient
    public function __call($method,$args)
    {
        // you Could also add method_exists check here
        return call_user_func_array(array($this->soapClient,$method),$args);
    }
}

脚本宝典总结

以上是脚本宝典为你收集整理的在PHP中记录所有Soap请求和响应全部内容,希望文章能够帮你解决在PHP中记录所有Soap请求和响应所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。