2011-02-03 01:07:08 +01:00
|
|
|
<?php
|
|
|
|
/*
|
2011-07-18 22:43:12 +02:00
|
|
|
* This file is part of the BeSimpleSoapBundle.
|
2011-02-03 01:07:08 +01:00
|
|
|
*
|
|
|
|
* (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.
|
|
|
|
*/
|
|
|
|
|
2011-07-18 22:43:12 +02:00
|
|
|
namespace BeSimple\SoapBundle\Soap;
|
2011-02-03 01:07:08 +01:00
|
|
|
|
2011-07-18 22:43:12 +02:00
|
|
|
use BeSimple\SoapBundle\Converter\ConverterRepository;
|
2011-02-03 01:07:08 +01:00
|
|
|
|
2011-07-17 10:46:54 +02:00
|
|
|
/**
|
|
|
|
* @author Christian Kerl <christian-kerl@web.de>
|
|
|
|
*/
|
2011-02-03 01:07:08 +01:00
|
|
|
class SoapServerFactory
|
|
|
|
{
|
2011-04-07 21:52:59 +02:00
|
|
|
private $wsdlFile;
|
2011-07-17 15:08:46 +02:00
|
|
|
private $classmap;
|
|
|
|
private $converters;
|
2011-07-17 12:35:47 +02:00
|
|
|
private $debug;
|
2011-02-03 01:07:08 +01:00
|
|
|
|
2011-07-17 15:08:46 +02:00
|
|
|
public function __construct($wsdlFile, array $classmap, ConverterRepository $converters, $debug = false)
|
2011-02-03 01:07:08 +01:00
|
|
|
{
|
2011-07-17 10:46:54 +02:00
|
|
|
$this->wsdlFile = $wsdlFile;
|
2011-07-17 15:08:46 +02:00
|
|
|
$this->classmap = $classmap;
|
2011-02-03 01:07:08 +01:00
|
|
|
$this->converters = $converters;
|
2011-07-17 12:35:47 +02:00
|
|
|
$this->debug = $debug;
|
2011-02-03 01:07:08 +01:00
|
|
|
}
|
|
|
|
|
2011-07-17 10:46:54 +02:00
|
|
|
public function create($request, $response)
|
2011-02-03 01:07:08 +01:00
|
|
|
{
|
2011-07-17 12:35:47 +02:00
|
|
|
return new \SoapServer(
|
2011-04-07 21:52:59 +02:00
|
|
|
$this->wsdlFile,
|
2011-02-03 01:07:08 +01:00
|
|
|
array(
|
2011-07-17 15:08:46 +02:00
|
|
|
'classmap' => $this->classmap,
|
2011-07-17 12:35:47 +02:00
|
|
|
'typemap' => $this->createSoapServerTypemap($request, $response),
|
|
|
|
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
|
|
|
|
'cache_wsdl' => $this->debug ? WSDL_CACHE_NONE : WSDL_CACHE_DISK,
|
2011-02-03 01:07:08 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-07-17 10:46:54 +02:00
|
|
|
private function createSoapServerTypemap($request, $response)
|
2011-02-03 01:07:08 +01:00
|
|
|
{
|
2011-07-17 12:35:47 +02:00
|
|
|
$typemap = array();
|
2011-02-03 01:07:08 +01:00
|
|
|
|
2011-07-14 17:45:03 +02:00
|
|
|
foreach($this->converters->getTypeConverters() as $typeConverter) {
|
2011-07-17 12:35:47 +02:00
|
|
|
$typemap[] = array(
|
2011-02-03 01:07:08 +01:00
|
|
|
'type_name' => $typeConverter->getTypeName(),
|
2011-07-17 10:46:54 +02:00
|
|
|
'type_ns' => $typeConverter->getTypeNamespace(),
|
|
|
|
'from_xml' => function($input) use ($request, $typeConverter) {
|
2011-02-03 01:07:08 +01:00
|
|
|
return $typeConverter->convertXmlToPhp($request, $input);
|
|
|
|
},
|
2011-07-17 10:46:54 +02:00
|
|
|
'to_xml' => function($input) use ($response, $typeConverter) {
|
2011-02-03 01:07:08 +01:00
|
|
|
return $typeConverter->convertPhpToXml($response, $input);
|
2011-07-17 10:46:54 +02:00
|
|
|
},
|
2011-02-03 01:07:08 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-07-17 12:35:47 +02:00
|
|
|
return $typemap;
|
2011-02-03 01:07:08 +01:00
|
|
|
}
|
2011-07-14 17:45:03 +02:00
|
|
|
}
|