Added TypeConverterCollection::getTypemap() function
This commit is contained in:
parent
9b0ec8816d
commit
c2a2413330
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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']);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue