diff --git a/src/BeSimple/SoapClient/Curl.php b/src/BeSimple/SoapClient/Curl.php index ae57933..54e40cf 100644 --- a/src/BeSimple/SoapClient/Curl.php +++ b/src/BeSimple/SoapClient/Curl.php @@ -72,7 +72,7 @@ class Curl CURLOPT_HEADER => true, CURLOPT_USERAGENT => $options['user_agent'], CURLINFO_HEADER_OUT => true, - ); + ); curl_setopt_array($this->ch, $curlOptions); if (isset($options['compression']) && !($options['compression'] & SOAP_COMPRESSION_ACCEPT)) { curl_setopt($this->ch, CURLOPT_ENCODING, 'identity'); @@ -215,7 +215,7 @@ class Curl 67 => 'Could not connect to host', //CURLE_LOGIN_DENIED 77 => 'Could not connect to host', //CURLE_SSL_CACERT_BADFILE 80 => 'Error Fetching http body, No Content-Length, connection closed or chunked data', //CURLE_SSL_SHUTDOWN_FAILED - ); + ); } /** diff --git a/src/BeSimple/SoapClient/SoapClient.php b/src/BeSimple/SoapClient/SoapClient.php index afa6515..d0d99e8 100644 --- a/src/BeSimple/SoapClient/SoapClient.php +++ b/src/BeSimple/SoapClient/SoapClient.php @@ -13,7 +13,6 @@ namespace BeSimple\SoapClient; use BeSimple\SoapCommon\Helper; -use BeSimple\SoapCommon\SoapKernel; use BeSimple\SoapCommon\Converter\MtomTypeConverter; use BeSimple\SoapCommon\Converter\SwaTypeConverter; @@ -77,9 +76,9 @@ class SoapClient extends \SoapClient private $lastResponse = ''; /** - * Last response. + * Soap kernel. * - * @var \BeSimple\SoapCommon\SoapKernel + * @var \BeSimple\SoapClient\SoapKernel */ protected $soapKernel = null; @@ -252,7 +251,7 @@ class SoapClient extends \SoapClient /** * Get SoapKernel instance. * - * @return \BeSimple\SoapCommon\SoapKernel + * @return \BeSimple\SoapClient\SoapKernel */ public function getSoapKernel() { @@ -286,7 +285,6 @@ class SoapClient extends \SoapClient if (!isset($options['typemap'])) { $options['typemap'] = array(); } - $soapKernel = $this->soapKernel; $options['typemap'][] = array( 'type_name' => $converter->getTypeName(), 'type_ns' => $converter->getTypeNamespace(), diff --git a/src/BeSimple/SoapClient/SoapClientBuilder.php b/src/BeSimple/SoapClient/SoapClientBuilder.php index 3759f13..cce4a9a 100644 --- a/src/BeSimple/SoapClient/SoapClientBuilder.php +++ b/src/BeSimple/SoapClient/SoapClientBuilder.php @@ -13,6 +13,7 @@ namespace BeSimple\SoapClient; use BeSimple\SoapCommon\AbstractSoapBuilder; +use BeSimple\SoapCommon\Helper; /** * Fluent interface builder for SoapClient instance. @@ -192,6 +193,42 @@ class SoapClientBuilder extends AbstractSoapBuilder return $this; } + /** + * SOAP attachment type Base64. + * + * @return \BeSimple\SoapServer\SoapServerBuilder + */ + public function withBase64Attachments() + { + $this->options['attachment_type'] = Helper::ATTACHMENTS_TYPE_BASE64; + + return $this; + } + + /** + * SOAP attachment type SwA. + * + * @return \BeSimple\SoapServer\SoapServerBuilder + */ + public function withSwaAttachments() + { + $this->options['attachment_type'] = Helper::ATTACHMENTS_TYPE_SWA; + + return $this; + } + + /** + * SOAP attachment type MTOM. + * + * @return \BeSimple\SoapServer\SoapServerBuilder + */ + public function withMtomAttachments() + { + $this->options['attachment_type'] = Helper::ATTACHMENTS_TYPE_MTOM; + + return $this; + } + /** * Validate options. */ diff --git a/src/BeSimple/SoapClient/SoapKernel.php b/src/BeSimple/SoapClient/SoapKernel.php new file mode 100644 index 0000000..949798e --- /dev/null +++ b/src/BeSimple/SoapClient/SoapKernel.php @@ -0,0 +1,47 @@ + + * (c) Francis Besset + * (c) Andreas Schamberger + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace BeSimple\SoapClient; + +use BeSimple\SoapCommon\SoapKernel as CommonSoapKernel; +use BeSimple\SoapCommon\SoapRequest; +use BeSimple\SoapCommon\SoapResponse; + +/** + * SoapKernel for Client. + * + * @author Andreas Schamberger + */ +class SoapKernel extends CommonSoapKernel +{ + /** + * {@inheritDoc} + */ + public function filterRequest(SoapRequest $request) + { + $request->setAttachments($this->attachments); + $this->attachments = array(); + + parent::filterRequest($request); + } + + /** + * {@inheritDoc} + */ + public function filterResponse(SoapResponse $response) + { + parent::filterResponse($response); + + $this->attachments = $response->getAttachments(); + } +} \ No newline at end of file diff --git a/tests/AxisInterop/MTOM.php b/tests/AxisInterop/MTOM.php index 2579c1d..38efbf0 100644 --- a/tests/AxisInterop/MTOM.php +++ b/tests/AxisInterop/MTOM.php @@ -5,7 +5,37 @@ use BeSimple\SoapClient\SoapClient as BeSimpleSoapClient; require '../bootstrap.php'; -echo '
';
+class base64Binary
+{
+    public $_;
+    public $contentType;
+}
+
+class AttachmentType
+{
+    public $fileName;
+    public $binaryData;
+}
+
+class AttachmentRequest extends AttachmentType
+{
+}
+
+class base64Binary
+{
+    public $_;
+    public $contentType;
+}
+
+class AttachmentType
+{
+    public $fileName;
+    public $binaryData;
+}
+
+class AttachmentRequest extends AttachmentType
+{
+}
 
 class base64Binary
 {
diff --git a/tests/AxisInterop/SwA.php b/tests/AxisInterop/SwA.php
index 0cf5b77..eaf1bc6 100644
--- a/tests/AxisInterop/SwA.php
+++ b/tests/AxisInterop/SwA.php
@@ -5,8 +5,6 @@ use BeSimple\SoapClient\SoapClient as BeSimpleSoapClient;
 
 require '../bootstrap.php';
 
-echo '
';
-
 $options = array(
     'soap_version'    => SOAP_1_1,
     'features'        => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
diff --git a/tests/AxisInterop/WsAddressing.php b/tests/AxisInterop/WsAddressing.php
index 9ec1bcc..dacabcb 100644
--- a/tests/AxisInterop/WsAddressing.php
+++ b/tests/AxisInterop/WsAddressing.php
@@ -5,8 +5,6 @@ use BeSimple\SoapClient\WsAddressingFilter as BeSimpleWsAddressingFilter;
 
 require '../bootstrap.php';
 
-echo '
';
-
 $options = array(
     'soap_version' => SOAP_1_2,
     'features'     => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
diff --git a/tests/AxisInterop/WsSecurityUserPass.php b/tests/AxisInterop/WsSecurityUserPass.php
index 595d9ba..231f1e5 100644
--- a/tests/AxisInterop/WsSecurityUserPass.php
+++ b/tests/AxisInterop/WsSecurityUserPass.php
@@ -5,8 +5,6 @@ use BeSimple\SoapClient\WsSecurityFilter as BeSimpleWsSecurityFilter;
 
 require '../bootstrap.php';
 
-echo '
';
-
 $options = array(
     'soap_version' => SOAP_1_2,
     'features'     => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
diff --git a/tests/ServerInterop/MTOM.php b/tests/ServerInterop/MTOM.php
new file mode 100644
index 0000000..4f815b9
--- /dev/null
+++ b/tests/ServerInterop/MTOM.php
@@ -0,0 +1,61 @@
+ SOAP_1_1,
+    'features'        => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
+    'trace'           => true, // enables use of the methods  SoapClient->__getLastRequest,  SoapClient->__getLastRequestHeaders,  SoapClient->__getLastResponse and  SoapClient->__getLastResponseHeaders
+    'attachment_type' => BeSimpleSoapHelper::ATTACHMENTS_TYPE_MTOM,
+    'cache_wsdl'      => WSDL_CACHE_NONE,
+    'classmap'        => array(
+        'base64Binary'      => 'base64Binary',
+        'AttachmentRequest' => 'AttachmentRequest',
+    ),
+);
+
+$sc = new BeSimpleSoapClient('MTOM.wsdl', $options);
+
+//var_dump($sc->__getFunctions());
+//var_dump($sc->__getTypes());
+
+try {
+    $b64 = new base64Binary();
+    $b64->_ = 'This is a test. :)';
+    $b64->contentType = 'text/plain';
+
+    $attachment = new AttachmentRequest();
+    $attachment->fileName = 'test123.txt';
+    $attachment->binaryData = $b64;
+
+    var_dump($sc->attachment($attachment));
+
+} catch (Exception $e) {
+    var_dump($e);
+}
+
+// var_dump(
+//     $sc->__getLastRequestHeaders(),
+//     $sc->__getLastRequest(),
+//     $sc->__getLastResponseHeaders(),
+//     $sc->__getLastResponse()
+// );
\ No newline at end of file
diff --git a/tests/ServerInterop/MTOM.wsdl b/tests/ServerInterop/MTOM.wsdl
new file mode 100644
index 0000000..7772015
--- /dev/null
+++ b/tests/ServerInterop/MTOM.wsdl
@@ -0,0 +1,89 @@
+
+
+  
+    
+            
+            
+                
+                    
+                    
+                
+            
+            
+            
+        
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+  
+  
+    
+    
+  
+  
+    
+    
+  
+  
+    
+      
+    
+      
+    
+    
+  
+  
+    
+    
+      
+      
+        
+      
+      
+        
+      
+    
+  
+  
+    
+    
+      
+      
+        
+      
+      
+        
+      
+    
+  
+  
+    
+      
+    
+    
+      
+    
+  
+
diff --git a/tests/ServerInterop/MTOMServer.php b/tests/ServerInterop/MTOMServer.php
new file mode 100644
index 0000000..5deee38
--- /dev/null
+++ b/tests/ServerInterop/MTOMServer.php
@@ -0,0 +1,53 @@
+ SOAP_1_1,
+    'features'        => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
+    'attachment_type' => BeSimpleSoapHelper::ATTACHMENTS_TYPE_MTOM,
+    'cache_wsdl'      => WSDL_CACHE_NONE,
+    'classmap'        => array(
+        'base64Binary'      => 'base64Binary',
+        'AttachmentRequest' => 'AttachmentRequest',
+    ),
+);
+
+class Mtom
+{
+    public function attachment(AttachmentRequest $attachment)
+    {
+        $b64 = $attachment->binaryData;
+
+        file_put_contents('test.txt', var_export(array(
+            $attachment->fileName,
+            $b64->_,
+            $b64->contentType
+        ), true));
+
+        return 'done';
+    }
+}
+
+$ss = new BeSimpleSoapServer('MTOM.wsdl', $options);
+$ss->setClass('Mtom');
+$ss->handle();