notfalsedev / laravel-soap

A soap client wrapper for Laravel
MIT License
634 stars 122 forks source link

Call creates new instance of Client everytime #79

Closed Scaenicus closed 7 years ago

Scaenicus commented 7 years ago

Hello,

For debug purposes I wanted to get the last request back.

This code would work in principle:

$this->soapWrapper->client('SOAPServiceName', function ($client) {
    $dom = new \DOMDocument();
    $dom->preserveWhiteSpace = false;
    $dom->formatOutput = true;
    if (empty($client->getLastRequest())) {
        \Log::debug('SOAPServiceName.FunctionName getLastRequest is empty.');
    } else {
        $dom->loadXML($client->getLastRequest());
        \Log::debug('SOAPServiceName.FunctionName'."\n".$dom->saveXML());
    }
});

But the problem is, that I always get a fresh Client instance. I think I found the solution (at least it works for me).

SoapWrapper.php > public function client

Change

      if (!$client instanceof SoapClient) {
        $client = new Client($service->getWsdl(), $service->getOptions());
      }

to

      if (!$client instanceof SoapClient) {
        $client = new Client($service->getWsdl(), $service->getOptions());
        $service->client($client);
      }

Now the Client instance, which is implicitly created by public function call, is stored to the service and is found the next time call, or client is accessed.

With kind regards, Philipp

LasseRafn commented 7 years ago

Added a pull request: #81

notfalsedev commented 7 years ago

Please try version 0.3.0.4.

Scaenicus commented 7 years ago

I'm sorry, how can I verify that composer loaded 0.3.0.4 because getLastRequest is still not working and in SoapWrapper it is still...

            if (is_null($service->getClient())) {
                $client = new Client($service->getWsdl(), $service->getOptions());
            } else {
                $client = $service->getClient();
            }

...instead of...

            if (is_null($service->getClient())) {
                $client = new Client($service->getWsdl(), $service->getOptions());
                $service->client($client);
            } else {
                $client = $service->getClient();
            }