Skip to content

Commit

Permalink
Merge pull request #391 from phpro/v2.0.0
Browse files Browse the repository at this point in the history
V2.0.0
  • Loading branch information
veewee authored Sep 24, 2021
2 parents b8b413e + 72055ff commit 662dce2
Show file tree
Hide file tree
Showing 384 changed files with 1,993 additions and 18,428 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/grumphp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
operating-system: ['windows-latest', 'ubuntu-latest']
php-versions: ['7.4', '8.0']
php-versions: ['8.0']
composer-options: ['', '--prefer-lowest']
fail-fast: false
name: PHP ${{ matrix.php-versions }} @ ${{ matrix.operating-system }} with ${{ matrix.composer-options }}
Expand All @@ -20,7 +20,7 @@ jobs:
with:
php-version: ${{ matrix.php-versions }}
tools: 'composer:v2'
extensions: mbstring, posix, soap, intl
extensions: mbstring, posix, soap, intl, sodium, xsl
- name: Check Versions
run: |
php -v
Expand Down
58 changes: 33 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,26 @@
Sick and tired of building crappy SOAP implementations?
This package aims to help you with some common SOAP integration pains in PHP.
Its goal is to make integrating with SOAP fun again!
Let's inspect some of the pains that are solved by this package:

# Demo
<img src="https://raw.githubusercontent.com/wiki/phpro/soap-client/soap-client-demo-fast.gif" alt="Soap Client demo" width="100%"/>



## Prerequisites

You can choose what HTTP client you want to use.
This package expects some PSR implementations to be present in order to be installed:

* PSR-7: `psr/http-message-implementation` like `nyholm/psr7` or `guzzlehttp/psr7`
* PSR-17: `psr/http-factory-implementation` like `nyholm/psr7` or `guzzlehttp/psr7`
* PSR-18: `psr/http-client-implementation` like `symfony/http-client` or `guzzlehttp/guzzle`

Example:

```sh
$ composer require symfony/http-client nyholm/psr7
```

## Installation

```sh
Expand All @@ -25,7 +40,6 @@ Since life is too short to read documentation,
All you need to do is:

```sh
composer require --dev laminas/laminas-code:^3.1.0
./vendor/bin/soap-client wizard
```

Expand All @@ -44,28 +58,20 @@ You can customize the generated code based on the manual installation pages in t

## Advanced configuration

- [Add type converters.](docs/type-converter.md)
- [Add type converters.](https://github.com/php-soap/ext-soap-engine/#typeconverter)
- [Listen to events.](docs/events.md)
- [Logger Subscriber](docs/event-subscribers/logger.md)
- [Validator Subscriber](docs/event-subscribers/validator.md)
- [Caching Subscriber](docs/event-subscribers/caching.md)
- [Get in control of the soap-client](docs/engine.md)
- [Choose a driver](docs/engine.md#driver)
- [ExtSoapDriver](docs/drivers/ext-soap.md)
- [Create your own driver](docs/drivers/new.md)
- [Manipulate the drivers metadata](docs/drivers/metadata.md)
- [Specify your HTTP handler.](docs/engine.md#handler)
- [HttPlugHandle](docs/handlers/httplug.md) (Supports [middlewares](docs/middlewares.md))
- [ExtSoapClientHandle](docs/handlers/ext-soap/client.md)
- [ExtSoapServerHandle](docs/handlers/ext-soap/local-server.md)
- [Create your own handler](docs/handlers/new.md)
- [Configure one or multiple HTTP middlewares.](docs/middlewares.md)
- [BasicAuthMiddleware](docs/middlewares.md#basicauthmiddleware)
- [NtlmMiddleware](docs/middlewares.md#ntlmmiddleware)
- [WsaMiddleware](docs/middlewares.md#wsamiddleware)
- [WsseMiddleware](docs/middlewares.md#wssemiddleware)
- [Create your own middleware](docs/middlewares.md#creating-your-own-middleware)
- [Select a WSDL Provider](docs/wsdl-providers.md)
- [Get in control of the soap-client](https://github.com/php-soap/engine)
- [Psr-18 HTTP Transport](https://github.com/php-soap/psr18-transport/)
- [Configure one or multiple HTTP middlewares.](https://github.com/php-soap/psr18-transport/#middleware)
- [Customize how ext-soap behaves](https://github.com/php-soap/ext-soap-engine/)
- [Select a WSDL Provider](https://github.com/php-soap/ext-soap-engine/#wsdlprovider)
- [Manipulate the metadata](docs/drivers/metadata.md)


This is a client implementation on top of [php-soap](https://github.com/php-soap).
For more advanced configuration, you can check the documentation inside the php-soap packages.


## Customize the code generation
Expand Down Expand Up @@ -116,7 +122,7 @@ Creating a great OO SOAP client means that you'll have to create a lot of code.

It is important keep your code clean. Therefore, we added an event-listener to your Soap client.
You can hook in at every important step of the SOAP flow.
This way it is possible to add logging, validation, caching and error handling with event subscribers.
This way it is possible to add logging, validation and error handling with event subscribers.
Pretty cool right?!

Implementing SOAP extensions is a real pain in the ass.
Expand All @@ -132,8 +138,10 @@ Dealing with ext-soap is not for all developers. There are some nasty quirks you
By default we will still ship an ext-soap driver, but it is completely opt-in.
You can use any user-land SoapClient implementation if you wrap it in our own driver interfaces.

Testing webservices is hard!
That is Why this package is fully compatible with [php-vcr](http://php-vcr.github.io/).
Testing webservices is hard!
This package provide some various ways of testing a SOAP service.
Since the transport is HTTP based, you could use a `php-vcr` implementation.
If you don't want to do actual HTTP calls, you could also use a custom `Transport` or `Caller` in your test cases.
Testing your SOAP client will be very fast and without any errors at the 3th party side of the integration.

Last but not least, we want to make it easy for you to configure your SoapClient.
Expand Down
261 changes: 261 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
# V1 to V2

V1 has been around for quite some time.
Since the low-level SOAP parts became very stable and trustworthy,
We decided to move them [to a separate organisation](https://github.com/php-soap/).
This will make it easier to make changes in both this soap-client and the more low-level SOAP parts.
An additional benefit is that the robust SOAP fundamentals can be used by other SOAP clients as well.
We hope this will lead to an even more stable SOAP core.

The focus of this package shifted to the generation of SOAP client code.
This is the part that makes it easy to interact with your SOAP service.
We decided to make it more opinionated, so that you have to deal with less strange SOAP related bugs than before.

By moving the low-level SOAP stuff out, we can now focus on improving WSDL metadata collection,
which will results in more strictly typed generated code.
You can expect this to come in one of the next releases.

## Prerequisites

If your application does not contain a PSR-18 client, you'll have to
choose which HTTP client you want to use.
This package expects some PSR implementations to be present in order to be installed:

* PSR-7: `psr/http-message-implementation` like `nyholm/psr7` or `guzzlehttp/psr7`
* PSR-17: `psr/http-factory-implementation` like `nyholm/psr7` or `guzzlehttp/psr7`
* PSR-18: `psr/http-client-implementation` like `symfony/http-client` or `guzzlehttp/guzzle`

Example implementations:

```
composer require symfony/http-client nyholm/psr7
```

## Upgrading

```bash
composer require phpro/soap-client:^2.0
```

We suggest you to use the `soap-client` CLI tools again if you want to upgrade and existing application:

```
./vendor/bin/soap-client wizard
```

From this point on, you can re-add the custom parts of your existing SOAP client back into the new SOAP client.

**You can check the updated documentation in order to discover how you need to do specific actions like adding middleware in v2.**


This update comes with some breaking changes:

## php-soap

The new php-soap organisation provides most of the interfaces that were previously in this package.

### Engine

https://github.com/php-soap/engine

Provides following interfaces:

* [Engine](https://raw.githubusercontent.com/php-soap/engine/main/src/Engine.php) : Replaces the old `EngineInterface`
* [Metadata](https://raw.githubusercontent.com/php-soap/engine/main/src/Metadata/Metadata.php) : Replaces the old `MetadataInterface`
* [MetadataProvider](https://raw.githubusercontent.com/php-soap/engine/main/src/Metadata/MetadataProvider.php) : Replaces the old `MetadataProviderInterface`
* [Driver](https://raw.githubusercontent.com/php-soap/engine/main/src/Driver.php) : Replaces the old `DriverInterface`
* [Decoder](https://raw.githubusercontent.com/php-soap/engine/main/src/Decoder.php) : Replaces the old `DecoderInterface`
* [Encoder](https://raw.githubusercontent.com/php-soap/engine/main/src/Encoder.php) : Replaces the old `EncoderInterface`


If you use any of these interfaces in your own code, you will need to replace them with the `php-soap` alternatives.


**Note:**

* The metadata has slightly been changed : property and parameter collections are replacing plain arrays.

### Transport

https://github.com/php-soap/psr18-transport/

* [Transport](https://raw.githubusercontent.com/php-soap/engine/main/src/Transport.php) : Replaces the old `HandlerInterface`

By default we will be using a [PSR-18](https://www.php-fig.org/psr/psr-18/) based transport.
The `ExtSoapClientTransport` is still available, but won't be used by default anymore,
because it has many known issues in PHP's bug tracker.

The downside is that you have to decide which PSR-18 HTTP client you want to use before installing this package.
For example:

```bash
composer require symfony/http-client nyholm/psr7
```

The HTTP middleware are now regular [httplug](http://httplug.io/) plugins, which are also moved to another package:
You can find a full list of plugins that can be used here:

* [All HTTPlug plugins](https://docs.php-http.org/en/latest/plugins/)
* [Authentication plugins](https://github.com/php-soap/psr18-transport#authentication)
* [Soap - WSDL middleware](https://github.com/php-soap/psr18-transport/tree/main/src/Middleware)
* [WSSE - WSA middleware](https://github.com/php-soap/psr18-wsse-middleware)

### ExtSoap

https://github.com/php-soap/ext-soap-engine/

All `ext-soap` quirks are now maintained in a separate package.
This will most likely have impact on:

* [SoapOptions](https://github.com/php-soap/ext-soap-engine/#extsoapoptions): The same as before, but without metadata manipulators. You can now configure them in the Engine factory.
* [ClassMap](https://github.com/php-soap/ext-soap-engine/#classmap): It now takes variadic `ClassMap` arguments as arguments instead of an array.
* [TypeConverter](https://github.com/php-soap/ext-soap-engine/#typeconverter): Moved
* [WsdlProvider](https://github.com/php-soap/ext-soap-engine/#wsdlprovider): New WSDL providers were added to the new repo


If you have custom classes implementing one of the items above, they will require some love whilst upgrading.


**Note:**

* By default, the Transport does not contain any last request information anymore. There is a `TraceableTransport` available that you can decorate another transport with in order to get this functionality back.

## Dependency upgrades

* Symfony to LTS (4.4)
* PHP (^8.0)
* Removed a lot of old dependencies and suggestions
* Removed ext-*, since they are required in the specific php-soap packages

## Removed deprecations

### Events

The custom event dispatchers are removed.
We now support any [PSR-14 event dispatcher](https://www.php-fig.org/psr/psr-14/).

Fully qualified class names will be used as event names.
The old deprecated event names are now removed from the codebase.

The events won't contain the SOAP client anymore.
We don't want them to be service containers.
So instead, if you require the SOAP client in the event listeners, you need to inject them manually.

## Client

We don't work with a base client anymore.
Instead, a `Caller` is injected into the client you fully own.
The caller is responsible for transporting the request.
We provide an engine caller and an event dispatching caller
so that your client keeps on working how you expect it to.

Example of generated client:

```php
use Calculator\Type\Add;
use Calculator\Type\AddResponse;
use Phpro\SoapClient\Caller\Caller;

class CalculatorClient
{
/**
* @var Caller
*/
private $caller;

public function __construct(\Phpro\SoapClient\Caller\Caller $caller)
{
$this->caller = $caller;
}

public function add(Add $parameters) : AddResponse
{
return ($this->caller)('Add', $parameters);
}
}
```

We removed the debugging method from the soap-client.
Instead, you can either debug the request or result directly.
If you want to have access to the HTTP SOAP payload, we suggest adding a logger plugin to the HTTP client.
There is also a `TraceableTransport` available that can be used to detect the last SOAP request and response like you would in the old client.

This implies that changes where done to:

* the client generator
* the client factory generator
* the configuration generator

## Client Factory

In order to make the new `Caller` system available for your SOAP client,
the factory now injects the caller into your SOAP client.

```php
use Symfony\Component\EventDispatcher\EventDispatcher;
use Phpro\SoapClient\Soap\DefaultEngineFactory;
use Soap\ExtSoapEngine\ExtSoapOptions;
use Phpro\SoapClient\Caller\EventDispatchingCaller;
use Phpro\SoapClient\Caller\EngineCaller;

class CalculatorClientFactory
{
public static function factory(string $wsdl) : CalculatorClient
{
$engine = DefaultEngineFactory::create(
ExtSoapOptions::defaults($wsdl, [])
->withClassMap(CalculatorClassmap::getCollection())
);

$eventDispatcher = new EventDispatcher();
$caller = new EventDispatchingCaller(new EngineCaller($engine), $eventDispatcher);

return new CalculatorClient($caller);
}
}
```

You can opt-out on the event dispatching logic or decorate your own caller.

The `DefaultEngineFactory` can now be configured with a transport and the metadata options.
Full example on how you can personalize your factory class:

```php
use Http\Client\Common\PluginClient;
use Http\Discovery\Psr18ClientDiscovery;
use Phpro\SoapClient\Soap\DefaultEngineFactory;
use Phpro\SoapClient\Soap\ExtSoap\Metadata\Manipulators\DuplicateTypes\RemoveDuplicateTypesStrategy;use Phpro\SoapClient\Soap\Metadata\Manipulators\TypesManipulatorChain;
use Phpro\SoapClient\Soap\Metadata\MetadataOptions;
use Soap\ExtSoapEngine\ExtSoapOptions;
use Soap\ExtSoapEngine\Wsdl\Naming\Md5Strategy;
use Soap\ExtSoapEngine\Wsdl\PermanentWsdlLoaderProvider;
use Soap\Psr18Transport\Psr18Transport;
use Soap\Psr18Transport\Wsdl\Psr18Loader;

$httpClient = Psr18ClientDiscovery::find();
$engine = DefaultEngineFactory::create(
ExtSoapOptions::defaults($wsdl, [])
->withClassMap(CalculatorClassmap::getCollection())
->withWsdlProvider(
new PermanentWsdlLoaderProvider(
Psr18Loader::createForClient($httpClient),
new Md5Strategy(),
'target/location'
)
),
Psr18Transport::createForClient(
new PluginClient(
$httpClient,
[
$middleware1,
$middleware2,
]
)
),
MetadataOptions::empty()->withTypesManipulator(
new TypesManipulatorChain(
new RemoveDuplicateTypesStrategy()
)
)
);
```
Loading

0 comments on commit 662dce2

Please sign in to comment.