This repository has been archived by the owner on Jan 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of git://github.com/zendframework/zf2
- Loading branch information
40 parents
3264a3c
+
0c2ce53
+
fcc59de
+
ad50dbb
+
a46cbd4
+
6192f93
+
bb42677
+
02419fd
+
cf6df36
+
92345be
+
737b39e
+
fde18af
+
43ca092
+
e3acc17
+
b5bc61a
+
30d69f9
+
7dbd12c
+
9f45cc7
+
473bfa3
+
916cd80
+
5aac7b0
+
6f66646
+
12c90a3
+
435c161
+
9bb6b33
+
6c32cce
+
f3c637f
+
c54876c
+
e1d13eb
+
daa8e6c
+
5570955
+
388a6c0
+
ac33840
+
00e233b
+
532572e
+
1e1f8d2
+
b636e56
+
18878ed
+
79ce391
+
9db7d70
commit e8f73d2
Showing
5 changed files
with
343 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace Zend\Soap\Exception; | ||
|
||
class BadMethodCallException | ||
extends \BadMethodCallException | ||
implements \Zend\Soap\Exception | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
<?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 Server | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
/** | ||
* @namespace | ||
*/ | ||
namespace Zend\Soap\Server; | ||
|
||
use ReflectionClass; | ||
use Zend\Soap\Exception\UnexpectedValueException; | ||
use Zend\Soap\Exception\BadMethodCallException; | ||
|
||
/** | ||
* Wraps WSDL Document/Literal Style service objects to hide SOAP request | ||
* message abstraction from the actual service object. | ||
* | ||
* When using the document/literal SOAP message pattern you end up with one | ||
* object passed to your service methods that contains all the parameters of | ||
* the method. This obviously leads to a problem since Zend\Soap\Wsdl tightly | ||
* couples method parameters to request message parameters. | ||
* | ||
* Example: | ||
* | ||
* class MyCalculatorService | ||
* { | ||
* /** | ||
* * @param int $x | ||
* * @param int $y | ||
* * @return int | ||
* * | ||
* public function add($x, $y) {} | ||
* } | ||
* | ||
* The document/literal wrapper pattern would lead php ext/soap to generate a | ||
* single "request" object that contains $x and $y properties. To solve this a | ||
* wrapper service is needed that extracts the properties and delegates a | ||
* proper call to the underlying service. | ||
* | ||
* The input variable from a document/literal SOAP-call to the client | ||
* MyCalculatorServiceClient#add(10, 20) would lead PHP ext/soap to create | ||
* the following request object: | ||
* | ||
* $addRequest = new \stdClass; | ||
* $addRequest->x = 10; | ||
* $addRequest->y = 20; | ||
* | ||
* This object does not match the signature of the server-side | ||
* MyCalculatorService and lead to failure. | ||
* | ||
* Also the response object in this case is supposed to be an array | ||
* or object with a property "addResult": | ||
* | ||
* $addResponse = new \stdClass; | ||
* $addResponse->addResult = 30; | ||
* | ||
* To keep your service object code free from this implementation detail | ||
* of SOAP this wrapper service handles the parsing between the formats. | ||
* | ||
* @example | ||
* | ||
* $service = new MyCalculatorService(); | ||
* $soap = new \Zend\Soap\Server($wsdlFile); | ||
* $soap->setObject(new \Zend\Soap\Server\DocumentLiteralWrapper($service)); | ||
* $soap->handle(); | ||
* | ||
* @uses ReflectionClass | ||
* @category Zend | ||
* @package Zend_Soap | ||
* @subpackage Server | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
class DocumentLiteralWrapper | ||
{ | ||
/** | ||
* @var object | ||
*/ | ||
protected $_object; | ||
|
||
/** | ||
* @var ReflectionObject | ||
*/ | ||
protected $_reflection; | ||
|
||
/** | ||
* Pass Service object to the constructor | ||
* | ||
* @param object $object | ||
*/ | ||
public function __construct($object) | ||
{ | ||
$this->_object = $object; | ||
$this->_reflection = new \ReflectionObject($this->_object); | ||
} | ||
|
||
/** | ||
* Proxy method that does the heavy document/literal decomposing. | ||
* | ||
* @param string $method | ||
* @param array $args | ||
* @return mixed | ||
*/ | ||
public function __call($method, $args) | ||
{ | ||
$this->_assertOnlyOneArgument($args); | ||
$this->_assertServiceDelegateHasMethod($method); | ||
|
||
$delegateArgs = $this->_parseArguments($method, $args[0]); | ||
$ret = call_user_func_array(array($this->_object, $method), $delegateArgs); | ||
return $this->_getResultMessage($method, $ret); | ||
} | ||
|
||
/** | ||
* Parse the document/literal wrapper into arguments to call the real | ||
* service. | ||
* | ||
* @param string $method | ||
* @param object $document | ||
* @return array | ||
*/ | ||
protected function _parseArguments($method, $document) | ||
{ | ||
$reflMethod = $this->_reflection->getMethod($method); | ||
$params = array(); | ||
foreach ($reflMethod->getParameters() as $param) { | ||
$params[$param->getName()] = $param; | ||
} | ||
|
||
$delegateArgs = array(); | ||
foreach (get_object_vars($document) as $argName => $argValue) { | ||
if (!isset($params[$argName])) { | ||
throw new UnexpectedValueException(sprintf( | ||
"Recieved unknown argument %s which is not an argument to %s::%s", | ||
get_class($this->_object), $method | ||
)); | ||
} | ||
$delegateArgs[$params[$argName]->getPosition()] = $argValue; | ||
} | ||
return $delegateArgs; | ||
} | ||
|
||
protected function _getResultMessage($method, $ret) | ||
{ | ||
return array($method.'Result' => $ret); | ||
} | ||
|
||
protected function _assertServiceDelegateHasMethod($method) | ||
{ | ||
if ( !$this->_reflection->hasMethod($method) ) { | ||
throw new BadMethodCallException(sprintf( | ||
"Method %s does not exist on delegate object %s", | ||
$method, get_class($this->_object) | ||
)); | ||
} | ||
} | ||
|
||
protected function _assertOnlyOneArgument($args) | ||
{ | ||
if (count($args) != 1) { | ||
throw new UnexpectedValueException(sprintf( | ||
"Expecting exactly one argument that is the document/literal wrapper, got %d", | ||
count($args))); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?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 UnitTests | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace ZendTest\Soap\Server; | ||
|
||
use Zend\Soap\Client\Local as SoapClient, | ||
Zend\Soap\Server, | ||
Zend\Soap\ServerException, | ||
Zend\Soap\Server\DocumentLiteralWrapper, | ||
ZendTest\Soap\TestAsset\MyCalculatorService; | ||
|
||
class DocumentLiteralWrapperTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
const WSDL = '/_files/calculator.wsdl'; | ||
|
||
private $client; | ||
|
||
public function setUp() | ||
{ | ||
ini_set("soap.wsdl_cache_enabled", 0); | ||
} | ||
|
||
/** | ||
* @runInSeparateProcess | ||
*/ | ||
public function testDelegate() | ||
{ | ||
$server = new Server(__DIR__ . self::WSDL); | ||
$server->setObject(new DocumentLiteralWrapper(new MyCalculatorService)); | ||
|
||
// The local client needs an abstraction for this pattern as well. | ||
// This is just a test so we use the messy way. | ||
$client = new SoapClient($server, __DIR__ . self::WSDL); | ||
$ret = $client->add(array('x' => 10, 'y' => 20)); | ||
|
||
$this->assertInstanceOf('stdClass', $ret); | ||
$this->assertEquals(30, $ret->addResult); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0"?> | ||
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://localhost" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="MyCalculatorService" targetNamespace="http://localhost"> | ||
<types> | ||
<xsd:schema targetNamespace="http://localhost"> | ||
<xsd:element name="add"> | ||
<xsd:complexType> | ||
<xsd:sequence> | ||
<xsd:element name="x" type="xsd:int"/> | ||
<xsd:element name="y" type="xsd:int"/> | ||
</xsd:sequence> | ||
</xsd:complexType> | ||
</xsd:element> | ||
<xsd:element name="addResponse"> | ||
<xsd:complexType> | ||
<xsd:sequence> | ||
<xsd:element name="addResult" type="xsd:int"/> | ||
</xsd:sequence> | ||
</xsd:complexType> | ||
</xsd:element> | ||
</xsd:schema> | ||
</types> | ||
<portType name="MyCalculatorServicePort"> | ||
<operation name="add"> | ||
<documentation>@param int $x</documentation> | ||
<input message="tns:addIn"/> | ||
<output message="tns:addOut"/> | ||
</operation> | ||
</portType> | ||
<binding name="MyCalculatorServiceBinding" type="tns:MyCalculatorServicePort"> | ||
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> | ||
<operation name="add"> | ||
<soap:operation soapAction="http://localhost#add"/> | ||
<input> | ||
<soap:body use="literal"/> | ||
</input> | ||
<output> | ||
<soap:body use="literal"/> | ||
</output> | ||
</operation> | ||
</binding> | ||
<service name="MyCalculatorServiceService"> | ||
<port name="MyCalculatorServicePort" binding="tns:MyCalculatorServiceBinding"> | ||
<soap:address location="http://localhost"/> | ||
</port> | ||
</service> | ||
<message name="addIn"> | ||
<part name="parameters" element="tns:add"/> | ||
</message> | ||
<message name="addOut"> | ||
<part name="parameters" element="tns:addResponse"/> | ||
</message> | ||
</definitions> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?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 UnitTests | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace ZendTest\Soap\TestAsset; | ||
|
||
/** | ||
* MyCalculatorService | ||
* | ||
* Class used in DocumentLiteralWrapperTest | ||
*/ | ||
class MyCalculatorService | ||
{ | ||
/** | ||
* @param int $x | ||
* @param int $y | ||
* @return int | ||
*/ | ||
public function add($x, $y) | ||
{ | ||
return $x+$y; | ||
} | ||
} | ||
|