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-09-04 01:59:32 +02:00
|
|
|
use BeSimple\SoapCommon\Cache;
|
2011-08-24 23:36:49 +02:00
|
|
|
use Zend\Soap\Wsdl;
|
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-09-04 12:59:19 +02:00
|
|
|
private $options;
|
2011-02-03 01:07:08 +01:00
|
|
|
|
2011-09-04 12:59:19 +02:00
|
|
|
public function __construct($wsdlFile, array $classmap, ConverterRepository $converters, array $options = array())
|
2011-02-03 01:07:08 +01:00
|
|
|
{
|
2011-07-17 10:46:54 +02:00
|
|
|
$this->wsdlFile = $wsdlFile;
|
2011-08-24 23:36:49 +02:00
|
|
|
$this->classmap = $this->fixSoapServerClassmap($classmap);
|
2011-02-03 01:07:08 +01:00
|
|
|
$this->converters = $converters;
|
2011-09-04 12:59:19 +02:00
|
|
|
$this->setOptions($options);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setOptions(array $options)
|
|
|
|
{
|
|
|
|
$this->options = array(
|
|
|
|
'debug' => false,
|
|
|
|
'cache_type' => null,
|
|
|
|
);
|
|
|
|
|
|
|
|
// check option names and live merge, if errors are encountered Exception will be thrown
|
|
|
|
$invalid = array();
|
|
|
|
$isInvalid = false;
|
|
|
|
foreach ($options as $key => $value) {
|
|
|
|
if (array_key_exists($key, $this->options)) {
|
|
|
|
$this->options[$key] = $value;
|
|
|
|
} else {
|
|
|
|
$isInvalid = true;
|
|
|
|
$invalid[] = $key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($isInvalid) {
|
|
|
|
throw new \InvalidArgumentException(sprintf(
|
|
|
|
'The "%s" class does not support the following options: "%s".',
|
|
|
|
get_class($this),
|
|
|
|
implode('\', \'', $invalid)
|
|
|
|
));
|
|
|
|
}
|
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,
|
2011-09-04 12:59:19 +02:00
|
|
|
'cache_wsdl' => null !== $this->options['cache_type'] ? $this->options['cache_type'] : Cache::getType(),
|
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-08-24 23:36:49 +02:00
|
|
|
|
|
|
|
private function fixSoapServerClassmap($classmap)
|
|
|
|
{
|
|
|
|
$classmapFixed = array();
|
|
|
|
|
|
|
|
foreach ($classmap as $class => $definition) {
|
|
|
|
$classmapFixed[Wsdl::translateType($class)] = $class;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $classmapFixed;
|
|
|
|
}
|
2011-07-14 17:45:03 +02:00
|
|
|
}
|