Added SoapHeader in SoapRequest

This commit is contained in:
Francis Besset
2011-09-04 23:42:03 +02:00
parent caeb484e19
commit 5790a89571
4 changed files with 104 additions and 5 deletions

View File

@ -37,6 +37,7 @@ class SoapClient
$this->options = array(
'debug' => false,
'cache_type' => null,
'namespace' => null,
);
// check option names and live merge, if errors are encountered Exception will be thrown
@ -114,10 +115,26 @@ class SoapClient
return $this->getNativeSoapClient()->__soapCall(
$soapRequest->getFunction(),
$soapRequest->getArguments(),
$soapRequest->getOptions()
$soapRequest->getOptions(),
$soapRequest->getHeaders()
);
}
/**
* @param string The SoapHeader name
* @param mixed The SoapHeader value
*
* @return \SoapHeader
*/
public function createSoapHeader($name, $value)
{
if (null === $namespace = $this->getOption('namespace')) {
throw new \RuntimeException('You cannot create SoapHeader if you do not specify a namespace.');
}
return new \SoapHeader($namespace, $name, $value);
}
/**
* @return \SoapClient
*/

View File

@ -20,12 +20,14 @@ class SoapRequest
protected $function;
protected $arguments;
protected $options;
protected $headers;
public function __construct($function = null, array $arguments = array(), array $options = array())
public function __construct($function = null, array $arguments = array(), array $options = array(), array $headers = array())
{
$this->function = $function;
$this->arguments = $arguments;
$this->options = $options;
$this->setHeaders($headers);
}
/**
@ -143,6 +145,42 @@ class SoapRequest
return $this;
}
/**
* @return array
*/
public function getHeaders()
{
return $this->headers;
}
/**
* @param array $headers
*
* @return SoapRequest
*/
public function setHeaders(array $headers)
{
$this->headers = array();
foreach ($headers as $header) {
$this->addHeader($header);
}
return $this;
}
/**
* @param \SoapHeader $header
*
* @return SoapRequest
*/
public function addHeader(\SoapHeader $header)
{
$this->headers[] = $header;
return $this;
}
/**
* @param string The name of option
* @param mixed The value of option