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 $soapFeatures;
protected $wsdlFile; protected $wsdlFile;
protected $wsdlCacheType; protected $wsdlCacheType;
protected $wsdlCacheDir;
protected $classMap; protected $classMap;
protected $typeConverterCollection; protected $typeConverterCollection;
protected $attachmentType; 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 string $encoding = SoapOptions::SOAP_ENCODING_UTF8
* @param SoapFeatures $features * @param SoapFeatures $features
* @param string $wsdlFile * @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 $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 ClassMap $classMap
* @param TypeConverterCollection $typeConverterCollection * @param TypeConverterCollection $typeConverterCollection
* @param string $attachmentType = SoapOptions::SOAP_ATTACHMENTS_OFF|SoapOptions::SOAP_ATTACHMENTS_TYPE_SWA|SoapOptions::ATTACHMENTS_TYPE_MTOM|SoapOptions::ATTACHMENTS_TYPE_BASE64 * @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, SoapFeatures $features,
$wsdlFile, $wsdlFile,
$wsdlCacheType, $wsdlCacheType,
$wsdlCacheDir = null,
ClassMap $classMap, ClassMap $classMap,
TypeConverterCollection $typeConverterCollection, TypeConverterCollection $typeConverterCollection,
$attachmentType = null $attachmentType = null
@ -77,6 +80,16 @@ class SoapOptions
return $this->wsdlFile; return $this->wsdlFile;
} }
public function hasWsdlCacheDir()
{
return $this->wsdlCacheDir !== null;
}
public function getWsdlCacheDir()
{
return $this->wsdlCacheDir;
}
public function getWsdlCacheType() public function getWsdlCacheType()
{ {
return $this->wsdlCacheType; return $this->wsdlCacheType;
@ -118,6 +131,9 @@ class SoapOptions
'classmap' => $this->getClassMap()->getAll(), 'classmap' => $this->getClassMap()->getAll(),
'typemap' => $this->getTypeConverterCollection()->getTypemap(), 'typemap' => $this->getTypeConverterCollection()->getTypemap(),
]; ];
if ($this->hasWsdlCacheDir()) {
$optionsAsArray['wsdl_cache_dir'] = $this->getWsdlCacheDir();
}
return $optionsAsArray; return $optionsAsArray;
} }

View File

@ -22,10 +22,37 @@ use InvalidArgumentException;
*/ */
class SoapOptionsBuilder 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)) { 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 = new SoapOptions(
SoapOptions::SOAP_VERSION_1_2, SoapOptions::SOAP_VERSION_1_2,
@ -35,8 +62,10 @@ class SoapOptionsBuilder
]), ]),
$wsdlFile, $wsdlFile,
$wsdlCacheType, $wsdlCacheType,
new ClassMap(), $wsdlCacheDir,
new TypeConverterCollection() $classMap,
new TypeConverterCollection(),
$attachmentType
); );
return $soapOptions; return $soapOptions;