Ver Fonte

ZF-6351: added the proxy class to manage document-literal SOAP

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24718 44c647ce-9c0f-0410-b52a-842ac1e357ba
ezimuel há 13 anos atrás
pai
commit
691a6883b2

+ 48 - 5
library/Zend/Soap/Server.php

@@ -86,7 +86,13 @@ class Zend_Soap_Server implements Zend_Server_Interface
      */
     protected $_wsdlCache;
 
-
+    /**
+     * WS-I compliant
+     * 
+     * @var boolean 
+     */
+    protected $_wsiCompliant;
+    
     /**
      * Registered fault exceptions
      * @var array
@@ -217,6 +223,9 @@ class Zend_Soap_Server implements Zend_Server_Interface
                 case 'cache_wsdl':
                     $this->setWsdlCache($value);
                     break;
+                case 'wsi_compliant':
+                    $this->setWsiCompliant($value);
+                    break;
                 default:
                     break;
             }
@@ -253,17 +262,42 @@ class Zend_Soap_Server implements Zend_Server_Interface
             $options['uri'] = $this->_uri;
         }
 
-        if(null !== $this->_features) {
+        if (null !== $this->_features) {
             $options['features'] = $this->_features;
         }
 
-        if(null !== $this->_wsdlCache) {
+        if (null !== $this->_wsdlCache) {
             $options['cache_wsdl'] = $this->_wsdlCache;
         }
 
+        if (null !== $this->_wsiCompliant) {
+            $options['ws_i'] = $this->_wsiCompliant;
+        }
+        
         return $options;
     }
-
+    /**
+     * Set WS-I compliant
+     * 
+     * @param  boolean $value
+     * @return Zend_Soap_Server 
+     */
+    public function setWsiCompliant($value)
+    {
+        if (is_bool($value)) {
+            $this->_wsiCompliant = $value;
+        }
+        return $this;
+    }
+    /**
+     * Gt WS-I compliant
+     * 
+     * @return boolean
+     */
+    public function getWsiCompliant() 
+    {
+        return $this->_wsiCompliant;
+    }
     /**
      * Set encoding
      *
@@ -595,7 +629,12 @@ class Zend_Soap_Server implements Zend_Server_Interface
             throw new Zend_Soap_Server_Exception('An object has already been registered with this soap server instance');
         }
 
-        $this->_object = $object;
+        if ($this->_wsiCompliant) {
+            require_once 'Zend/Soap/Server/Proxy.php';
+            $this->_object = new Zend_Soap_Server_Proxy($object);
+        } else {
+            $this->_object = $object;
+        }    
 
         return $this;
     }
@@ -768,6 +807,10 @@ class Zend_Soap_Server implements Zend_Server_Interface
         if (!empty($this->_class)) {
             $args = $this->_classArgs;
             array_unshift($args, $this->_class);
+            if ($this->_wsiCompliant) {
+                require_once 'Zend/Soap/Server/Proxy.php';
+                array_unshift($args, 'Zend_Soap_Server_Proxy');
+            } 
             call_user_func_array(array($server, 'setClass'), $args);
         }
 

+ 56 - 0
library/Zend/Soap/Server/Proxy.php

@@ -0,0 +1,56 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Soap
+ * @subpackage AutoDiscover
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id:$
+ */
+
+class Zend_Soap_Server_Proxy
+{
+    /**
+     * @var object
+     */
+    protected $_service;
+    /**
+     * Constructor
+     * 
+     * @param object $service 
+     */
+    public function  __construct($service)
+    {
+        $this->_service = $service;
+    }
+    /**
+     * Proxy for the WS-I compliant call
+     * 
+     * @param  string $name
+     * @param  string $arguments
+     * @return array 
+     */
+    public function __call($name, $arguments)
+    {
+        $params = array();
+        if(count($arguments) > 0){
+            foreach($arguments[0] as $property => $value){
+                $params[$property] = $value;
+            }
+        }
+        $result = call_user_func_array(array($this->_service, $name), $params);
+        return array("{$name}Result"=>$result);
+    }
+}

+ 67 - 0
tests/Zend/Soap/ServerTest.php

@@ -83,6 +83,24 @@ class Zend_Soap_ServerTest extends PHPUnit_Framework_TestCase
         $this->assertTrue($server->getOptions() == $options);
     }
 
+    public function testSetWsiCompliantViaConstructor()
+    {
+        $options = array(
+            'wsi_compliant' => true
+        );
+        $server = new Zend_Soap_Server(null, $options);
+        $this->assertTrue($server->getWsiCompliant());
+    }
+    
+    public function testSetWsiCompliant()
+    {
+        $server = new Zend_Soap_Server();
+        $server->setWsiCompliant(true);
+        $this->assertTrue($server->getWsiCompliant());
+        $server->setWsiCompliant(false);
+        $this->assertFalse($server->getWsiCompliant());
+    }
+    
     /**
      * @group ZF-9816
      */
@@ -557,6 +575,55 @@ class Zend_Soap_ServerTest extends PHPUnit_Framework_TestCase
         $this->assertEquals($request, $server->getLastRequest());
     }
 
+    public function testWsiCompliant()
+    {
+        $server = new Zend_Soap_Server(null, array('wsi_compliant' => true));
+        $server->setOptions(array('location'=>'test://', 'uri'=>'http://framework.zend.com'));
+        $server->setReturnResponse(true);
+
+        $server->setClass('Zend_Soap_Server_TestClass');
+        
+        $request =
+            '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
+          . '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '
+                             . 'xmlns:ns1="http://framework.zend.com" '
+                             . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
+                             . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
+                             . 'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" '
+                             . 'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'
+          .     '<SOAP-ENV:Body>'
+          .         '<ns1:testFunc2>'
+          .             '<param0 xsi:type="xsd:string">World</param0>'
+          .         '</ns1:testFunc2>'
+          .     '</SOAP-ENV:Body>'
+          . '</SOAP-ENV:Envelope>' . "\n";
+        
+        $expectedResult = 
+            '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
+          . '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '
+                             . 'xmlns:ns1="http://framework.zend.com" '
+                             . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
+                             . 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
+                             . 'xmlns:ns2="http://xml.apache.org/xml-soap" '
+                             . 'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" '
+                             . 'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'
+          .     '<SOAP-ENV:Body>'
+          .         '<ns1:testFunc2Response>'
+          .             '<return xsi:type="ns2:Map">'
+          .                 '<item>'
+          .                     '<key xsi:type="xsd:string">testFunc2Result</key>'
+          .                     '<value xsi:type="xsd:string">Hello !</value>'
+          .                 '</item>'
+          .             '</return>'
+          .         '</ns1:testFunc2Response>'
+          .     '</SOAP-ENV:Body>'
+          . '</SOAP-ENV:Envelope>' . "\n";     
+        
+        $response = $server->handle($request);
+        
+        $this->assertEquals($response, $expectedResult);
+    }
+    
     public function testSetReturnResponse()
     {
         $server = new Zend_Soap_Server();