Skip to content

Commit 4469ea3

Browse files
committedDec 19, 2017
Use the new ParsedContentsInterface
1 parent ab1c148 commit 4469ea3

File tree

4 files changed

+811
-200
lines changed

4 files changed

+811
-200
lines changed
 

‎composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"require": {
1212
"php": "^7.0",
1313
"api-clients/middleware": "^4.0",
14+
"api-clients/transport": "^3.1",
1415
"fillup/array2xml": "^0.5.1",
1516
"ringcentral/psr7": "^1.2",
1617
"verdant/xml2array": "dev-master#b518d755a305fb4249027d20f8e9042bb733b857"

‎composer.lock

+803-196
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/XmlEncodeMiddleware.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use ApiClients\Foundation\Middleware\ErrorTrait;
77
use ApiClients\Foundation\Middleware\MiddlewareInterface;
88
use ApiClients\Foundation\Middleware\PostTrait;
9+
use ApiClients\Foundation\Transport\ParsedContentsInterface;
910
use fillup\A2X;
1011
use Psr\Http\Message\RequestInterface;
1112
use React\Promise\CancellablePromiseInterface;
@@ -29,11 +30,12 @@ public function pre(
2930
string $transactionId,
3031
array $options = []
3132
): CancellablePromiseInterface {
32-
if (!($request->getBody() instanceof XmlStream)) {
33+
$body = $request->getBody();
34+
if (!($body instanceof ParsedContentsInterface)) {
3335
return resolve($request);
3436
}
3537

36-
$xml = (new A2X($request->getBody()->getXml()))->asXml();
38+
$xml = (new A2X($body->getParsedContents()))->asXml();
3739
$body = new BufferStream(strlen($xml));
3840
$body->write($xml);
3941
return resolve($request->withBody($body)->withAddedHeader('Content-Type', 'text/xml'));

‎src/XmlStream.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
namespace ApiClients\Middleware\Xml;
44

5+
use ApiClients\Foundation\Transport\ParsedContentsInterface;
56
use Psr\Http\Message\StreamInterface;
67
use RingCentral\Psr7\BufferStream;
78

8-
class XmlStream implements StreamInterface
9+
class XmlStream implements StreamInterface, ParsedContentsInterface
910
{
1011
/**
1112
* @var array
@@ -28,7 +29,7 @@ public function __construct(array $xml)
2829
/**
2930
* @return array
3031
*/
31-
public function getXml()
32+
public function getParsedContents(): array
3233
{
3334
return $this->xml;
3435
}

0 commit comments

Comments
 (0)
Please sign in to comment.