mirror of
https://github.com/guzzle/guzzle.git
synced 2025-02-24 18:13:00 +01:00
Adding the ability to serialize and XML payload even if no XML parameters were set.
This commit is contained in:
parent
e575c6b2d3
commit
e03795e5a6
@ -61,9 +61,22 @@ class XmlVisitor extends AbstractRequestVisitor
|
||||
*/
|
||||
public function after(CommandInterface $command, RequestInterface $request)
|
||||
{
|
||||
$xml = null;
|
||||
|
||||
// If data was found that needs to be serialized, then do so
|
||||
if (isset($this->data[$command])) {
|
||||
$request->setBody($this->data[$command]->asXML());
|
||||
$xml = $this->data[$command]->asXML();
|
||||
unset($this->data[$command]);
|
||||
} else {
|
||||
// Check if XML should always be sent for the command
|
||||
$operation = $command->getOperation();
|
||||
if ($operation->getData('xmlAllowEmpty')) {
|
||||
$xml = $this->createRootElement($operation)->asXML();
|
||||
}
|
||||
}
|
||||
|
||||
if ($xml) {
|
||||
$request->setBody($xml);
|
||||
// Don't overwrite the Content-Type if one is set
|
||||
if ($this->contentType && !$request->hasHeader('Content-Type')) {
|
||||
$request->setHeader('Content-Type', $this->contentType);
|
||||
|
@ -503,4 +503,23 @@ class XmlVisitorTest extends AbstractVisitorTestCase
|
||||
(string) $request->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
public function testAllowsSendingXmlPayloadIfNoXmlParamsWereSet()
|
||||
{
|
||||
$operation = new Operation(array(
|
||||
'httpMethod' => 'POST',
|
||||
'data' => array('xmlAllowEmpty' => true),
|
||||
'parameters' => array('Foo' => array('location' => 'xml'))
|
||||
));
|
||||
$command = $this->getMockBuilder('Guzzle\Service\Command\OperationCommand')
|
||||
->setConstructorArgs(array(array(), $operation))
|
||||
->getMockForAbstractClass();
|
||||
$command->setClient(new Client('http://foo.com'));
|
||||
$request = $command->prepare();
|
||||
$this->assertEquals(
|
||||
'<?xml version="1.0"?>' . "\n"
|
||||
. '<Request/>' . "\n",
|
||||
(string) $request->getBody()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user