Yes, use the native SOAP functions. You just need to decide where to put them.
/**
* Construct a new instance. Calls the soap service and creates an endpoint, gets methods
* @param App\System $system system model with the various URL and passwords
*/
public function __construct($system)
{
$this->system = $system;
$this->options = array(
'soap_version' => SOAP_1_1,
'exceptions' => true,
'trace' => 1,
'cache_wsdl' => WSDL_CACHE_MEMORY,
'login' => $system['webuser'],
'password' => $system['webpass'],
'connection_timeout' => 25,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
);
$this->client = new \SoapClient($this->system['url'] . '?WSDL', $this->options);
}
The above creates a new soap connection to an endpoint that is passed as an array ($system) - URL and password.
You can then call functions on the $client;
public function provider($method, $query)
{
try {
$response = $this->client->$method($query);
} catch (\Exception $e) {
Log::error('Soap Exception: ' . $e->getMessage());
throw new \Exception('Problem with SOAP call');
}
return $response;
}
public function getRecentPlannedConsignments($hours = 1)
{
$query = ['hoursToLookBack'=>$hours];
return $this->provider('GetRecentPlannedConsignments', $query);
}
In my code I can call functions like getRecentPlannedConsignments() (there are many more)
This calls a function that wraps the soap client call in a try-catch block.