diff --git a/src/BeSimple/SoapCommon/Converter/TypeConverterCollection.php b/src/BeSimple/SoapCommon/Converter/TypeConverterCollection.php index fbdd79b..099d0eb 100644 --- a/src/BeSimple/SoapCommon/Converter/TypeConverterCollection.php +++ b/src/BeSimple/SoapCommon/Converter/TypeConverterCollection.php @@ -28,4 +28,27 @@ class TypeConverterCollection { return $this->typeConverters; } + + /** + * @return array + */ + public function getTypemap() + { + $typemap = array(); + + foreach ($this->all() as $typeConverter) { + $typemap[] = array( + 'type_name' => $typeConverter->getTypeName(), + 'type_ns' => $typeConverter->getTypeNamespace(), + 'from_xml' => function($input) use ($typeConverter) { + return $typeConverter->convertXmlToPhp($input); + }, + 'to_xml' => function($input) use ($typeConverter) { + return $typeConverter->convertPhpToXml($input); + }, + ); + } + + return $typemap; + } } diff --git a/tests/BeSimple/Tests/SoapCommon/Converter/TypeConverterCollectionTest.php b/tests/BeSimple/Tests/SoapCommon/Converter/TypeConverterCollectionTest.php index 4c9feef..19865f1 100644 --- a/tests/BeSimple/Tests/SoapCommon/Converter/TypeConverterCollectionTest.php +++ b/tests/BeSimple/Tests/SoapCommon/Converter/TypeConverterCollectionTest.php @@ -37,4 +37,29 @@ class TypeConverterCollectionTest extends \PHPUnit_Framework_TestCase $this->assertSame(array($dateTimeTypeConverter, $dateTypeConverter), $converters->all()); } + + public function testGetTypemap() + { + $converters = new TypeConverterCollection(); + + $this->assertEquals(array(), $converters->getTypemap()); + + $dateTimeTypeConverter = new DateTimeTypeConverter(); + $converters->add($dateTimeTypeConverter); + + $dateTypeConverter = new DateTypeConverter(); + $converters->add($dateTypeConverter); + + $typemap = $converters->getTypemap(); + + $this->assertEquals('http://www.w3.org/2001/XMLSchema', $typemap[0]['type_ns']); + $this->assertEquals('dateTime', $typemap[0]['type_name']); + $this->assertInstanceOf('Closure', $typemap[0]['from_xml']); + $this->assertInstanceOf('Closure', $typemap[0]['to_xml']); + + $this->assertEquals('http://www.w3.org/2001/XMLSchema', $typemap[1]['type_ns']); + $this->assertEquals('date', $typemap[1]['type_name']); + $this->assertInstanceOf('Closure', $typemap[1]['from_xml']); + $this->assertInstanceOf('Closure', $typemap[1]['to_xml']); + } } \ No newline at end of file