Skip to content

Commit

Permalink
Merge pull request #197 from veewee/new-soap-engine
Browse files Browse the repository at this point in the history
New soap engine
  • Loading branch information
veewee committed Feb 22, 2019
2 parents 82bb72e + d463b35 commit 50a06a2
Show file tree
Hide file tree
Showing 251 changed files with 10,265 additions and 2,384 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@ cache:

matrix:
include:
- php: 7.0
- php: 7.0
env: DEPENDENCIES='low'
- php: 7.1
- php: 7.1
env: DEPENDENCIES='low'
- php: 7.2
- php: 7.2
env: DEPENDENCIES='low'
- php: 7.3
- php: 7.3
env: DEPENDENCIES='low'
fast_finish: true

before_install:
- composer selfupdate
- composer global require hirak/prestissimo

install:
- if [ "$DEPENDENCIES" != "low" ]; then travis_retry composer update --no-progress --profile --prefer-dist --no-scripts --no-interaction; fi;
Expand Down
29 changes: 20 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,24 @@ You can customize the generated code based on the manual installation pages in t

- [Add type converters.](docs/type-converter.md)
- [Listen to events.](docs/events.md)
- [Logger plugin](docs/plugins/logger.md)
- [Validator plugin](docs/plugins/validator.md)
- [Caching plugin](docs/plugins/caching.md)
- [Specify your data transfer handler.](docs/handlers.md)
- [SoapHandle](docs/handlers.md#soaphandle)
- [HTTPlugHandle](docs/handlers.md#httplughandle)
- [LocalSoapServerHandle](docs/handlers.md#localsoapserverhandle)
- [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)
- [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)


Expand Down Expand Up @@ -119,12 +125,17 @@ Implementing SOAP extensions is a real pain in the ass.
You can specify which data transfer handler like e.g. Guzzle you want to use.
Depending on the selected handler,
you can easily add support for SOAP extensions or advanced authentication through HTTP middlewares.

Dealing with ext-soap is not for all developers. There are some nasty quirks you need to know about.
Therefor, we made it possible for you to use which ever driver you want to use.
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 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.
That is why we included a ClientBuilder on which you can configure your custom Client.
That is why we included a generated ClientFactory on which you can configure your custom Client.
You want some other settings during development and in production?
No problem! Sit back and let the ClientBuilder handle your Client initialisation.
No problem! Sit back and let the factory handle your Client initialisation.
27 changes: 15 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
}
],
"require": {
"php": "^7.0",
"ext-soap": "*",
"php": "^7.1",
"ext-dom": "*",
"ext-xml": "*",
"doctrine/collections": "~1.3",
"psr/log": "^1.0",
"symfony/console": "~2.8|~3.0|~4.0",
"symfony/event-dispatcher": "~2.8|~3.0|~4.0",
"symfony/filesystem": "~2.8|~3.0|~4.0",
"symfony/validator": "~2.8|~3.0|~4.0"
"symfony/options-resolver": "^4.1"
},
"require-dev": {
"ext-soap": "*",
"guzzlehttp/guzzle": "^6.3.2",
"guzzlehttp/promises": "^1.3.1",
"guzzlehttp/psr7": "^1.4.2",
Expand All @@ -36,27 +36,30 @@
"php-http/mock-client": "^1.0",
"php-vcr/php-vcr": "~1.3.2",
"php-vcr/phpunit-testlistener-vcr": "3.0",
"phpro/grumphp": "~0.11",
"phpspec/phpspec": "~3.2",
"phpspec/prophecy": "~1.7",
"phpro/grumphp": "~0.15",
"phpspec/phpspec": "~3.4",
"phpspec/prophecy": "~1.8",
"phpunit/phpunit": "~6.0",
"psr/http-message": "^1.0",
"robrichards/wse-php": "^2.0.2",
"robrichards/xmlseclibs": "^3.0",
"squizlabs/php_codesniffer": "~2.7",
"zendframework/zend-code": "^3.1.0"
"symfony/validator": "~2.8|~3.0|~4.0",
"squizlabs/php_codesniffer": "~2.9",
"zendframework/zend-code": "^3.3.1"
},
"suggest": {
"doctrine/common": "For caching SOAP responses",
"ext-soap": "If you want to use PHP's ext-soap driver.",
"php-http/client-implementation": "For gaining control over the HTTP layer",
"phpro/annotated-cache": "For caching SOAP responses",
"psr/log-implementation": "For logging SOAP requests, responses and errors",
"psr/http-message": "For gaining control over the HTTP layer",
"php-http/httplug": "For gaining control over the HTTP layer",
"php-http/message-factory": "For gaining control over the HTTP layer",
"php-http/discovery": "For gaining control over the HTTP layer",
"php-http/message": "For gaining control over the HTTP layer",
"php-http/client-common": "For gaining control over the HTTP layer",
"monolog/monolog": "For logging SOAP transactions",
"robrichards/wse-php": "If you want to use the WSA or WSSE middleware"
"robrichards/wse-php": "If you want to use the WSA or WSSE middleware",
"symfony/validator": "If you easily want to validate SOAP requests / responses manually"
},
"autoload": {
"psr-0": {
Expand Down
28 changes: 19 additions & 9 deletions docs/cli/generate-clientfactory.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,35 @@ Example output:

namespace App\Client;

use App\Client\Client;
use App\Client\MyClient;
use App\Order\OrderClassmap;
use Phpro\SoapClient\ClientFactory as PhproClientFactory;
use Phpro\SoapClient\ClientBuilder;
use Phpro\SoapClient\Soap\Driver\ExtSoap\ExtSoapEngineFactory;
use Phpro\SoapClient\Soap\Driver\ExtSoap\ExtSoapOptions;

class ClientFactory
{

public static function factory(string $wsdl) : \App\Client
public static function factory(string $wsdl) : \App\Client\MyClient
{
$clientFactory = new PhproClientFactory(Client::class);
$clientBuilder = new ClientBuilder($clientFactory, $wsdl, []);
$clientBuilder->withClassMaps(OrderClassmap::getCollection());
$engine = ExtSoapEngineFactory::fromOptions(
ExtSoapOptions::defaults($wsdl, [])
->withClassMap(OrderClassmap::getCollection())
);
$eventDispatcher = new EventDispatcher();

return $clientBuilder->build();
return new MyClient($engine, $eventDispatcher);
}

}


```

You can then tweak this class to fit your needs.
You can then tweak this class to fit your needs.

Here you can find some bookmarks for changing the factory:

- [Configuring ExtSoapOptions](../drivers/ext-soap.md#extsoapoptions)
- [Listening to events](../events.md)
- [Configuring the engine](../engine.md)
- [Using HTTP middleware](../middlewares.md)
36 changes: 12 additions & 24 deletions docs/code-generation/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ The code generation commands require a configuration file to determine how the S
use Phpro\SoapClient\CodeGenerator\Config\Config;
use Phpro\SoapClient\CodeGenerator\Rules;
use Phpro\SoapClient\CodeGenerator\Assembler;
use Phpro\SoapClient\Soap\Driver\ExtSoap\ExtSoapOptions;
use Phpro\SoapClient\Soap\Driver\ExtSoap\ExtSoapEngineFactory;

return Config::create()
->setWsdl('http://localhost/path/to/soap.wsdl')
->setEngine(ExtSoapEngineFactory::fromOptions(
ExtSoapOptions::defaults('wsdl.xml', [])
->disableWsdlCache()
))
->setTypeDestination('src/SoapTypes')
->setTypeNamespace('SoapTypes')
->setClientDestination('src/SoapClient')
Expand All @@ -20,7 +25,6 @@ return Config::create()
->setClassMapNamespace('Acme\\Classmap')
->setClassMapDestination('src/acme/classmap')
->setClassMapName('AcmeClassmap')
->addSoapOption('features', SOAP_SINGLE_ELEMENT_ARRAYS)
->addRule(new Rules\AssembleRule(new Assembler\GetterAssembler(
(new Assembler\GetterAssemblerOptions())
->withReturnType()
Expand All @@ -40,12 +44,15 @@ return Config::create()
Luckily a command is provided to generate this for you in an interactive manner.
Execute `vendor/bin/soap-client generate:config` to start the interactive config generator.

**wsdl**
**engine**

String - REQUIRED
`Phpro\SoapClient\Soap\Engine\Engine` - REQUIRED

The full path the the WSDL file you want to parse
Specify how the code generation tool can talk to SOAP.
By default, we push PHP's built-in ext-soap engine by code generation.
However, it is possible to change this to any other engine you want to use.

[Read more about engines.](../engine.md)

**type destination**

Expand All @@ -59,25 +66,6 @@ String - REQUIRED

The destination of the generated soap client.


**soapOptions**

Array - OPTIONAL

The soap options you want to add to the SoapClient during code generation.
Default values:


```php
[
'trace' => false,
'exceptions' => true,
'keep_alive' => true,
'cache_wsdl' => WSDL_CACHE_NONE,
]
```


**type namespace**

String - OPTIONAL
Expand Down
46 changes: 46 additions & 0 deletions docs/drivers/ext-soap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# ExtSoapDriver

```
❗️ Make sure ext-soap is loaded.
```

This soap driver wraps PHPs ext-soap `\SoapClient` implementation.

- It abuses the `__doRequest()` method to make it possible to encode the request and decode the response.
- Metadata is being parsed based on the `__getTypes()` and `__getFunctions()` method.

**Example usage**

```php
<?php

use Phpro\SoapClient\Soap\Driver\ExtSoap\ExtSoapEngineFactory;
use Phpro\SoapClient\Soap\Driver\ExtSoap\ExtSoapOptions;

$engine = ExtSoapEngineFactory::fromOptions(ExtSoapOptions::defaults($wsdl, []));
$client = new MyClient($engine, $eventDispatcher);
````

## ExtSoapOptions

This package provides a little wrapper around all available `\SoapClient` options.
We provide some default options and the additional options can be configured in a sane way.
It will validate the options before they are passed to the `\SoapClient`.
This way, you'll spend less time browsing the official PHP documentation.

**Example usage**

```php
<?php

use Phpro\SoapClient\Soap\Driver\ExtSoap\ExtSoapOptions;
use Phpro\SoapClient\Wsdl\Provider\HttPlugWsdlProvider;

$options = ExtSoapOptions::defaults($wsdl, ['location' => 'http://somedifferentserver.com'])
->disableWsdlCache()
->withClassMap(MyClassMap::getCollection())
->withWsdlProvider(HttPlugWsdlProvider::createForClient($httpClient));

$typemap = $options->getTypeMap();
$typemap->add(new MyTypeConverter());
```

0 comments on commit 50a06a2

Please sign in to comment.