2013-10-30 15:54:35 +01:00
# BeSimpleSoap
2013-08-24 17:31:35 +02:00
2017-02-03 15:22:37 +01:00
Build SOAP and WSDL based web services.
2017-03-15 11:23:21 +01:00
This fork is a refactored version that fixes a lot of errors and provides
better API, robust, stable and modern codebase.
2017-02-03 15:22:37 +01:00
See [How to use ](#how-to-use ) that will help you to understand the magic.
2013-08-24 17:31:35 +02:00
# Components
BeSimpleSoap consists of five components ...
2017-02-03 15:22:37 +01:00
## BeSimpleSoapClient
2013-08-24 17:31:35 +02:00
2017-02-03 15:22:37 +01:00
**Refactored** BeSimpleSoapClient is a component that extends the native PHP SoapClient with further features like SwA and WS-Security.
2013-08-24 17:31:35 +02:00
2017-02-03 15:22:37 +01:00
## BeSimpleSoapServer
2013-08-24 17:31:35 +02:00
2017-02-03 15:22:37 +01:00
**Refactored** BeSimpleSoapServer is a component that extends the native PHP SoapServer with further features like SwA and WS-Security.
2013-08-24 17:31:35 +02:00
## BeSimpleSoapCommon
2017-02-03 15:22:37 +01:00
**Refactored** BeSimpleSoapCommon component contains functionality shared by both the server and client implementations.
2013-08-24 17:31:35 +02:00
2017-02-03 15:22:37 +01:00
## BeSimpleSoapWsdl
2013-08-24 17:31:35 +02:00
2017-03-15 11:23:21 +01:00
**Untouched!**
The component is not affected by refactoring so it should work properly.
For further information see the original [README ](https://github.com/BeSimple/BeSimpleSoap/blob/master/src/BeSimple/SoapWsdl/README.md ).
2013-08-24 17:31:35 +02:00
2017-02-03 15:22:37 +01:00
## BeSimpleSoapBundle
2013-08-24 17:31:35 +02:00
2017-03-15 11:23:21 +01:00
**Unsupported!**
2017-02-03 15:22:37 +01:00
The BeSimpleSoapBundle is a Symfony2 bundle to build WSDL and SOAP based web services.
For further information see the the original [README ](https://github.com/BeSimple/BeSimpleSoap/blob/master/src/BeSimple/SoapBundle/README.md ).
2017-03-15 11:23:21 +01:00
*Will not work since the Symfony libraries were removed and usages of other components were not refactored. Feel free to fork this repository and fix it!*
2013-08-24 17:31:35 +02:00
# Installation
If you do not yet have composer, install it like this:
```sh
curl -s http://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin
```
Create a `composer.json` file:
```json
{
"require": {
2017-05-25 18:13:58 +02:00
"tuscanicz/soap": "^4.2"
2013-08-24 17:31:35 +02:00
}
}
```
Now you are ready to install the library:
```sh
php /usr/local/bin/composer.phar install
2013-10-30 16:49:47 +01:00
```
2017-02-03 15:22:37 +01:00
# How to use
2017-03-15 10:48:23 +01:00
You can investigate the unit tests dir ``tests`` in order to get a clue.
2017-03-15 11:23:21 +01:00
Forget about associative arrays, vague configurations, multiple extension and silent errors!
This may look a bit more complex at the first sight,
but it will guide you to configure and set up your client or server properly.
2017-02-03 15:22:37 +01:00
2017-03-15 11:23:21 +01:00
## Example of soap client call
2017-02-03 15:22:37 +01:00
```php
$soapClientBuilder = new SoapClientBuilder();
$soapClient = $soapClientBuilder->build(
SoapClientOptionsBuilder::createWithDefaults(),
SoapOptionsBuilder::createWithDefaults('http://path/to/wsdlfile.wsdl')
);
$myRequest = new MyRequest();
$myRequest->attribute = 'string value';
$soapResponse = $soapClient->soapCall('myMethod', [$myRequest]);
var_dump($soapResponse); // Contains Response, Attachments
```
### Something wrong?!
Turn on the tracking and catch `SoapFaultWithTracingData` exception to get some sweets :)
```php
try {
2017-03-15 11:23:21 +01:00
$soapResponse = $soapClient->soapCall('myMethod', [$myRequest]);
2017-02-03 15:22:37 +01:00
} catch (SoapFaultWithTracingData $fault) {
var_dump($fault->getSoapResponseTracingData()->getLastRequest());
}
```
2017-03-15 10:48:23 +01:00
In this example, a ``MyRequest`` object has been used to describe request.
Using a ClassMap, you help SoapClient to turn it into XML request.
2017-02-03 15:22:37 +01:00
2017-03-15 11:23:21 +01:00
## Example of soap server handling
2017-02-03 15:22:37 +01:00
Starting a SOAP server is a bit more complex.
2017-03-15 11:23:21 +01:00
I recommend you to inspect SoapServer unit tests for inspiration.
2017-02-03 15:22:37 +01:00
```php
$dummyService = new DummyService();
$classMap = new ClassMap();
foreach ($dummyService->getClassMap() as $type => $className) {
$classMap->add($type, $className);
}
$soapServerBuilder = new SoapServerBuilder();
$soapServerOptions = SoapServerOptionsBuilder::createWithDefaults($dummyService);
$soapOptions = SoapOptionsBuilder::createWithClassMap($dummyService->getWsdlPath(), $classMap);
$soapServer = $soapServerBuilder->build($soapServerOptions, $soapOptions);
$request = $soapServer->createRequest(
$dummyService->getEndpoint(),
'DummyService.dummyServiceMethod',
'text/xml;charset=UTF-8',
2017-03-15 10:48:23 +01:00
'< received > < soap > < request > < here / > < / request > < / soap > < / received > '
2017-02-03 15:22:37 +01:00
);
$response = $soapServer->handleRequest($request);
var_dump($response); // Contains Response, Attachments
```
2017-03-15 10:48:23 +01:00
In this example, a ``DummyService`` service has been used to handle request.
Using a service can help you create coherent SoapServer endpoints.
Service can hold an endpoint URL, WSDL path and a class map as associative array.
2017-03-15 11:23:21 +01:00
You can hold a class map as ``ClassMap`` object directly in the ``DummyService`` instead of array.
In the service you should describe SOAP methods from given WSDL.
In the example, the dummyServiceMethod is called.
The method will receive request object and return response object that are matched according to the class map.
See a simplified implementation of ``dummyServiceMethod`` to get a clue:
```
/**
* @param DummyServiceRequest $dummyServiceRequest
* @return DummyServiceResponse
*/
public function dummyServiceMethod(DummyServiceRequest $dummyServiceRequest)
{
$response = new DummyServiceResponse();
$response->status = true;
return $response;
}
```
2017-05-25 18:13:58 +02:00
For further information and getting inspiration for your implementation, see the unit tests in ``tests`` dir.
2017-06-07 16:18:46 +02:00
# Contribute
[![Build Status ](https://travis-ci.org/tuscanicz/BeSimpleSoap.svg?branch=master )](https://travis-ci.org/tuscanicz/BeSimpleSoap)
Feel free to contribute! Please, run the tests via Phing ``php phing -f build.xml``.
**Warning:** Unit tests may fail under Windows OS, tested under Linux, MacOS.