dmt-software /
insolvency-client
| 1 | <?php |
||
| 2 | |||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 3 | namespace DMT\Insolvency\Http\Middleware; |
||
| 4 | |||
| 5 | use DMT\Http\Client\MiddlewareInterface; |
||
| 6 | use DMT\Http\Client\RequestHandlerInterface; |
||
| 7 | use DMT\Insolvency\Exception\RequestException; |
||
| 8 | use Psr\Http\Message\RequestInterface; |
||
| 9 | use Psr\Http\Message\ResponseInterface; |
||
| 10 | use SimpleXMLElement; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Class SoapActionMiddleware |
||
| 14 | */ |
||
|
0 ignored issues
–
show
|
|||
| 15 | class SoapActionMiddleware implements MiddlewareInterface |
||
| 16 | { |
||
| 17 | /** |
||
|
0 ignored issues
–
show
|
|||
| 18 | * {@inheritDoc} |
||
| 19 | */ |
||
|
0 ignored issues
–
show
|
|||
| 20 | 12 | public function process(RequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
| 21 | { |
||
| 22 | 12 | return $handler->handle($this->withSoapHeader($request)); |
|
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
|
0 ignored issues
–
show
|
|||
| 26 | * @param RequestInterface $request |
||
|
0 ignored issues
–
show
|
|||
| 27 | * |
||
| 28 | * @return RequestInterface |
||
| 29 | * @throws RequestException |
||
| 30 | */ |
||
| 31 | 12 | private function withSoapHeader(RequestInterface $request): RequestInterface |
|
|
0 ignored issues
–
show
|
|||
| 32 | { |
||
| 33 | 12 | $request->getBody()->rewind(); |
|
| 34 | |||
| 35 | 12 | $xml = new SimpleXMLElement($request->getBody()->getContents()); |
|
| 36 | |||
| 37 | 12 | $query = '//*[local-name()="Action" and namespace-uri()="http://schemas.xmlsoap.org/ws/2004/08/addressing"]'; |
|
| 38 | 12 | $elements = $xml->xpath($query); |
|
| 39 | |||
| 40 | 12 | if (count($elements) === 0) { |
|
| 41 | 1 | throw new RequestException( |
|
| 42 | 1 | 'Malformed request, missing {http://schemas.xmlsoap.org/ws/2004/08/addressing}Action' |
|
| 43 | ); |
||
| 44 | } |
||
| 45 | |||
| 46 | return $request |
||
| 47 | 11 | ->withAddedHeader('SOAPAction', strval($elements[0])) |
|
| 48 | 11 | ->withAddedHeader('Content-Type', 'text/xml; charset=utf-8'); |
|
| 49 | } |
||
| 50 | } |