PHP code example of raigu / x-road-soap-envelope-builder

1. Go to this page and download the library: Download raigu/x-road-soap-envelope-builder library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

raigu / x-road-soap-envelope-builder example snippets


$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;

$client = new \Guzzle\Http\Client();
$request = $client->post(
    $securityServerUrl,
    [ 
        'Content-Type' => 'text/xml',
        'SOAPAction' => ''
    ],
    $envelope
);

$response = $client->send($request);

echo $response->getBody();

$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;