[SoapClient] Added Classmap

This commit is contained in:
Francis Besset 2011-10-08 15:07:49 +02:00
parent 7be719ffc5
commit 29a388eb7d
2 changed files with 40 additions and 4 deletions

View File

@ -13,6 +13,7 @@
namespace BeSimple\SoapClient;
use BeSimple\SoapCommon\Cache;
use BeSimple\SoapCommon\Classmap;
use BeSimple\SoapCommon\Converter\TypeConverterCollection;
/**
@ -21,6 +22,7 @@ use BeSimple\SoapCommon\Converter\TypeConverterCollection;
class SoapClient
{
protected $wsdl;
protected $classmap;
protected $converters;
protected $soapClient;
@ -28,9 +30,10 @@ class SoapClient
* @param string $wsdl
* @param array $options
*/
public function __construct($wsdl, array $options = array(), TypeConverterCollection $converters = null)
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);
@ -163,10 +166,23 @@ class SoapClient
return array(
'cache_wsdl' => $this->options['cache_type'],
'trace' => $this->options['debug'],
'classmap' => $this->getClassmap(),
'typemap' => $this->getTypemap(),
);
}
/**
* @return array
*/
protected function getClassmap()
{
if (!$this->classmap) {
return array();
}
return $this->classmap->all();
}
/**
* @return array
*/

View File

@ -13,6 +13,7 @@
namespace BeSimple\Tests\SoapClient;
use BeSimple\SoapCommon\Cache;
use BeSimple\SoapCommon\Classmap;
use BeSimple\SoapCommon\Converter\DateTimeTypeConverter;
use BeSimple\SoapCommon\Converter\DateTypeConverter;
use BeSimple\SoapCommon\Converter\TypeConverterCollection;
@ -88,10 +89,29 @@ class SoapClientTest extends \PHPUnit_Framework_TestCase
{
Cache::setType(Cache::TYPE_MEMORY);
$soapClient = new SoapClient('foo.wsdl', array('debug' => true));
$this->assertEquals(array('cache_wsdl' => Cache::getType(), 'trace' => true, 'typemap' => array()), $soapClient->getSoapOptions());
$this->assertEquals(array('cache_wsdl' => Cache::getType(), 'trace' => true, 'classmap' => array(), 'typemap' => array()), $soapClient->getSoapOptions());
$soapClient = new SoapClient('foo.wsdl', array('debug' => false, 'cache_type' => Cache::TYPE_NONE));
$this->assertEquals(array('cache_wsdl' => Cache::TYPE_NONE, 'trace' => false, 'typemap' => array()), $soapClient->getSoapOptions());
$this->assertEquals(array('cache_wsdl' => Cache::TYPE_NONE, 'trace' => false, 'classmap' => array(), 'typemap' => array()), $soapClient->getSoapOptions());
}
public function testGetSoapOptionsWithClassmap()
{
$classmap = new Classmap();
$soapClient = new SoapClient('foo.wsdl', array(), $classmap);
$soapOptions = $soapClient->getSoapOptions();
$this->assertSame(array(), $soapOptions['classmap']);
$map = array(
'foobar' => 'BeSimple\SoapClient\SoapClient',
'barfoo' => 'BeSimple\SoapClient\Tests\SoapClientTest',
);
$classmap->set($map);
$soapOptions = $soapClient->getSoapOptions();
$this->assertSame($map, $soapOptions['classmap']);
}
public function testGetSoapOptionsWithTypemap()
@ -104,7 +124,7 @@ class SoapClientTest extends \PHPUnit_Framework_TestCase
$dateTypeConverter = new DateTypeConverter();
$converters->add($dateTypeConverter);
$soapClient = new SoapClient('foo.wsdl', array(), $converters);
$soapClient = new SoapClient('foo.wsdl', array(), null, $converters);
$soapOptions = $soapClient->getSoapOptions();
$this->assertEquals('http://www.w3.org/2001/XMLSchema', $soapOptions['typemap'][0]['type_ns']);