Skip to content

Commit 9f884a6

Browse files
author
Gregor Becker
committed
refactor(laravel-soap-179): Apply review discussion
- Added Flattingloader - Using SoapActionDetector - bit more code clean up to PHP 8 standard
1 parent 125577d commit 9f884a6

File tree

2 files changed

+31
-86
lines changed

2 files changed

+31
-86
lines changed

src/Client/Request.php

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,26 @@
66
use CodeDredd\Soap\Xml\XMLSerializer;
77
use Illuminate\Support\Arr;
88
use Illuminate\Support\Str;
9+
use Psr\Http\Message\RequestInterface;
10+
use Soap\Psr18Transport\HttpBinding\SoapActionDetector;
911
use Soap\Xml\Locator\SoapBodyLocator;
1012
use VeeWee\Xml\Dom\Document;
13+
use function VeeWee\Xml\Dom\Configurator\optimize_namespaces;
14+
use function VeeWee\Xml\Dom\Configurator\pretty_print;
15+
use function VeeWee\Xml\Dom\Configurator\utf8;
16+
use function VeeWee\Xml\Encoding\xml_decode;
1117

1218
/**
1319
* Class Request.
1420
*/
1521
class Request
1622
{
17-
/**
18-
* The underlying PSR request.
19-
*
20-
* @var \Psr\Http\Message\RequestInterface
21-
*/
22-
protected $request;
23+
protected RequestInterface $request;
2324

2425
/**
2526
* Create a new request instance.
2627
*
27-
* @param \Psr\Http\Message\RequestInterface $request
28+
* @param RequestInterface $request
2829
* @return void
2930
*/
3031
public function __construct($request)
@@ -34,42 +35,27 @@ public function __construct($request)
3435

3536
/**
3637
* Get the soap action for soap 1.1 and 1.2.
37-
*
38-
* @return string
3938
*/
4039
public function action(): string
4140
{
42-
$contentType = $this->request->getHeaderLine('Content-Type');
43-
$soapAction = $this->request->getHeaderLine('SOAPAction');
44-
if (empty($soapAction)) {
45-
return Str::of($contentType)->afterLast('action=')->remove('"');
46-
}
47-
48-
return Str::of($this->request->getHeaderLine('SOAPAction'))->remove('"');
41+
return Str::remove('"', SoapActionDetector::detectFromRequest($this->request));
4942
}
5043

51-
/**
52-
* @return \Psr\Http\Message\RequestInterface
53-
*/
54-
public function getRequest()
44+
public function getRequest(): RequestInterface
5545
{
5646
return $this->request;
5747
}
5848

5949
/**
6050
* Return complete xml request body.
61-
*
62-
* @return string
6351
*/
64-
public function xmlContent()
52+
public function xmlContent(): string
6553
{
6654
return $this->request->getBody()->getContents();
6755
}
6856

6957
/**
7058
* Return request arguments.
71-
*
72-
* @return array
7359
*/
7460
public function arguments(): array
7561
{

src/SoapClient.php

Lines changed: 20 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,30 @@
77
use CodeDredd\Soap\Driver\ExtSoap\ExtSoapEngineFactory;
88
use CodeDredd\Soap\Exceptions\NotFoundConfigurationException;
99
use CodeDredd\Soap\Exceptions\SoapException;
10-
use CodeDredd\Soap\Faker\EngineFaker;
1110
use CodeDredd\Soap\Middleware\CisDhlMiddleware;
1211
use CodeDredd\Soap\Middleware\WsseMiddleware;
1312
use GuzzleHttp\Client;
1413
use GuzzleHttp\HandlerStack;
1514
use Http\Client\Common\PluginClient;
1615
use Http\Client\Exception\HttpException;
17-
use Http\Client\HttpClient;
18-
use Http\Discovery\Psr17FactoryDiscovery;
1916
use Illuminate\Contracts\Validation\Validator;
20-
use Illuminate\Support\Facades\Http;
17+
use Illuminate\Support\Arr;
2118
use Illuminate\Support\Str;
2219
use Illuminate\Support\Traits\Macroable;
2320
use Phpro\SoapClient\Type\ResultInterface;
2421
use Phpro\SoapClient\Type\ResultProviderInterface;
2522
use Psr\Http\Client\ClientInterface;
2623
use Soap\Engine\Engine;
2724
use Soap\Engine\Transport;
25+
use Soap\ExtSoapEngine\AbusedClient;
2826
use Soap\ExtSoapEngine\ExtSoapOptions;
2927
use Soap\ExtSoapEngine\Transport\TraceableTransport;
30-
use Soap\ExtSoapEngine\Wsdl\InMemoryWsdlProvider;
3128
use Soap\ExtSoapEngine\Wsdl\PassThroughWsdlProvider;
3229
use Soap\ExtSoapEngine\Wsdl\WsdlProvider;
3330
use Soap\Psr18Transport\Psr18Transport;
3431
use Soap\Psr18Transport\Wsdl\Psr18Loader;
3532
use Soap\Psr18WsseMiddleware\WsaMiddleware;
33+
use Soap\Wsdl\Loader\FlatteningLoader;
3634

3735
/**
3836
* Class SoapClient.
@@ -47,76 +45,37 @@ class SoapClient
4745

4846
protected PluginClient $pluginClient;
4947

50-
/**
51-
* @var Engine
52-
*/
53-
protected $engine;
48+
protected Engine $engine;
5449

55-
/**
56-
* @var array
57-
*/
58-
protected $options = [];
50+
protected array $options = [];
5951

60-
/**
61-
* @var ExtSoapOptions
62-
*/
63-
protected $extSoapOptions;
52+
protected ExtSoapOptions $extSoapOptions;
6453

65-
/**
66-
* @var TraceableTransport
67-
*/
68-
protected $transport;
54+
protected TraceableTransport $transport;
6955

70-
/**
71-
* @var array
72-
*/
73-
protected $guzzleClientOptions = [];
56+
protected array $guzzleClientOptions = [];
7457

75-
/**
76-
* @var string
77-
*/
78-
protected $wsdl = '';
58+
protected string $wsdl = '';
7959

80-
/**
81-
* @var bool
82-
*/
83-
protected $isClientBuilded = false;
60+
protected bool $isClientBuilded = false;
8461

85-
/**
86-
* @var array
87-
*/
88-
protected $middlewares = [];
62+
protected array $middlewares = [];
8963

90-
/**
91-
* @var SoapFactory|null
92-
*/
93-
protected $factory;
64+
protected SoapFactory|null $factory;
9465

95-
/**
96-
* @var Psr18Loader|WsdlProvider
97-
*/
98-
protected $wsdlProvider;
66+
protected FlatteningLoader|WsdlProvider $wsdlProvider;
9967

100-
/**
101-
* The request cookies.
102-
*
103-
* @var array
104-
*/
105-
protected $cookies;
68+
protected array $cookies;
10669

10770
/**
10871
* The callbacks that should execute before the request is sent.
109-
*
110-
* @var array
11172
*/
112-
protected $beforeSendingCallbacks;
73+
protected \Illuminate\Support\Collection $beforeSendingCallbacks;
11374

11475
/**
11576
* The stub callables that will handle requests.
116-
*
117-
* @var \Illuminate\Support\Collection|null
11877
*/
119-
protected $stubCallbacks;
78+
protected \Illuminate\Support\Collection|null $stubCallbacks;
12079

12180
/**
12281
* Create a new Soap Client instance.
@@ -129,16 +88,16 @@ public function __construct(SoapFactory $factory = null)
12988
$this->factory = $factory;
13089
$this->client = new Client($this->guzzleClientOptions);
13190
$this->pluginClient = new PluginClient($this->client, $this->middlewares);
132-
$this->wsdlProvider = Psr18Loader::createForClient($this->pluginClient);
91+
$this->wsdlProvider = new FlatteningLoader(Psr18Loader::createForClient($this->pluginClient));
13392
$this->beforeSendingCallbacks = collect([
13493
function (Request $request, array $options) {
135-
$this->cookies = $options['cookies'];
94+
$this->cookies = Arr::wrap($options['cookies']);
13695
},
13796
]);
13897
}
13998

14099
public function refreshWsdlProvider(){
141-
$this->wsdlProvider = Psr18Loader::createForClient($this->pluginClient);
100+
$this->wsdlProvider = new FlatteningLoader(Psr18Loader::createForClient($this->pluginClient));
142101

143102
return $this;
144103
}
@@ -160,7 +119,7 @@ public function getPluginClient(): PluginClient
160119

161120
protected function setTransport(Transport $handler = null): static
162121
{
163-
$soapClient = \Soap\ExtSoapEngine\AbusedClient::createFromOptions(
122+
$soapClient = AbusedClient::createFromOptions(
164123
ExtSoapOptions::defaults($this->wsdl, $this->options)
165124
);
166125
$transport = $handler ?? Psr18Transport::createForClient($this->pluginClient);

0 commit comments

Comments
 (0)