SoapClient large refactoring & tests update

This commit is contained in:
Petr Bechyně
2017-02-03 15:22:37 +01:00
parent 00ddf149b0
commit aee034791e
78 changed files with 4957 additions and 1126 deletions

View File

@ -13,27 +13,45 @@
namespace BeSimple\SoapBundle;
use BeSimple\SoapCommon\Cache as BaseCache;
use BeSimple\SoapCommon\SoapOptions\SoapOptions;
use Exception;
/**
* @author Francis Besset <francis.besset@gmail.com>
*/
class Cache
{
public function __construct($cacheDisabled, $type, $directory, $lifetime = null, $limit = null)
public function __construct(SoapOptions $soapOptions)
{
$isEnabled = (Boolean) $cacheDisabled ? BaseCache::DISABLED : BaseCache::ENABLED;
if ($soapOptions->isWsdlCached()) {
$isEnabled = (bool)$soapOptions->isWsdlCached() ? BaseCache::ENABLED : BaseCache::DISABLED;
BaseCache::setEnabled($isEnabled);
BaseCache::setType($type);
BaseCache::setDirectory($directory);
if (null !== $lifetime) {
BaseCache::setLifetime($lifetime);
BaseCache::setEnabled($isEnabled);
BaseCache::setType($soapOptions->getWsdlCacheType());
BaseCache::setDirectory($soapOptions->getWsdlCacheDir());
} else {
BaseCache::setEnabled(BaseCache::DISABLED);
BaseCache::setType(SoapOptions::SOAP_CACHE_TYPE_NONE);
BaseCache::setDirectory(null);
}
}
if (null !== $limit) {
BaseCache::setLimit($limit);
public function validateSettings(SoapOptions $soapOptions)
{
if ($soapOptions->isWsdlCached()) {
if (BaseCache::isEnabled() !== true) {
throw new Exception('WSDL cache could not be set');
}
if ($soapOptions->getWsdlCacheType() !== (int)BaseCache::getType()) {
throw new Exception('WSDL cache type could not be set, ini settings is: '.BaseCache::getType());
}
if ($soapOptions->getWsdlCacheDir() !== BaseCache::getDirectory()) {
throw new Exception('WSDL cache dir could not be set, real dir is: '.BaseCache::getDirectory());
}
} else {
if (BaseCache::isEnabled() !== false) {
throw new Exception('WSDL cache could not be turned off');
}
}
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace BeSimple\SoapBundle\Soap;
class SoapAttachmentList
{
private $soapAttachments;
/**
* @param SoapAttachment[] $soapAttachments
*/
public function __construct(array $soapAttachments = [])
{
$this->soapAttachments = $soapAttachments;
}
public function hasSoapAttachments()
{
return $this->soapAttachments !== null && count($this->soapAttachments) > 0;
}
public function getSoapAttachments()
{
return $this->soapAttachments;
}
public function getSoapAttachmentIds()
{
$ids = [];
foreach ($this->getSoapAttachments() as $soapAttachment) {
$ids[] = $soapAttachment->getId();
}
return $ids;
}
}

View File

@ -13,6 +13,8 @@ namespace BeSimple\SoapBundle;
use BeSimple\SoapBundle\ServiceBinding\ServiceBinder;
use BeSimple\SoapCommon\Converter\TypeConverterCollection;
use BeSimple\SoapCommon\SoapOptionsBuilder;
use BeSimple\SoapServer\SoapServerOptionsBuilder;
use BeSimple\SoapWsdl\Dumper\Dumper;
use BeSimple\SoapServer\SoapServerBuilder;
use Symfony\Component\Config\ConfigCache;
@ -102,15 +104,14 @@ class WebServiceContext
public function getServerBuilder()
{
if (null === $this->serverBuilder) {
$this->serverBuilder = SoapServerBuilder::createWithDefaults()
->withWsdl($this->getWsdlFile())
->withClassmap($this->getServiceDefinition()->getTypeRepository()->getClassmap())
->withTypeConverters($this->converters)
;
if (null !== $this->options['cache_type']) {
$this->serverBuilder->withWsdlCache($this->options['cache_type']);
}
$soapServerBuilder = new SoapServerBuilder();
$this->serverBuilder = $soapServerBuilder->build(
SoapServerOptionsBuilder::createWithDefaults(),
SoapOptionsBuilder::createWithClassMap(
$this->getWsdlFile(),
$this->getServiceDefinition()->getTypeRepository()->getClassmap()
)
);
}
return $this->serverBuilder;