Skip to content

Commit 8453e60

Browse files
author
Gregor Becker
committed
feat(laravel-soap-199): add working ray
1 parent bdb26fd commit 8453e60

13 files changed

+514
-78
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.idea
2+
.env
23
.php_cs
34
.php_cs.cache
45
.phpunit.result.cache
@@ -12,3 +13,4 @@ testbench.yaml
1213
vendor
1314
node_modules
1415
.php-cs-fixer.cache
16+
ray.php

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
"robrichards/wse-php": "^2.0",
2828
"php-soap/psr18-transport": "^1.2",
2929
"php-soap/psr18-wsse-middleware": "^1.1",
30-
"veewee/xml": "^1.3"
30+
"veewee/xml": "^1.3",
31+
"spatie/laravel-package-tools": "^1.11",
32+
"illuminate/contracts": "^9.0"
3133
},
3234
"require-dev": {
3335
"symfony/options-resolver": "^5.4.3",

composer.lock

Lines changed: 60 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/soap.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@
1616
'namespace' => 'App\\Soap',
1717
],
1818

19+
/*
20+
|--------------------------------------------------------------------------
21+
| SOAP Code Generation directory
22+
|--------------------------------------------------------------------------
23+
|
24+
| Define the destination for the code generator under the app directory
25+
*/
26+
27+
'ray' => [
28+
'send_soap_client_requests' => false
29+
],
30+
1931
/*
2032
|--------------------------------------------------------------------------
2133
| SOAP Client Configuration

phpstan.neon

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,3 @@ parameters:
1010
checkOctaneCompatibility: true
1111
checkModelProperties: true
1212
checkMissingIterableValueType: false
13-
ignoreErrors:
14-
- '#on an unknown class Spatie\\RayBundle\\Ray#'
15-
- '#on an unknown class Spatie\\WordPressRay\\Ray#'
16-
- '#on an unknown class Spatie\\YiiRay\\Ray#'

src/Client/Request.php

Lines changed: 172 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Illuminate\Support\Arr;
66
use Illuminate\Support\Str;
7+
use Illuminate\Support\Traits\Macroable;
8+
use LogicException;
79
use Psr\Http\Message\RequestInterface;
810
use Soap\Psr18Transport\HttpBinding\SoapActionDetector;
911
use Soap\Xml\Locator\SoapBodyLocator;
@@ -18,8 +20,18 @@
1820
*/
1921
class Request
2022
{
23+
use Macroable;
24+
25+
/**
26+
* The underlying PSR request.
27+
*/
2128
protected RequestInterface $request;
2229

30+
/**
31+
* The decoded payload for the request.
32+
*/
33+
protected array $data;
34+
2335
/**
2436
* Create a new request instance.
2537
*
@@ -44,6 +56,90 @@ public function getRequest(): RequestInterface
4456
return $this->request;
4557
}
4658

59+
/**
60+
* Get the URL of the request.
61+
*/
62+
public function url(): string
63+
{
64+
return (string) $this->request->getUri();
65+
}
66+
67+
/**
68+
* Determine if the request has a given header.
69+
*
70+
* @param string $key
71+
* @param mixed $value
72+
* @return bool
73+
*/
74+
public function hasHeader($key, $value = null)
75+
{
76+
if (is_null($value)) {
77+
return ! empty($this->request->getHeaders()[$key]);
78+
}
79+
80+
$headers = $this->headers();
81+
82+
if (! Arr::has($headers, $key)) {
83+
return false;
84+
}
85+
86+
$value = is_array($value) ? $value : [$value];
87+
88+
return empty(array_diff($value, $headers[$key]));
89+
}
90+
91+
/**
92+
* Determine if the request has the given headers.
93+
*
94+
* @param array|string $headers
95+
* @return bool
96+
*/
97+
public function hasHeaders($headers)
98+
{
99+
if (is_string($headers)) {
100+
$headers = [$headers => null];
101+
}
102+
103+
foreach ($headers as $key => $value) {
104+
if (! $this->hasHeader($key, $value)) {
105+
return false;
106+
}
107+
}
108+
109+
return true;
110+
}
111+
112+
/**
113+
* Get the values for the header with the given name.
114+
*
115+
* @param string $key
116+
* @return array
117+
*/
118+
public function header($key)
119+
{
120+
return Arr::get($this->headers(), $key, []);
121+
}
122+
123+
/**
124+
* Get the request headers.
125+
*
126+
* @return array
127+
*/
128+
public function headers()
129+
{
130+
return $this->request->getHeaders();
131+
}
132+
133+
/**
134+
* Get the body of the request.
135+
*
136+
* @return string
137+
*/
138+
public function body()
139+
{
140+
return (string) $this->request->getBody();
141+
}
142+
47143
/**
48144
* Return complete xml request body.
49145
*/
@@ -61,7 +157,82 @@ public function arguments(): array
61157
{
62158
$doc = Document::fromXmlString($this->xmlContent());
63159
$method = $doc->locate(new SoapBodyLocator())?->firstElementChild;
160+
return Arr::wrap(Arr::get(element_decode($method, traverse(new RemoveNamespaces())), 'node', []));
161+
}
162+
163+
/**
164+
* Set the decoded data on the request.
165+
*
166+
* @param array $data
167+
* @return $this
168+
*/
169+
public function withData(array $data)
170+
{
171+
$this->data = $data;
172+
173+
return $this;
174+
}
175+
176+
/**
177+
* Get the underlying PSR compliant request instance.
178+
*
179+
* @return \Psr\Http\Message\RequestInterface
180+
*/
181+
public function toPsrRequest()
182+
{
183+
return $this->request;
184+
}
185+
186+
/**
187+
* Determine if the given offset exists.
188+
*
189+
* @param string $offset
190+
* @return bool
191+
*
192+
* @throws EncodingException
193+
*/
194+
public function offsetExists(string $offset): bool
195+
{
196+
return isset($this->arguments()[$offset]);
197+
}
198+
199+
/**
200+
* Get the value for a given offset.
201+
*
202+
* @param string $offset
203+
* @return mixed
204+
*
205+
* @throws EncodingException
206+
*/
207+
public function offsetGet($offset): mixed
208+
{
209+
return $this->arguments()[$offset];
210+
}
64211

65-
return Arr::get(element_decode($method, traverse(new RemoveNamespaces())), 'node', []);
212+
/**
213+
* Set the value at the given offset.
214+
*
215+
* @param string $offset
216+
* @param mixed $value
217+
* @return void
218+
*
219+
* @throws LogicException
220+
*/
221+
public function offsetSet($offset, $value): void
222+
{
223+
throw new LogicException('Request data may not be mutated using array access.');
224+
}
225+
226+
/**
227+
* Unset the value at the given offset.
228+
*
229+
* @param string $offset
230+
* @return void
231+
*
232+
* @throws LogicException
233+
*/
234+
public function offsetUnset($offset): void
235+
{
236+
throw new LogicException('Request data may not be mutated using array access.');
66237
}
67238
}

src/Client/Response.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use ArrayAccess;
66
use CodeDredd\Soap\Exceptions\RequestException;
77
use GuzzleHttp\Psr7\Response as Psr7Response;
8+
use GuzzleHttp\TransferStats;
89
use Illuminate\Support\Collection;
910
use Illuminate\Support\Str;
1011
use Illuminate\Support\Traits\Macroable;
@@ -16,6 +17,9 @@
1617

1718
/**
1819
* Class Response.
20+
*
21+
* @property ?TransferStats $transferStats
22+
* @property array $cookies
1923
*/
2024
class Response implements ResultInterface, ArrayAccess
2125
{
@@ -214,6 +218,16 @@ public function onError(callable $callback)
214218
return $this;
215219
}
216220

221+
/**
222+
* Get the handler stats of the response.
223+
*
224+
* @return array
225+
*/
226+
public function handlerStats()
227+
{
228+
return $this->transferStats?->getHandlerStats() ?? [];
229+
}
230+
217231
/**
218232
* Get the JSON decoded body of the response as an array.
219233
*/
@@ -230,6 +244,22 @@ public function json($key = null, $default = null): ?array
230244
return data_get($this->decoded, $key, $default);
231245
}
232246

247+
/**
248+
* Get a header from the response.
249+
*/
250+
public function header(string $header): string
251+
{
252+
return $this->response->getHeaderLine($header);
253+
}
254+
255+
/**
256+
* Get the headers from the response.
257+
*/
258+
public function headers(): array
259+
{
260+
return $this->response->getHeaders();
261+
}
262+
233263
/**
234264
* Determine if the given offset exists.
235265
*

0 commit comments

Comments
 (0)