raigu/x-road-soap-envelope

PHP library for creating a SOAP envelope for X-Road request.

v0.1.0 2020-05-19 06:30 UTC

This package is auto-updated.

Last update: 2024-04-23 17:27:48 UTC


README

Latest Stable Version License: MIT Build Status codecov Maintainability Scrutinizer

x-road-soap-envelope

PHP library for creating a SOAP envelope for X-Road request.

Intended for applications which proxy several X-Road services and must create SOAP requests dynamically. If you need to integrate only one X-Road service then this library might not be the best choice.

Requirements

  • php 7.2+
  • DOM extension

Installation

$ composer require raigu/x-road-soap-envelope

Usage

require_once 'vendor/autoload.php';

use Raigu\XRoad\SoapEnvelope\SoapEnvelope;
use Raigu\XRoad\SoapEnvelope\Client;
use Raigu\XRoad\SoapEnvelope\ClientReference;
use Raigu\XRoad\SoapEnvelope\Service;
use Raigu\XRoad\SoapEnvelope\ServiceReference;
use Raigu\XRoad\SoapEnvelope\ServiceRequest;
use Raigu\XRoad\SoapEnvelope\UniqueId;

$envelope = new SoapEnvelope(
    new Client(
        new ClientReference('EE/GOV/MEMBER1/SUBSYSTEM1')
    ),
    new Service(
        new ServiceReference('EE/GOV/MEMBER2/SUBSYSTEM2/exampleService/v1')
    ),
    new ServiceRequest(
        '<ns1:exampleService xmlns:ns1="http://producer.x-road.eu">' .
        '<exampleInput>foo</exampleInput>' .
        '</ns1:exampleService>'
    ),
    new UniqueId
);


echo $envelope->asStr();

The above will output:

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:id="http://x-road.eu/xsd/identifiers"
              xmlns:xrd="http://x-road.eu/xsd/xroad.xsd">
    <env:Header>
        <xrd:client id:objectType="SUBSYSTEM">
            <id:xRoadInstance>EE</id:xRoadInstance>
            <id:memberClass>GOV</id:memberClass>
            <id:memberCode>MEMBER1</id:memberCode>
            <id:subsystemCode>SUBSYSTEM1</id:subsystemCode>
        </xrd:client>
        <xrd:service id:objectType="SERVICE">
            <id:xRoadInstance>EE</id:xRoadInstance>
            <id:memberClass>GOV</id:memberClass>
            <id:memberCode>MEMBER2</id:memberCode>
            <id:subsystemCode>SUBSYSTEM2</id:subsystemCode>
            <id:serviceCode>exampleService</id:serviceCode>
            <id:serviceVersion>v1</id:serviceVersion>
        </xrd:service>
        <xrd:id>0113072ef17ebb989e61a5b6c95f9efe</xrd:id>
        <xrd:protocolVersion>4.0</xrd:protocolVersion>
    </env:Header>
    <env:Body>
        <ns1:exampleService xmlns:ns1="http://producer.x-road.eu">
            <exampleInput>foo</exampleInput>
        </ns1:exampleService>
    </env:Body>
</env:Envelope>

The order of input parameters in SoapEnvelope constructor is not important.

There are more parameter types. See future test, it demonstrates all options.

Development

$ git@github.com:raigu/x-road-soap-envelope.git
$ cd x-road-soap-envelope
$ composer install

Now you can run tests.

Testing

$ composer test

Human readable tests

$ composer test -- --testdox

Code coverage report

$ composer coverage

Motivation

This library has grown out from raigu/x-road-soap-envelope-builder in pursuit of improving code metrics. In the process studied several code metrics service providers ( some more badges CodeScene Code Health CodeScene System Mastery Test Coverage )

One lesson I learned worth of sharing is that be suspicious about Maintainability Index. I tend to agree with the statement "size as a measure of maintainability has been underrated, and that the “sophisticated” maintenance metrics are overrated" referred in this article.

References