Used converters of BeSimple\SoapCommon for SoapServer
This commit is contained in:
parent
ecc3ec3c93
commit
864cf22895
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of the BeSimpleSoapBundle.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapBundle\Converter;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* @author Christian Kerl <christian-kerl@web.de>
|
||||
*/
|
||||
class ConverterRepository
|
||||
{
|
||||
private $typeConverters = array();
|
||||
|
||||
public function addTypeConverter(TypeConverterInterface $converter)
|
||||
{
|
||||
$this->typeConverters[] = $converter;
|
||||
}
|
||||
|
||||
public function getTypeConverters()
|
||||
{
|
||||
return $this->typeConverters;
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of the BeSimpleSoapBundle.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapBundle\Converter;
|
||||
|
||||
use BeSimple\SoapBundle\Soap\SoapRequest;
|
||||
use BeSimple\SoapBundle\Soap\SoapResponse;
|
||||
use BeSimple\SoapBundle\Util\String;
|
||||
|
||||
/**
|
||||
* @author Christian Kerl <christian-kerl@web.de>
|
||||
*/
|
||||
class DateTimeTypeConverter implements TypeConverterInterface
|
||||
{
|
||||
public function getTypeNamespace()
|
||||
{
|
||||
return 'http://www.w3.org/2001/XMLSchema';
|
||||
}
|
||||
|
||||
public function getTypeName()
|
||||
{
|
||||
return 'dateTime';
|
||||
}
|
||||
|
||||
public function convertXmlToPhp(SoapRequest $request, $data)
|
||||
{
|
||||
$doc = new \DOMDocument();
|
||||
$doc->loadXML($data);
|
||||
|
||||
return new \DateTime($doc->textContent);
|
||||
}
|
||||
|
||||
public function convertPhpToXml(SoapResponse $response, $data)
|
||||
{
|
||||
return sprintf('<%1$s>%2$s</%1$s>', $this->getTypeName(), $data->format('Y-m-d\TH:i:sP'));
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of the BeSimpleSoapBundle.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapBundle\Converter;
|
||||
|
||||
use BeSimple\SoapBundle\Soap\SoapRequest;
|
||||
use BeSimple\SoapBundle\Soap\SoapResponse;
|
||||
use BeSimple\SoapBundle\Util\String;
|
||||
|
||||
/**
|
||||
* @author Francis Besset <francis.besset@gmail.com>
|
||||
*/
|
||||
class DateTypeConverter implements TypeConverterInterface
|
||||
{
|
||||
public function getTypeNamespace()
|
||||
{
|
||||
return 'http://www.w3.org/2001/XMLSchema';
|
||||
}
|
||||
|
||||
public function getTypeName()
|
||||
{
|
||||
return 'date';
|
||||
}
|
||||
|
||||
public function convertXmlToPhp(SoapRequest $request, $data)
|
||||
{
|
||||
$doc = new \DOMDocument();
|
||||
$doc->loadXML($data);
|
||||
|
||||
return new \DateTime($doc->textContent);
|
||||
}
|
||||
|
||||
public function convertPhpToXml(SoapResponse $response, $data)
|
||||
{
|
||||
return sprintf('<%1$s>%2$s</%1$s>', $this->getTypeName(), $data->format('Y-m-d'));
|
||||
}
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of the BeSimpleSoapBundle.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapBundle\Converter;
|
||||
|
||||
use BeSimple\SoapBundle\Soap\SoapRequest;
|
||||
use BeSimple\SoapBundle\Soap\SoapResponse;
|
||||
|
||||
/**
|
||||
* @author Christian Kerl <christian-kerl@web.de>
|
||||
*/
|
||||
interface TypeConverterInterface
|
||||
{
|
||||
function getTypeNamespace();
|
||||
|
||||
function getTypeName();
|
||||
|
||||
function convertXmlToPhp(SoapRequest $request, $data);
|
||||
|
||||
function convertPhpToXml(SoapResponse $response, $data);
|
||||
}
|
|
@ -23,14 +23,14 @@ class TypeConverterPass implements CompilerPassInterface
|
|||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (false === $container->hasDefinition('besimple.soap.converter.repository')) {
|
||||
if (false === $container->hasDefinition('besimple.soap.converter.collection')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$definition = $container->getDefinition('besimple.soap.converter.repository');
|
||||
$definition = $container->getDefinition('besimple.soap.converter.collection');
|
||||
|
||||
foreach ($container->findTaggedServiceIds('besimple.soap.converter') as $id => $attributes) {
|
||||
$definition->addMethodCall('addTypeConverter', array(new Reference($id)));
|
||||
$definition->addMethodCall('add', array(new Reference($id)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
|
||||
<parameters>
|
||||
<parameter key="besimple.soap.converter.repository.class">BeSimple\SoapBundle\Converter\ConverterRepository</parameter>
|
||||
<parameter key="besimple.soap.converter.date_time.class">BeSimple\SoapBundle\Converter\DateTimeTypeConverter</parameter>
|
||||
<parameter key="besimple.soap.converter.date.class">BeSimple\SoapBundle\Converter\DateTypeConverter</parameter>
|
||||
<parameter key="besimple.soap.converter.collection.class">BeSimple\SoapCommon\Converter\TypeConverterCollection</parameter>
|
||||
<parameter key="besimple.soap.converter.date_time.class">BeSimple\SoapCommon\Converter\DateTimeTypeConverter</parameter>
|
||||
<parameter key="besimple.soap.converter.date.class">BeSimple\SoapCommon\Converter\DateTypeConverter</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
<service id="besimple.soap.converter.repository" class="%besimple.soap.converter.repository.class%" />
|
||||
<service id="besimple.soap.converter.collection" class="%besimple.soap.converter.collection.class%" />
|
||||
|
||||
<service id="besimple.soap.converter.date_time" class="%besimple.soap.converter.date_time.class%" public="false">
|
||||
<tag name="besimple.soap.converter" />
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
<argument type="service" id="besimple.soap.definition.loader" />
|
||||
<argument type="service" id="besimple.soap.definition.dumper.wsdl.rpcliteral" />
|
||||
<argument type="service" id="besimple.soap.type.repository" />
|
||||
<argument type="service" id="besimple.soap.converter.repository" />
|
||||
<argument type="service" id="besimple.soap.converter.collection" />
|
||||
<argument type="collection">
|
||||
<argument key="cache_dir">%besimple.soap.cache_dir%</argument>
|
||||
<argument key="debug">%kernel.debug%</argument>
|
||||
|
@ -40,7 +40,7 @@
|
|||
<argument type="service" id="besimple.soap.definition.loader" />
|
||||
<argument type="service" id="besimple.soap.definition.dumper.wsdl.documentwrapped" />
|
||||
<argument type="service" id="besimple.soap.type.repository" />
|
||||
<argument type="service" id="besimple.soap.converter.repository" />
|
||||
<argument type="service" id="besimple.soap.converter.collection" />
|
||||
<argument type="collection">
|
||||
<argument key="cache_dir">%besimple.soap.cache_dir%</argument>
|
||||
<argument key="debug">%kernel.debug%</argument>
|
||||
|
|
|
@ -10,8 +10,9 @@
|
|||
|
||||
namespace BeSimple\SoapBundle\Soap;
|
||||
|
||||
use BeSimple\SoapBundle\Converter\ConverterRepository;
|
||||
use BeSimple\SoapCommon\Cache;
|
||||
use BeSimple\SoapCommon\Converter\TypeConverterCollection;
|
||||
|
||||
use Zend\Soap\Wsdl;
|
||||
|
||||
/**
|
||||
|
@ -24,7 +25,7 @@ class SoapServerFactory
|
|||
private $converters;
|
||||
private $options;
|
||||
|
||||
public function __construct($wsdlFile, array $classmap, ConverterRepository $converters, array $options = array())
|
||||
public function __construct($wsdlFile, array $classmap, TypeConverterCollection $converters, array $options = array())
|
||||
{
|
||||
$this->wsdlFile = $wsdlFile;
|
||||
$this->classmap = $this->fixSoapServerClassmap($classmap);
|
||||
|
@ -77,15 +78,15 @@ class SoapServerFactory
|
|||
{
|
||||
$typemap = array();
|
||||
|
||||
foreach($this->converters->getTypeConverters() as $typeConverter) {
|
||||
foreach($this->converters->all() as $typeConverter) {
|
||||
$typemap[] = array(
|
||||
'type_name' => $typeConverter->getTypeName(),
|
||||
'type_ns' => $typeConverter->getTypeNamespace(),
|
||||
'from_xml' => function($input) use ($request, $typeConverter) {
|
||||
return $typeConverter->convertXmlToPhp($request, $input);
|
||||
'from_xml' => function($input) use ($typeConverter) {
|
||||
return $typeConverter->convertXmlToPhp($input);
|
||||
},
|
||||
'to_xml' => function($input) use ($response, $typeConverter) {
|
||||
return $typeConverter->convertPhpToXml($response, $input);
|
||||
'to_xml' => function($input) use ($typeConverter) {
|
||||
return $typeConverter->convertPhpToXml($input);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of the BeSimpleSoapBundle.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapBundle\Tests\Converter;
|
||||
|
||||
use BeSimple\SoapBundle\Soap\SoapRequest;
|
||||
use BeSimple\SoapBundle\Soap\SoapResponse;
|
||||
use BeSimple\SoapBundle\Converter\DateTimeTypeConverter;
|
||||
|
||||
/**
|
||||
* UnitTest for \BeSimple\SoapBundle\Converter\DateTimeTypeConverter.
|
||||
*
|
||||
* @author Christian Kerl <christian-kerl@web.de>
|
||||
*/
|
||||
class DateTimeTypeConverterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConvertXmlToPhp()
|
||||
{
|
||||
$converter = new DateTimeTypeConverter();
|
||||
|
||||
$dateXml = '<sometag>2002-10-10T12:00:00-05:00</sometag>';
|
||||
$date = $converter->convertXmlToPhp(new SoapRequest(), $dateXml);
|
||||
|
||||
$this->assertEquals(new \DateTime('2002-10-10T12:00:00-05:00'), $date);
|
||||
}
|
||||
|
||||
public function testConvertPhpToXml()
|
||||
{
|
||||
$converter = new DateTimeTypeConverter();
|
||||
|
||||
$date = new \DateTime('2002-10-10T12:00:00-05:00');
|
||||
$dateXml = $converter->convertPhpToXml(new SoapResponse(), $date);
|
||||
|
||||
$this->assertEquals('<dateTime>2002-10-10T12:00:00-05:00</dateTime>', $dateXml);
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of the BeSimpleSoapBundle.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapBundle\Tests\Converter;
|
||||
|
||||
use BeSimple\SoapBundle\Soap\SoapRequest;
|
||||
use BeSimple\SoapBundle\Soap\SoapResponse;
|
||||
use BeSimple\SoapBundle\Converter\DateTypeConverter;
|
||||
|
||||
/**
|
||||
* UnitTest for \BeSimple\SoapBundle\Converter\DateTimeTypeConverter.
|
||||
*/
|
||||
class DateTypeConverterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConvertXmlToPhp()
|
||||
{
|
||||
$converter = new DateTypeConverter();
|
||||
|
||||
$dateXml = '<sometag>2002-10-10</sometag>';
|
||||
$date = $converter->convertXmlToPhp(new SoapRequest(), $dateXml);
|
||||
|
||||
$this->assertEquals(new \DateTime('2002-10-10'), $date);
|
||||
}
|
||||
|
||||
public function testConvertPhpToXml()
|
||||
{
|
||||
$converter = new DateTypeConverter();
|
||||
|
||||
$date = new \DateTime('2002-10-10');
|
||||
$dateXml = $converter->convertPhpToXml(new SoapResponse(), $date);
|
||||
|
||||
$this->assertEquals('<date>2002-10-10</date>', $dateXml);
|
||||
}
|
||||
}
|
|
@ -10,13 +10,14 @@
|
|||
|
||||
namespace BeSimple\SoapBundle;
|
||||
|
||||
use BeSimple\SoapBundle\Converter\ConverterRepository;
|
||||
use BeSimple\SoapBundle\Converter\TypeRepository;
|
||||
use BeSimple\SoapBundle\ServiceBinding\MessageBinderInterface;
|
||||
use BeSimple\SoapBundle\ServiceBinding\ServiceBinder;
|
||||
use BeSimple\SoapBundle\ServiceDefinition\Dumper\DumperInterface;
|
||||
use BeSimple\SoapBundle\Soap\SoapServerFactory;
|
||||
|
||||
use BeSimple\SoapCommon\Converter\TypeConverterCollection;
|
||||
|
||||
use Symfony\Component\Config\ConfigCache;
|
||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
|
||||
|
@ -38,12 +39,12 @@ class WebServiceContext
|
|||
private $serviceBinder;
|
||||
private $serverFactory;
|
||||
|
||||
public function __construct(LoaderInterface $loader, DumperInterface $dumper, TypeRepository $typeRepository, ConverterRepository $converterRepository, array $options) {
|
||||
public function __construct(LoaderInterface $loader, DumperInterface $dumper, TypeRepository $typeRepository, TypeConverterCollection $converters, array $options) {
|
||||
$this->loader = $loader;
|
||||
$this->wsdlFileDumper = $dumper;
|
||||
|
||||
$this->typeRepository = $typeRepository;
|
||||
$this->converterRepository = $converterRepository;
|
||||
$this->converters = $converters;
|
||||
|
||||
$this->options = $options;
|
||||
}
|
||||
|
@ -102,7 +103,7 @@ class WebServiceContext
|
|||
$this->serverFactory = new SoapServerFactory(
|
||||
$this->getWsdlFile(),
|
||||
$this->serviceDefinition->getDefinitionComplexTypes(),
|
||||
$this->converterRepository,
|
||||
$this->converters,
|
||||
array(
|
||||
'debug' => $this->options['debug'],
|
||||
'cache_type' => isset($this->options['cache_type']) ? $this->options['cache_type'] : null,
|
||||
|
|
Loading…
Reference in New Issue