1

I need to parse a SOAP request offline. All I need is to get the method_name of the request and the arguments to pass them to a controller without having generated any soap response to the request.

I have 2 ways: 1) create an XML reader for SOAP request, and manually parser it, or 2) use the soapServer and catch its output with buffer handler

I don't like none of the above. Because the first one will not be a good parser as like as PHP native soapServer. While the second use instead original soapServer class but also make use of OB handler, which is a ugly way to hack the library instead of have a clean parser.

Here is the actual code for the second way:

class SoapServerOffline {

    public function handle($soapRequest) {
        $wsdl = "provider.wsdl";
        $options =[
            'features' => 1,
            'trace' => 1,
            'cache_wsdl' => WSDL_CACHE_NONE,
            'exceptions' => true,
        ];


        $soapServer = new SoapServer($wsdl,$options);
        $soapHandler = new SoapServerHandler($this);
        $soapServer->setObject($soapHandler);

        ob_start();
        $soapServer->handle($dataraw);
        ob_end_clean();

        $soapServer->postExecute($);
    }

    public function execute($method_name, $args) {
        //run logic here
    }

    public function postExecute() {
        //run post execute logic here
    }
}

class SoapServerHandler  {
    private $soapServerOffline;

    public function __construct(soapServerOffline $soapServerOffline) {
        $this->soapServerOffline = $soapServerOffline;
    }

    public function WSCorIDSOAPHeader() {
        //do nothing
    }

    public function __call ($method_name , $arguments) {
        $this->soapServerOffline->execute(
            $method_name,
            json_decode(json_encode($arguments[0]),true)
        ];
    }
}

Instead of this method I would like to just retrieve method_name and arguments to pass them to a controller. Does nobody know how PHP native SoapServer retrieves these data and how to get these data without run all the handle function?

Max Cuttins
  • 614
  • 2
  • 6
  • 20

0 Answers0