<i id='S8vak'><tr id='S8vak'><dt id='S8vak'><q id='S8vak'><span id='S8vak'><b id='S8vak'><form id='S8vak'><ins id='S8vak'></ins><ul id='S8vak'></ul><sub id='S8vak'></sub></form><legend id='S8vak'></legend><bdo id='S8vak'><pre id='S8vak'><center id='S8vak'></center></pre></bdo></b><th id='S8vak'></th></span></q></dt></tr></i><div id='S8vak'><tfoot id='S8vak'></tfoot><dl id='S8vak'><fieldset id='S8vak'></fieldset></dl></div>

      <small id='S8vak'></small><noframes id='S8vak'>

        <legend id='S8vak'><style id='S8vak'><dir id='S8vak'><q id='S8vak'></q></dir></style></legend>
          <bdo id='S8vak'></bdo><ul id='S8vak'></ul>
      1. <tfoot id='S8vak'></tfoot>

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

        时间:2023-05-22
        <legend id='KF4RD'><style id='KF4RD'><dir id='KF4RD'><q id='KF4RD'></q></dir></style></legend>

              <bdo id='KF4RD'></bdo><ul id='KF4RD'></ul>
                <tfoot id='KF4RD'></tfoot>

                <small id='KF4RD'></small><noframes id='KF4RD'>

                    <tbody id='KF4RD'></tbody>
                1. <i id='KF4RD'><tr id='KF4RD'><dt id='KF4RD'><q id='KF4RD'><span id='KF4RD'><b id='KF4RD'><form id='KF4RD'><ins id='KF4RD'></ins><ul id='KF4RD'></ul><sub id='KF4RD'></sub></form><legend id='KF4RD'></legend><bdo id='KF4RD'><pre id='KF4RD'><center id='KF4RD'></center></pre></bdo></b><th id='KF4RD'></th></span></q></dt></tr></i><div id='KF4RD'><tfoot id='KF4RD'></tfoot><dl id='KF4RD'><fieldset id='KF4RD'></fieldset></dl></div>
                2. 本文介绍了在 PHP 中记录所有 Soap 请求和响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  有谁知道如何使用 PHP 中的内置 SoapClient 记录所有请求和响应?实际上,我可以使用 SoapClient::__getLastRequest()SoapClient::__getLastResponse() 手动记录所有内容,但是我们的系统中有很多我正在寻找的肥皂请求其他可能性.

                  Does anyone know how to log all request and responses with the builtin SoapClient in PHP? I could in fact manually log everything with SoapClient::__getLastRequest() and SoapClient::__getLastResponse() But we have that much soap requests in our system that i'm looking other possibilities.

                  注意:我使用的是 wsdl 模式,因此不能使用隧道到 SoapClient::__soapCall() 的方法

                  Note: i'm using wsdl mode so using a method that tunnels all through to SoapClient::__soapCall() isn't an option

                  推荐答案

                  我支持 Aleksanders 和 Stefans 的建议,但不会将 SoapClient 子类化.相反,我会将常规的 SoapClient 包装在一个装饰器中,因为日志记录不是 SoapClient 的直接关注点.此外,松散耦合让您可以轻松地用单元测试中的模拟替换 SoapClient,因此您可以专注于测试日志记录功能.如果您只想记录特定的调用,您可以添加一些逻辑,通过 $action 或您认为合适的任何内容过滤请求和响应.

                  I second Aleksanders and Stefans suggestion but would not subclass SoapClient. Instead I'd wrap the regular SoapClient in a decorator, because logging is not a direct concern of the SoapClient. In addition, the loose coupling lets you easily substitute the SoapClient with a mock in your UnitTests, so you can concentrate on testing the logging functionality. If you only want to log specific calls, you can add some logic that filters requests and responses by $action or anything you see fit.

                  编辑 由于 Stefan 建议添加一些代码,装饰器可能看起来像这样,尽管我不确定 __call() 方法(请参阅 Stefans 评论)

                  Edit since Stefan suggested to add some code, the decorator would probably look something like this, although I am not sure about the __call() method (see Stefans comments)

                  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, $location, $action, $version);
                  
                           $response = $this->soapClient->__doRequest($request, $location, 
                                                                      $action, $version, 
                                                                      $one_way);
                  
                           $this->log($response, $location, $action, $version);
                           return $response;
                      }
                  
                      public function log($request, $location, $action, $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 请求和响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用证书创建 PHP SOAP 请求 下一篇:PHP SOAP HTTP 请求

                  相关文章

                  最新文章

                3. <legend id='G3zFz'><style id='G3zFz'><dir id='G3zFz'><q id='G3zFz'></q></dir></style></legend>

                    <small id='G3zFz'></small><noframes id='G3zFz'>

                    <tfoot id='G3zFz'></tfoot>
                      • <bdo id='G3zFz'></bdo><ul id='G3zFz'></ul>
                      <i id='G3zFz'><tr id='G3zFz'><dt id='G3zFz'><q id='G3zFz'><span id='G3zFz'><b id='G3zFz'><form id='G3zFz'><ins id='G3zFz'></ins><ul id='G3zFz'></ul><sub id='G3zFz'></sub></form><legend id='G3zFz'></legend><bdo id='G3zFz'><pre id='G3zFz'><center id='G3zFz'></center></pre></bdo></b><th id='G3zFz'></th></span></q></dt></tr></i><div id='G3zFz'><tfoot id='G3zFz'></tfoot><dl id='G3zFz'><fieldset id='G3zFz'></fieldset></dl></div>