Deleted SoapClient
This commit is contained in:
@ -12,190 +12,9 @@
|
||||
|
||||
namespace BeSimple\SoapClient;
|
||||
|
||||
use BeSimple\SoapCommon\Cache;
|
||||
use BeSimple\SoapCommon\Classmap;
|
||||
use BeSimple\SoapCommon\Converter\TypeConverterCollection;
|
||||
|
||||
/**
|
||||
* @author Francis Besset <francis.besset@gmail.com>
|
||||
*/
|
||||
class SoapClient
|
||||
class SoapClient extends \SoapClient
|
||||
{
|
||||
protected $wsdl;
|
||||
protected $classmap;
|
||||
protected $converters;
|
||||
protected $soapClient;
|
||||
|
||||
/**
|
||||
* @param string $wsdl
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct($wsdl, array $options = array(), Classmap $classmap = null, TypeConverterCollection $converters = null)
|
||||
{
|
||||
$this->wsdl = $wsdl;
|
||||
$this->classmap = $classmap;
|
||||
$this->converters = $converters;
|
||||
|
||||
$this->setOptions($options);
|
||||
}
|
||||
|
||||
public function setOptions(array $options)
|
||||
{
|
||||
$this->options = array(
|
||||
'debug' => false,
|
||||
'cache_type' => null,
|
||||
'namespace' => null,
|
||||
'exceptions' => true,
|
||||
'user_agent' => 'BeSimpleSoap',
|
||||
);
|
||||
|
||||
// check option names and live merge, if errors are encountered Exception will be thrown
|
||||
$invalid = array();
|
||||
$isInvalid = false;
|
||||
foreach ($options as $key => $value) {
|
||||
if (array_key_exists($key, $this->options)) {
|
||||
$this->options[$key] = $value;
|
||||
} else {
|
||||
$isInvalid = true;
|
||||
$invalid[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
if ($isInvalid) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'The "%s" class does not support the following options: "%s".',
|
||||
get_class($this),
|
||||
implode('\', \'', $invalid)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name The name
|
||||
* @param mixed $value The value
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function setOption($name, $value)
|
||||
{
|
||||
if (!array_key_exists($name, $this->options)) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'The "%s" class does not support the "%s" option.',
|
||||
get_class($this),
|
||||
$name
|
||||
));
|
||||
}
|
||||
|
||||
$this->options[$name] = $value;
|
||||
}
|
||||
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key The key
|
||||
*
|
||||
* @return mixed The value
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function getOption($key)
|
||||
{
|
||||
if (!array_key_exists($key, $this->options)) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'The "%s" class does not support the "%s" option.',
|
||||
get_class($this),
|
||||
$key
|
||||
));
|
||||
}
|
||||
|
||||
return $this->options[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SoapRequest $soapRequest
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function send(SoapRequest $soapRequest)
|
||||
{
|
||||
return $this->getNativeSoapClient()->__soapCall(
|
||||
$soapRequest->getFunction(),
|
||||
$soapRequest->getArguments(),
|
||||
$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
|
||||
*/
|
||||
public function getNativeSoapClient()
|
||||
{
|
||||
if (!$this->soapClient) {
|
||||
$this->soapClient = new \SoapClient($this->wsdl, $this->getSoapOptions());
|
||||
}
|
||||
|
||||
return $this->soapClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array The \SoapClient options
|
||||
*/
|
||||
public function getSoapOptions()
|
||||
{
|
||||
if (null === $this->options['cache_type']) {
|
||||
$this->options['cache_type'] = Cache::getType();
|
||||
}
|
||||
|
||||
return array(
|
||||
'cache_wsdl' => $this->options['cache_type'],
|
||||
'trace' => $this->options['debug'],
|
||||
'classmap' => $this->getClassmap(),
|
||||
'exceptions' => $this->options['exceptions'],
|
||||
'typemap' => $this->getTypemap(),
|
||||
'user_agent' => $this->options['user_agent'],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getClassmap()
|
||||
{
|
||||
if (!$this->classmap) {
|
||||
return array();
|
||||
}
|
||||
|
||||
return $this->classmap->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getTypemap()
|
||||
{
|
||||
if (!$this->converters) {
|
||||
return array();
|
||||
}
|
||||
|
||||
return $this->converters->getTypemap();
|
||||
}
|
||||
}
|
@ -29,6 +29,19 @@ class SoapClientBuilder extends AbstractSoapBuilder
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SoapClient
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
$this->validateOptions();
|
||||
|
||||
return new SoapClient($this->optionWsdl, $this->options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SoapClientBuilder
|
||||
*/
|
||||
public function withTrace($trace = true)
|
||||
{
|
||||
$this->soapOptions['trace'] = $trace;
|
||||
@ -36,6 +49,9 @@ class SoapClientBuilder extends AbstractSoapBuilder
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SoapClientBuilder
|
||||
*/
|
||||
public function withExceptions($exceptions = true)
|
||||
{
|
||||
$this->soapOptions['exceptions'] = $exceptions;
|
||||
@ -43,10 +59,18 @@ class SoapClientBuilder extends AbstractSoapBuilder
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SoapClientBuilder
|
||||
*/
|
||||
public function withUserAgent($userAgent)
|
||||
{
|
||||
$this->soapOptions['user_agent'] = $userAgent;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function validateOptions()
|
||||
{
|
||||
$this->validateWsdl();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user