raigu / x-road-soap-envelope-builder
PHP library for generating X-Road SOAP envelope.
v2.0.0
2023-05-28 08:03 UTC
Requires
- php: ^8.0
- ext-dom: *
Requires (Dev)
- phpunit/phpunit: 9.*
This package is auto-updated.
Last update: 2024-11-28 11:19:15 UTC
README
x-road-soap-envelope-builder
PHP library for generating a SOAP envelope for X-Road request.
Requirements
- php ^8.0
- DOM extension
(For PHP ^PHP7.2 use version 1.1.1)
Installation
$ composer require raigu/x-road-soap-envelope-builder
Usage
Building SOAP envelope for X-Road request
$builder = \Raigu\XRoad\SoapEnvelope\SoapEnvelopeBuilder::create() ->withService('EE/GOV/70008440/rr/RR437/v1') ->withClient('EE/COM/12213008/gathering') ->withBody(<<<EOD <prod:RR437 xmlns:prod="http://rr.x-road.eu/producer"> <request> <Isikukood>00000000000</Isikukood> </request> </prod:RR437> EOD; ); $envelope = $builder->build(); echo $envelope;
The method's withBody
input parameter can be generated from
WSDL using free tools like WSDL Analyzer or SOAP UI.
The WSDL-s can be found in X-Road catalog.
See short (1:34) demo video how to acquire WSDL and generate a request body.
Builder methods
Making X-Road request
In following samples assign your X-Road security server URL to $securityServerUrl
.
Using Guzzle
$client = new \Guzzle\Http\Client(); $request = $client->post( $securityServerUrl, [ 'Content-Type' => 'text/xml', 'SOAPAction' => '' ], $envelope ); $response = $client->send($request); echo $response->getBody();
Using curl
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $securityServerUrl); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $envelope); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type' => 'text/xml', 'SOAPAction' => '' ]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); echo $output;