From 3c0f7310867ca3db8cac9ba726f403a18e83c4fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Bechyn=C4=9B?= Date: Tue, 1 Nov 2016 09:24:41 +0100 Subject: [PATCH] SoapOptions cache dir introduced + SoapOptionsBuilder - new methods added --- .../SoapCommon/SoapOptions/SoapOptions.php | 18 ++++++++- .../SoapCommon/SoapOptionsBuilder.php | 39 ++++++++++++++++--- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/src/BeSimple/SoapCommon/SoapOptions/SoapOptions.php b/src/BeSimple/SoapCommon/SoapOptions/SoapOptions.php index 25633f3..4ea3f8a 100644 --- a/src/BeSimple/SoapCommon/SoapOptions/SoapOptions.php +++ b/src/BeSimple/SoapCommon/SoapOptions/SoapOptions.php @@ -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; } diff --git a/src/BeSimple/SoapCommon/SoapOptionsBuilder.php b/src/BeSimple/SoapCommon/SoapOptionsBuilder.php index afb6366..f61e3ac 100644 --- a/src/BeSimple/SoapCommon/SoapOptionsBuilder.php +++ b/src/BeSimple/SoapCommon/SoapOptionsBuilder.php @@ -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;