SoapOptions cache dir introduced + SoapOptionsBuilder - new methods added

This commit is contained in:
Petr Bechyně 2016-11-01 09:24:41 +01:00
parent 374c64538a
commit 3c0f731086
2 changed files with 51 additions and 6 deletions

View File

@ -28,16 +28,18 @@ class SoapOptions
protected $soapFeatures;
protected $wsdlFile;
protected $wsdlCacheType;
protected $wsdlCacheDir;
protected $classMap;
protected $typeConverterCollection;
protected $attachmentType;
/**
* @param int $soapVersion = SoapOptions::SOAP_VERSION_1_1|SoapOptions::SOAP_VERSION_1_2
* @param SoapOptions::SOAP_VERSION_1_1|SoapOptions::SOAP_VERSION_1_2 $soapVersion
* @param string $encoding = SoapOptions::SOAP_ENCODING_UTF8
* @param SoapFeatures $features
* @param string $wsdlFile
* @param string $wsdlCacheType = SoapOptions::SOAP_CACHE_TYPE_NONE|SoapOptions::SOAP_CACHE_TYPE_MEMORY|SoapOptions::SOAP_CACHE_TYPE_DISK|SoapOptions::SOAP_CACHE_TYPE_DISK_MEMORY
* @param string $wsdlCacheDir = null
* @param ClassMap $classMap
* @param TypeConverterCollection $typeConverterCollection
* @param string $attachmentType = SoapOptions::SOAP_ATTACHMENTS_OFF|SoapOptions::SOAP_ATTACHMENTS_TYPE_SWA|SoapOptions::ATTACHMENTS_TYPE_MTOM|SoapOptions::ATTACHMENTS_TYPE_BASE64
@ -48,6 +50,7 @@ class SoapOptions
SoapFeatures $features,
$wsdlFile,
$wsdlCacheType,
$wsdlCacheDir = null,
ClassMap $classMap,
TypeConverterCollection $typeConverterCollection,
$attachmentType = null
@ -77,6 +80,16 @@ class SoapOptions
return $this->wsdlFile;
}
public function hasWsdlCacheDir()
{
return $this->wsdlCacheDir !== null;
}
public function getWsdlCacheDir()
{
return $this->wsdlCacheDir;
}
public function getWsdlCacheType()
{
return $this->wsdlCacheType;
@ -118,6 +131,9 @@ class SoapOptions
'classmap' => $this->getClassMap()->getAll(),
'typemap' => $this->getTypeConverterCollection()->getTypemap(),
];
if ($this->hasWsdlCacheDir()) {
$optionsAsArray['wsdl_cache_dir'] = $this->getWsdlCacheDir();
}
return $optionsAsArray;
}

View File

@ -22,10 +22,37 @@ use InvalidArgumentException;
*/
class SoapOptionsBuilder
{
static public function createWithDefaults($wsdlFile, $wsdlCacheType = Cache::TYPE_NONE)
{
static public function createWithDefaults(
$wsdlFile,
$wsdlCacheType = SoapOptions::SOAP_CACHE_TYPE_NONE,
$wsdlCacheDir = null
) {
return self::createWithClassMap($wsdlFile, new ClassMap(), $wsdlCacheType, $wsdlCacheDir);
}
static public function createSwaWithClassMap(
$wsdlFile,
ClassMap $classMap,
$wsdlCacheType = SoapOptions::SOAP_CACHE_TYPE_NONE,
$wsdlCacheDir = null
) {
return self::createWithClassMap($wsdlFile, $classMap, $wsdlCacheType, $wsdlCacheDir, SoapOptions::SOAP_ATTACHMENTS_TYPE_SWA);
}
static public function createWithClassMap(
$wsdlFile,
ClassMap $classMap,
$wsdlCacheType = SoapOptions::SOAP_CACHE_TYPE_NONE,
$wsdlCacheDir = null,
$attachmentType = null
) {
if (!Cache::hasType($wsdlCacheType)) {
throw new InvalidArgumentException;
throw new InvalidArgumentException('Invalid cache type');
}
if ($wsdlCacheType !== SoapOptions::SOAP_CACHE_TYPE_NONE) {
if ($wsdlCacheDir === null) {
throw new InvalidArgumentException('Cache dir must be set for this wsdl cache type');
}
}
$soapOptions = new SoapOptions(
SoapOptions::SOAP_VERSION_1_2,
@ -35,8 +62,10 @@ class SoapOptionsBuilder
]),
$wsdlFile,
$wsdlCacheType,
new ClassMap(),
new TypeConverterCollection()
$wsdlCacheDir,
$classMap,
new TypeConverterCollection(),
$attachmentType
);
return $soapOptions;