note 86519 added to book.soap
| From: | beau dot scott at gmail dot com | Date: | Wed, 22 Oct 2008 21:56:17 +0000 |
| Subject: | note 86519 added to book.soap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-145617@lists.php.net to get a copy of this message | ||
If you've been trying to send null to a service that considers empty property tags as empty
strings rather than null, here's an extending class that fixes this using xsi:nil:
class XSoapClient extends SoapClient
{
const SOAP_ENV_NS = "http://schemas.xmlsoap.org/soap/envelope/";
const XSI_NS = "http://www.w3.org/2001/XMLSchema-instance";
protected $mustParseNulls = false;
public function __doRequest($request, $location, $action, $version, $one_way = null)
{
if($this->mustParseNulls)
{
$this->mustParseNulls = false;
$dom = new DOMDocument("1.0");
$dom->loadXML($request);
$root = $dom->documentElement;
$bodies = $dom->getElementsByTagNameNS(self::SOAP_ENV_NS, 'Body');
$body = $bodies->item(0);
$params = $body->childNodes;
$i = 0;
while($child = $body->childNodes->item($i++))
{
if(!$child->hasChildNodes())
{
$child->setAttribute("xmlns:phpsoapclientsucks", self::XSI_NS);
$child->setAttribute("phpsoapclientsucks:nil", "true");
}
}
$request = $dom->saveXML();
}
return parent::__doRequest($request, $location, $action, $version, $one_way);
}
public function __call($method, $params)
{
if(count($params) == 0)
{
$this->mustParseNulls = true;
}
else
{
foreach($params as $param)
{
if($param === null)
{
$this->mustParseNulls = true;
break;
}
}
}
return parent::__call($method, $params);
}
}
----
Server IP: 64.71.164.2
Probable Submitter: 65.44.113.2
----
Manual Page -- http://www.php.net/manual/en/book.soap.php
Edit -- https://master.php.net/note/edit/86519
Del: integrated -- https://master.php.net/note/delete/86519/integrated
Del: useless -- https://master.php.net/note/delete/86519/useless
Del: bad code -- https://master.php.net/note/delete/86519/bad+code
Del: spam -- https://master.php.net/note/delete/86519/spam
Del: non-english -- https://master.php.net/note/delete/86519/non-english
Del: in docs -- https://master.php.net/note/delete/86519/in+docs
Del: other reasons-- https://master.php.net/note/delete/86519
Reject -- https://master.php.net/note/reject/86519
Search -- https://master.php.net/manage/user-notes.php