Skip to content

kernelguy/php-soap-react

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

clue/soap-react Build Status

A simple, async SOAP web service client library, built on top of React PHP.

Most notably, SOAP is often used for invoking Remote procedure calls (RPCs) in distributed systems. Internally, SOAP messages are encoded as XML and usually sent via HTTP POST requests. For the most part, SOAP (originally Simple Object Access protocol) is a protocol of the past, and in fact anything but simple. It is still in use by many (often legacy) systems.

This project provides a simple API for invoking async RPCs to remote web services.

  • Async execution of functions - Send any number of functions (RPCs) to the remote web service in parallel and process their responses as soon as results come in. The Promise-based design provides a sane interface to working with out of bound responses.
  • Async processing of the WSDL - The WSDL (web service description language) file will be downloaded and processed in the background.
  • Event-driven core - Internally, everything uses event handlers to react to incoming events, such as an incoming RPC result.
  • Lightweight, SOLID design - Provides a thin abstraction that is just good enough and does not get in your way. Built on top of tested components instead of re-inventing the wheel.
  • Good test coverage - Comes with an automated tests suite and is regularly tested against actual web services in the wild

Note: This project is in beta stage! Feel free to report any issues you encounter.

Quickstart example

Once installed, you can use the following code to query an example web service via SOAP:

$loop = React\EventLoop\Factory::create();
$factory = new Factory($loop);
$wsdl = 'http://example.com/demo.wsdl';

$factory->createClient($wsdl)->then(function (Client $client) {
    $api = new Proxy($client);

    $api->getBank(array('blz' => '12070000'))->then(function ($result) {
        var_dump('Result', $result);
    });
});

$loop->run();

See also the examples.

Usage

Factory

The Factory class is responsible for fetching the WSDL file once and constructing the Client instance. It also registers everything with the main EventLoop.

$loop = React\EventLoop\Factory::create();
$factory = new Factory($loop);

If you need custom DNS or proxy settings, you can explicitly pass a custom Browser instance:

$browser = new Clue\React\Buzz\Browser($loop);
$factory = new Factory($loop, $browser);

createClient()

The createClient($wsdl) method can be used to download the WSDL at the given URL into memory and create a new Client.

$factory->createClient($url)->then(
    function (Client $client) {
        // client ready
    },
    function (Exception $e) {
        // an error occured while trying to download the WSDL
    }
);

Client

The Client class is responsible for communication with the remote SOAP WebService server.

If you want to call RPC functions, see below for the Proxy class.

Note: It's recommended (and easier) to wrap the Client in a Proxy instance. All public methods of the Client are considered advanced usage.

soapCall()

The soapCall($method, $arguments) method can be used to queue the given function to be sent via SOAP and wait for a response from the remote web service.

Note: This is considered advanced usage, you may want to look into using the Proxy instead.

getFunctions()

The getFunctions() method returns an array of functions defined in the WSDL. It returns the equivalent of PHP's SoapClient::__getFunctions().

getTypes()

The getTypes() method returns an array of types defined in the WSDL. It returns the equivalent of PHP's SoapClient::__getTypes().

Proxy

The Proxy class wraps an existing Client instance in order to ease calling SOAP functions.

$proxy = new Proxy($client);

Functions

Each and every method call to the Proxy class will be sent via SOAP.

$proxy->myMethod($myArg1, $myArg2)->then(function ($response) {
    // result received
});

Please refer to your WSDL or its accompanying documentation for details on which functions and arguments are supported.

Processing

Issuing SOAP functions is async (non-blocking), so you can actually send multiple RPC requests in parallel. The web service will respond to each request with a return value. The order is not guaranteed. Sending requests uses a Promise-based interface that makes it easy to react to when a request is fulfilled (i.e. either successfully resolved or rejected with an error):

$proxy->demo()->then(
    function ($response) {
        // response received for demo function
    },
    function (Exception $e) {
        // an error occured while executing the request
    }
});

Install

The recommended way to install this library is through composer. New to composer?

{
    "require": {
        "clue/soap-react": "~0.1.0"
    }
}

License

MIT

About

A simple, async SOAP webservice client, built on top of React PHP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%